# #179 PostsModel write rail — one seam pairs every store write with the rescan > **Date:** 2026-11-09 > **Type:** issue > **Reference:** https://git.babylondreams.de/AlexKucera/museion/issues/179 ## Goal From the 2026-11-09 architecture review (content line, step 1 of 2): route every library verb through ONE internal seam that pairs the store write with the library rescan and owns the error strip — fourteen hand-copied write-then-rescan-then-error choreographies meant a new verb could silently forget the pairing. The model owns the Home: the parameter disappears from its public methods, construction and the Settings repoint remain the only two places it is set. The editor's flush keeps its own posture outside the rail. ## What Was Done - `performWrite` write rail in `Museion/PostsModel.swift` (~:209) — one seam: closure takes the bound Home, a clean run fires exactly one `Task { await rescan() }` and returns nil, a throw lands `localizedDescription` in the strip and returns the reason; nil-Home refuses with nothing written. - 10 verbs + the pass advance converted: `saveDraft`, `newPostFromSession`, `rename`, `trash`, `createProject`, `moveToProject`, `archivePost`, `restorePost`, `unarchiveProject`, `importFiles`, `runPass`'s `advancePassState`. Post-write state surgery rides inside each verb's closure (runs only on write success). Grep-proof: `Task { await rescan() }` now exists only in `bind` (initial scan), the rail, and the watcher. - Model owns the Home: `watchedHome` is `private(set)` (set only by `bind`/`startWatching`); every public method dropped its `home:` parameter — `select`, `saveDraft`, `rename`, `trash`, `createProject`, `moveTargets`, `moveToProject`, `archivePost`, `restorePost`, `unarchiveProject`, `importFiles`, `stageConversion`, `convertToPost`, the guard answers, `runPass`, `blindRead`, `applyCard`/`skipCard`/`doneCard`/`promoteCard`, `micropubSendDraft`, `refreshCards`. - Call-site sweep: 14 view sites (WorkspaceView, PostsPaneView, SessionsPaneView, MentorPaneView, FixCardsWindow, PromoteAskSheet, MicropubPublishSheet) and ~115 test sites across 9 test files; dead `home` plumbing cut (ArchivePaneView property, PassBarView property, ApplyAskSheet/PromoteAskSheet/MicropubPublishSheet properties, two test bindings). - 5 rail pins in `@Suite("write rail #179") struct PostsModelWriteRailTests` (suite members — name filters reach them, verified `-only-testing` 5/5): write→refresh+strip-cleared, failed write owns the strip, nil-Home refusal, import batch keeps per-file strip messages, mid-pass Home repoint refuses the advance. - Audit fixes (finish-audit fanout, 3 reviewers): repoint guard before the advance (`PostsModelPasses.swift:88`), dead-code cuts, `waitForPosts`→`pollUntil` consolidation (made internal in FixCardApplyTests). - Rig: `ScriptedEngine.endHeldPrompt()` — releases a held prompt as a NORMALLY ended turn (session/cancel only ever answers "cancelled"; the repoint pin needs `.ended` after the hold). - DOX: `Museion/AGENTS.md` PostsModel bullet (#179 write rail contract + runPass repoint refusal), `MuseionTests/AGENTS.md` suite map (rail pins + rig hook). ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | Strip clears BEFORE the write, not after | `importFiles` sets per-file failure messages mid-closure and must keep them while the batch still rescans; clear-before preserves that with zero special-casing. Flip-verified by its pin. | | `createProject` failure now shows in sheet AND strip | Issue: "the seam owns the error strip" — supersedes the #108 sheet-only rule. Flagged to the maintainer; default kept. | | `saveDraft` rides the rail | Read "the editor's flush/save-draft keeps its own posture" as EditorSession's debounced flush (⌘S on a saved piece); the verb list explicitly names "create post / outline" (= saveDraft). Flagged to the maintainer. | | Card closes, pass substrate (`snapshotPass`/stats/lint), micropub publish stay OFF the rail | None regroup the library (no rescan owed); micropub's stamp failure must never un-send the draft. Documented in code + AGENTS. | | Repoint guard (`watchedHome == home`) over passing the frozen home into the rail closure | Security reviewer's one-liner would write library A while the rail rescans library B — the exact desync the rail exists to kill. The guard keeps write+rescan consistent and refuses honestly. Converged finding (security + general, independent). | | `conversionWentLossyBehindAsk` helper | #142: swiftformat pushes a wrapped condition list's brace to its own line, swiftlint flags it, and nested ifs get collapsed into a 154-char line — the hoisted helper is the sanctioned escape. | | Nil-Home: rail speaks, pre-bind paths silently no-op | Pre-bind verb calls are unreachable in practice (every path needs posts/session ⇒ bound); the rail's refusal is the only reachable one and it says so. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---------|------------|-----| | swiftformat collapsed the nested-if guard into one 154-char line (new lint warning) | #142 formatter/linter brace fight; swiftformat reflows wraps AND merges nested ifs | Hoisted `conversionWentLossyBehindAsk` helper — short condition, guard-shaped, stable under both tools | | Test sweep left ~28 straggler call sites | First sed pass only handled trailing/first-arg `home:` shapes; mid-list `, home: home, ` and multiline continuation forms missed | Second scoped pass on those two shapes; compiler caught the rest | | `import batch` pin failed on first run | Library refresh rides the rail's rescan Task (async by design); the pin asserted `model.posts` synchronously | Poll via `pollUntil` (the suite's own convention); strip + select assertions stay synchronous | | Two xcresult summary reads died on a half-written bundle | `ls -td … \| head -1` chained to xcodebuild's exit races bundle finalization | Read the bundle in a LATER command (known #33 learning — re-bitten twice, worth re-pinning) | | Full suite exceeds the 420 s foreground terminal cap | Suite grew to ~8 min under load | `build-for-testing` + `test-without-building` split, suite run as a tracked background job with notify | | Repoint pin failed once in a full run (`lastError → nil`) | The parked scripted prompt hit its deadline while the UI-test runner starved the machine enabling automation mode; `endHeldPrompt` no-opped silently | Pin green isolated (5/5) and in the prior full run; `endHeldPrompt` now returns whether it released (queue.sync) and the pin `#require`s it — the next occurrence fails loudly (#30 flake family) | | Next-morning verify run: BOTH test runners "hung before establishing connection", zero tests executed | #134 machine wedge — testmanagerd/automation daemon degraded through the evening, reboot pending; an untouched control suite (WritingGoalTests) hangs identically | Machine-state, not the diff: 657/657 green the prior evening on this code, rail pins 5/5 isolated after the last (test-only) edit; committed with the wedge named | ## Verification - `build-for-testing`: **SUCCEEDED** at the final tree (re-verified after every edit, incl. the test-rig hardening). - Full suite (`test-without-building`): **657/657 passed, 0 failed, 0 skipped** — verified by xcresult counts, never the banner (655 pre-existing + 2 new pins; the 3 original rail pins were already in the 655 count). One later full run flaked the repoint pin under UI-runner load (see Gotchas — passed isolated, rig hardened); the next-morning re-run could not start at all: BOTH runners hung before establishing connection (#134 machine wedge, control suite hangs identically) — the 657/657 evening run on this code plus a 5/5 isolated rail-suite run after the last test-only edit are the verification of record. - Flip cycle: repoint guard `|| true` + rail clear-ordering flipped in one edit → both target pins FAILED, other three passed; restored → green. Each pin discriminates its own guard. - swiftformat clean; swiftlint **279 = 279** pre-change baseline parity (no new violations). - GitNexus: impact read before editing (verbs LOW; `refreshCards` CRITICAL / `openUnguarded` HIGH = hub fan-out on signature-only changes); `detect-changes` scope = intended symbols only; index re-analyzed. - Reviews: implement-close two-axis review (Standards+Spec) AND finish-audit three-reviewer fanout (ponytail/security/general) — 2+5 findings triaged, 7 fixed, rest accepted-as-designed with rationale above. ## Files Changed | File | Change Summary | |------|---------------| | `Museion/PostsModel.swift` | `performWrite` rail; verbs converted; `watchedHome` private(set); header | | `Museion/PostsModelOutline.swift` | Home-less guard/convert verbs; `conversionWentLossyBehindAsk` helper | | `Museion/PostsModelPasses.swift` | `runPass`/`blindRead` Home-less; advance on the rail; mid-pass repoint guard | | `Museion/PostsModelCards.swift` | Card verbs + `refreshCards` Home-less | | `Museion/Micropub.swift` | `micropubSendDraft` Home-less (off-rail, documented) | | `Museion/WorkspaceView.swift`, `PostsPaneView.swift`, `SessionsPaneView.swift`, `MentorPaneView.swift`, `FixCardsWindow.swift`, `PromoteAskSheet.swift`, `MicropubPublishSheet.swift` | Call-site sweep + dead `home` plumbing cut | | `MuseionTests/PostsModelTests.swift` | `PostsModelWriteRailTests` suite: 5 pins + scenario headers | | `MuseionTests/ScriptedEngine.swift` | `endHeldPrompt()` test hook | | `MuseionTests/FixCardApplyTests.swift` | `pollUntil` made internal (shared poll) | | 8 further test files | Mechanical `home:` sweep | | `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | DOX: write-rail contract, repoint refusal, suite map | ## Open Items & Next Steps - [ ] Maintainer ruling: `createProject` failure double-message (sheet + strip) — default kept per the issue's rail-owns-the-strip posture. - [ ] Maintainer ruling: `saveDraft` on the rail (reading of "the editor's flush/save-draft"). - [ ] None otherwise — all five acceptance criteria of #179 met and pinned. --- *Log written by write-log skill*