Files
museion/docs/devlog/20261110-issue179-postsmodel-write-rail_log.md
T
AlexKucera 3bef1d12b1
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
docs(devlog): #179 write rail session log
2026-11-10 03:12:23 +01:00

6.8 KiB

PostsModel write rail — one seam pairs every store write with the rescan

Date: 2026-11-10 Type: issue Reference: Closes #179 (git.babylondreams.de/AlexKucera/Museion, from the 2026-11-09 architecture review, content line step 1 of 2)

Goal

Route every library verb's store write through ONE internal seam that pairs the write with exactly one library rescan and owns the error strip — replacing ~a dozen hand-copied write-then-rescan-then-strip choreographies whose every future copy is a silent stale-library bug. The model owns the Home: the home parameter disappears from its public methods (construction and the Settings repoint stay the only two places it is set). The editor's flush posture stays outside the rail (different error semantics, editor-owned).

What Was Done

  • Museion/PostsModelRail.swift (new) — the rail. ONE seam, three error routings: railWrite (strip-owned default: success clears the strip + pairs exactly one rescan, a throw routes localizedDescription into the strip), railWriteReturningReason (project creation — the sheet owns its inline reason, the strip behind it must not double-message), railWriteKeepingStrip (the import batch — per-file failures continue inside the op, the rail pairs the ONE rescan for the whole batch). The pairing is pinned once in pairRailRescan — the single place a verb write meets a rescan. Observability: PostsModelRailEvent (write/pairedRescan/writeFailed) through the nil-in-production onRailEvent hook.
  • 12 write sites routed (enumerated from base 627ecf5): saveDraft (post + outline first save), newPostFromSession, rename, trash, createProject, moveToProject, archivePost, restorePost, unarchiveProject, importFiles, convertToPost, runPass's pass-state advance. Deliberately outside the rail: the pass substrate's snapshotPass/captureFirstDraftStats (never library-regrouping), the publish stamp stampMicropubURL (wire-owned, deliberately quiet), writeResearchNote (mentor-owned research/), ingestImage (assets/), and the editor flush overwrite (the ticket's own exclusion — editor-owned error semantics).
  • The model owns the Home — watchedHome became private(set) var boundHome, set by bind(home:) alone (app construction + the Settings repoint through the same .task(id:)); every public verb dropped its home: parameter: saveDraft, newPostFromSession, select, rename, trash, createProject, moveTargets, moveToProject, archivePost, restorePost, unarchiveProject, importFiles, stageConversion, convertToPost, the #111 guard answers, refreshCards, applyCard/skipCard/doneCard, promoteCard, runPass, blindRead, micropubSendDraft. Internal helpers (isGuardedOutline, openUnguarded) follow. Pre-bind verbs early-return (views and the test rigs bind first — makeModelHome already did).
  • Behavior deltas (intended, AC-pinned): createProject now pairs one rescan on success (an empty-folder scan — no visible change); importFiles' trailing unconditional rescan became the rail's paired one (identical). Everything else byte-equivalent.
  • Views + tests swept — PostsPaneView, WorkspaceView, SessionsPaneView, MentorPaneView, FixCardsWindow, PromoteAskSheet, MicropubPublishSheet + 11 test files (160 call sites) to the homeless signatures.
  • MuseionTests/PostsModelWriteRailTests.swift (new) — the seam-observability suite: every write verb drives exactly [.write, .pairedRescan] (the runPass pin over the scripted-engine rig covers the advance); a failed write rides once as [.write, .writeFailed] with no rescan and the strip owning the reason.

Decisions & Rationale

Decision Rationale
Three named entries, never overloads A shared performLibraryWrite base name let unlabeled trailing-closure calls resolve into the labeled non-generic entry — a verb meant for the strip silently took the reason-returning path, never touching lastError (found live: the trash-twice failure pin read a nil strip with a [.write]-only event trail). Distinct names make the routing choice unambiguous at every call site
strip / reason-returning / strip-keeping as the three routings createProject's sheet-inline reason ("must not double-message") and the import batch's per-file-continue contract predate the rail; the rail owns the pairing everywhere, the strip only where the verb's contract says so
advancePassState in, snapshotPass out The advance regroups the library (Pass State sections) — it was a full hand-copied write-then-rescan pair. The snapshot/stats writes never regroup anything (the watcher covers the cards/ tail); railing them would add pairings with no library change
Observability via a nil-in-production hook, not a log Zero production cost; the test drives real verbs on real temp homes and reads synchronous events (fired at rail time, before the rescan Task runs)
boundHome set by bind alone The ticket's construction/Settings-repoint rule lands as one guarded property write (startWatching's existing idempotence guard); verbs read, never take

Verification

  • RED (8c5ceff, pushed at first commit): xcodebuild … build-for-testing → ** TEST BUILD SUCCEEDED **; … test-without-building -only-testing:MuseionTests/PostsModelWriteRailTests → executed 3 / passed 0 / failed 3 — every verb events → [] (nothing rode the seam).
  • GREEN (06283b6): same two commands → executed 3 / passed 3 / failed 0.
  • Full unit suite: … test-without-building -only-testing:MuseionTests → executed 654 / passed 654 / failed 0 / skipped 0 (result: Passed); main's 651 + the 3 new pins. EditorSessionTests debounce flake did not fire. UITests not run (only the unit target) — the UITests-Runner automation-mode wedge is the known machine-state baseline; unit suite is the gate.
  • swiftformat . → exit 0; swiftlint . → 279 violations / 60 serious — byte-identical to base main (spike/ + one pre-existing backtick test name), zero delta from this branch.
  • GitNexus: pre-edit impact PostsModel = CRITICAL (144 upstream — the panes + rigs this refactor sweeps, acknowledged); post-edit detect-changes --scope compare --base-ref main = 23 files / 79 symbols / 81 flows, all in the expected verb surface. The analyzer's self-written AGENTS.md counter delta (6752→6760) was reverted, not committed.

Machine-state notes (this slot)

The hosted-test runner was wedged on arrival: six testmanagerd xctestsession transactions stuck for 2+ hours (an _XCT_enableAutomationModeWithReply open since ~00:11, before this slot). killall (SIGTERM) logged an exit handler but left pid 48552 alive; kill -9 + launchd respawn cleared it — hosted tests ran normally after. Suite-member -only-testing filters containing backticks/spaces matched zero tests and "passed" vacuously (exit 0, empty counts) — the whole-suite filter is the reliable spelling.