Reviewer fanout (ponytail/security/general) fixes: bind hoisted to the WorkspaceView root task (stale boundHome after a Home repoint while another pane was showing), railWriteReturningReason emits .writeFailed (pinned, flip-verified), dead home: params deleted from the three ask sheets, saveDraft locals inlined; AGENTS.md docs delta applied; devlog closeout. Suite 655/655, lint parity with base.
9.1 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 routeslocalizedDescriptioninto 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 inpairRailRescan— the single place a verb write meets a rescan. Observability:PostsModelRailEvent(write/pairedRescan/writeFailed) through the nil-in-productiononRailEventhook.- 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'ssnapshotPass/captureFirstDraftStats(never library-regrouping), the publish stampstampMicropubURL(wire-owned, deliberately quiet),writeResearchNote(mentor-owned research/),ingestImage(assets/), and the editor flushoverwrite(the ticket's own exclusion — editor-owned error semantics). - The model owns the Home —
watchedHomebecameprivate(set) var boundHome, set bybind(home:)alone (app construction + the Settings repoint through the same.task(id:)); every public verb dropped itshome: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 —makeModelHomealready 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 verbevents → [](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-editdetect-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.
Finish-audit closeout (2026-11-10)
Three-reviewer fanout (ponytail / security / general) on the branch diff plus the pending AGENTS.md docs delta; findings triaged and fixed in the same tree.
Accepted + fixed:
- Bind hoisted to the WorkspaceView root (
.task(id: gate.museionHome)): the pane-local.task(id: home)unmounted with the Posts pane, leavingboundHomestale after a Home repoint while the Archive pane and every root sheet (import / new project / convert) kept writing through it — a regression window main didn't have (its verbs readgate.museionHomefresh). The overclaiming comments ("app construction and the Settings repoint are the only two places it is set") corrected to name the root task. Unpinned delta: view wiring, no render harness — verified by build + suite; the bind seam itself is model-level. railWriteReturningReasonnow emits.writeFailedon a throw — the reason-returning entry's failure was unobservable on the seam (bare[.write]trail). Pinned:a failed reason-returning write reports writeFailed and leaves the strip alone(duplicate project name →[.write, .writeFailed],lastErrorstays nil — pins the routing separation too). Flip-verified: guard removed → only this pin fails; restored → green.- Dead
homeparameters deleted —MicropubPublishSheet,PromoteAskSheet,ApplyAskSheetno longer take or thread a Home (the sweep had stopped one layer short). - saveDraft's three hoisted locals deleted —
stagedis an immutable local, captured directly.
Rejected/deferred: security INFO findings (pre-bind no-op guards unreachable via real UI and non-destructive; onRailEvent a standard internal test seam) — no remediation.
Post-fix verification: full unit suite test-without-building -only-testing:MuseionTests → executed 655 / passed 655 / failed 0 / skipped 0 (the 654 + the new pin); swiftformat 0/135 dirty; swiftlint 279 violations / 60 serious — byte-identical to base. Task { await rescan() } still exactly two sites (bind + pairRailRescan). GitNexus impact on saveDraft/bind = HIGH (144–145 upstream) — the acknowledged app-scoped-model closure; all edits body-only or call-site moves with grep-enumerated callers. The index itself predates the branch (no rail symbols).