Devlog records the class-site re-derivation (post-side rescan disclosed as representation-consistent with evidence), the helper location decision (EditorSession.swift beside readDocument — no ceiling pressure, no new file), and the RED/GREEN evidence chain.
8.0 KiB
brief-32 — the external guest's watch compares normalized text
Date: 2026-11-30 Type: fix (unticketed) Reference: finding
museion/external-watch-compares-unnormalized-text(argus cycle-6 bugs pass,museion-bugs.mdfinding 1; MEDIUM, certain) — branchfix/external-watch-compares-unnormalized-textoffmainat5341c4ee53291ad74b30e812ca84fc5cbdbf990b
Goal
startExternalWatch's onEvent read the open external guest's disk text RAW
(String(contentsOf: url, encoding: .utf8), PostsModelImports.swift:69) and
handed it straight to session.diskDidChange(diskText:) — no BOM strip, no
CRLF→LF. But the session's text and lastFlushedText came through
readDocument's external branch (EditorSession.swift:162-166), which strips a
\u{FEFF} prefix and maps \r\n→\n. diskDidChange raises the #67
conflictAlert when the handed text differs from BOTH lastFlushedText and
text — which it ALWAYS did for a file whose bytes carry a BOM or CRLF, even
with content unchanged.
Blocking surface: the alert makes sessionMayDepart refuse → select,
newPost, newOutline, openExternal (via departOpenDocuments) and quit
(via documentsMayDepart riding WritingLockAppDelegate) all block. Both
alert answers clear the state for the moment, but the watcher observes the
containing DIRECTORY (PostsModelImports.swift:72), so the next sibling-file
event re-fires the raw compare and re-arms the false conflict — until the
user's own flush rewrites the file normalized. A quit-blocking false alarm
that keeps coming back.
Class-site re-derivation (pattern-exhaustive, from root cause)
Re-derived from the pin myself (basis: grep -rn 'diskDidChange|readDocument| readBody|String(contentsOf' Museion/*.swift plus a full read of the seam):
every site that feeds diskDidChange or seeds session text —
| # | Site | Read path | Verdict |
|---|---|---|---|
| 1 | PostsModelImports.swift:69 — the external watch's onEvent | raw String(contentsOf:) |
the defect (fixed) |
| 2 | PostsModelWatcher.swift:157/197 — the post-side rescan's #67 read | PostStore.readBody |
representation-consistent: readDocument's POST branch reads through the same readBody (EditorSession.swift:160), so both sides of that compare are byte-identical reads of the same file |
| 3 | EditorSession.swift:136 (init seed), :269 (reloadFromDisk), :316 (keepLocal) | readDocument |
the normalized baseline itself — all three stay on it |
| 4 | Sites seeding session text otherwise: edit(_:) (the editor surface), adoptText(_:) (Fix Card apply, caller-computed) |
— | not disk reads; not in the class |
No sites beyond the scanner's seed table were found; the one seeded site
believed unexposed (the post-side rescan, #2) is disclosed above with its
consistency evidence. The other String(contentsOf:) reads in
PostsModelOutline/Micropub/FixCardStore/PostStore internals feed other
consumers, never the #67 compare.
What Was Done
ONE shared normalization for the external read path — two callers, no second normalizer at the compare site:
EditorSession.readExternalDocument(at:) -> String?(EditorSession.swift, internal static, extracted byte-identically fromreadDocument's external branch): raw UTF-8 read → BOM prefix strip → CRLF→LF. This is now the ONE external-target disk read —readDocument's external case calls it, and the guest watch calls it.reloadFromDisk/keepLocalalready read throughreadDocument, so all four external readers (open, watch, yes-reload, keep-local) funnel through the same helper: the #67 compare is normalized-to-normalized by construction.PostsModelImports.startExternalWatch's onEvent now readsEditorSession.readExternalDocument(at: url)instead of the rawString(contentsOf:). Nothing else in the closure changes.readDocumentitself only re-dispatches (both switch cases are now single expressions; swiftformat'sredundantReturnrewrites it to the implicit switch-expression form — syntax-only, semantics identical). WhatreadDocumentloads is unchanged: the fix adds a caller, not a second normalizer.diskDidChange's compare is untouched — deliberately: a normalize-at-compare site would be a parallel second normalizer, exactly what the fix direction rules out.
Helper location decision (called by the brief): it lives in
EditorSession.swift beside readDocument/writeDocument. The session owns
document reading (the readDocument/writeDocument pair is the existing
contract), no new file was warranted for 11 lines, and
file_length/type_body_length are disabled in this repo's .swiftlint.yml
— no ceiling pressure either way.
Tests (RED-first): three pins in ImportExternalTests driving the REAL
watch closure (model.externalWatcher.onEvent?() — the exact code a
directory event runs), over a dedicated temp dir (the watch observes the
containing folder, so the guest lives where no sibling test writes):
external watch raises no 67 conflict on an unchanged BOM and CRLF file— BOM+CRLF guest ("\u{FEFF}# Title\r\n\r\nBody line.\r\n") opened throughopenExternal; pins the normalized open (session.text), then fires the watch closure twice: no alert, ever.external watch still conflicts on a real write and never re-arms after yes-reload— the load-bearing negative: a REAL foreign write (different content, same BOM/CRLF representation) still raises the alert (the departure gate must not go blind); yes-reload takes the foreign content normalized; the next watch event over the unchanged file does NOT re-arm.external watch never re-arms after keep-local on a BOM and CRLF file— the No answer's leg: keep-local sees the (normalized) disk state, the local buffer stays and stays pending (saveState == .changed); no re-arm.
Verification
- RED at the pinned base (
5341c4ee+ tests only, commit b69ddd3's tree):./scripts/full-test.sh start -- -only-testing:MuseionTests/ImportExternalTests→ run dir20261130T211504Z-Museion: 11 executed / 8 passed / 3 failed (xcodebuild exit 65; all three failures are the new pins on!session.conflictAlert), 164 SwiftCompile lines (cold build, real compile — #197 clear). Suite-name filter per #195/#31/#134 (the file also holds the suite; filter by SUITE name, never file name). - GREEN targeted (fix tree, pre-format-pass):
same filter, run dir
20261130T211616Z-Museion: 11 executed / 11 passed / 0 failed (xcodebuild exit 0), 59 SwiftCompile lines. - GREEN full rail at the fix commit
70dd47e(exact committed tree, post-format):./scripts/full-test.sh start→ run dir20261130T211720Z-Museion: 720 executed / 720 passed / 0 failed / 0 skipped, xcodebuild exit 0, 3 SwiftCompile lines (incremental rebuild of the touched files — nonzero, #197 clear). 720 = the 717 baseline + the 3 new pins; the 717 rail re-covers the untouched open path (acceptance 3). - swiftformat
.: 0/152 files formatted, 278 skipped, rc 0. - swiftlint
.: 0 violations, 0 serious, 141 files, rc 0. - GitNexus impact analysis: not run — no
.gitnexus/, no gitnexus binary, no.claude/skills/gitnexus/in this clone (root AGENTS.md's GitNexus block is stale, as the cycle-6 audit disclosed); the manual caller trace above is the impact analysis. No AGENTS.md file was written by this session (consent-gated): the intended root-window row and the Museion/AGENTS.md EditorSession-bullet delta ship as the owner-apply patch~/daedalus-builds/museion/brief-32-agents-owner-apply.patch(git apply --checkclean at the branch head).
Evidence classes: failing-test proof (RED 3/3 at base), coupled-run proof (targeted GREEN + full-rail GREEN at the committed head), structural proof (caller-trace table above).