Session log + INDEX row + CHANGELOG entry for the snapshot invalidation fix: the rescan-rail content revision and the mounted key/gate, with the red-first verification trail.
4.5 KiB
Library search snapshots invalidated by library writes — the #144/#157 mounted gap
Date: 2026-11-11 Type: fix (finding
museion/library-search-stale-after-mutation; no Gitea ticket) Reference: #144 (library search), #157 (LibrarySearch seam + pure suite — mounted invalidation explicitly unpinned), #179 (the write rail this extends), #143 (the equality-gatedpostsassignment whose blind spot this closes)
Goal
PostsPaneView's search stored a snapshot in matches but its only task identity was trimmedQuery (.task(id: trimmedQuery) at PostsPaneView.swift:333 on 5915178). Library mutations never re-keyed the task, so the sweep never re-ran: after Archive/Trash from a result row's own context menu, the archived post REMAINED in the non-archived search results even after model.posts rescanned; new, renamed, and externally edited matching pieces never entered or left the results until the query changed or the view remounted. Body-only changes had no signal at all — #143's equality-gated assignment keeps posts still when a rewritten post.md parses to an equal Post.
What Was Done
- The rail extension (PostsModel.swift):
rescan()now bumpscontentRevisionwhenever a scan sees the library change — a Post-list change OR any re-read post.md (the scan cache's miss counter deltas across the detached scan; a miss is one disk read + parse). Archive/trash/rename arrive as list changes; a body-only edit arrives as a cache miss (metadata-equal — the #143 skip keeps the panes still; the bump alone re-keys the search). Theposts-assignment skip is untouched: panes never regroup on autosave echoes, and an unchanged rescan (all cache hits) does not bump — pinned. - The mounted key + gate (LibrarySearch.swift, pure seam):
LibrarySearch.SearchKey(query, homePath, revision) andLibrarySearch.Snapshot(key + results) withisFresh(for:)— a landed sweep renders only under the key that computed it. - The view rewiring (PostsPaneView.swift): the column's
.task(id:)keys on the fullsearchKey(trimmed query + Home +model.contentRevision), so library writes and Home repoints restart the sweep; the task captures its key at start and lands the snapshot under it; body renders a snapshot only whileisFresh(for: searchKey)— stale rows drop to the recompute spinner instead of lingering. A mid-sweep key change cancels at the existingTask.isCancelledguards, and even a raced assignment cannot render — the body-side gate refuses it. - Tests (MuseionTests/LibrarySearchTests.swift, new
LibrarySearchSnapshotTestssuite): the pure key/gate pin, plus controller-level pins over the real rescan rail (makeModelHome+pollUntilconvention) proving archive, trash, and a same-query body edit each move the revision through the standing-snapshotisFreshgate; a guard pin that an unchanged rescan keeps the revision. The three rail pins were committed red first (c0cd60b: 3 failed / 2 passed) and turned green with the fix (becad45: 5/5).
Not done (out of scope): a render harness for the SwiftUI column itself — no UI automation per house style; the invalidation is observable at controller level, which is what the view consumes.
Verification
- Baseline on pristine
5915178(before any edit, after a stash):xcodebuild -project Museion.xcodeproj -scheme Museion -destination 'platform=macOS' -derivedDataPath <scratch>/dd-base -resultBundlePath <scratch>/base.xcresult -only-testing:MuseionTests test→ ** TEST SUCCEEDED **, exit 0; xcresult summary: totalTestCount 681, result Passed. - RED @
c0cd60b: same invocation with-only-testing:MuseionTests/LibrarySearchSnapshotTests→ ** TEST FAILED **, exit 65; failedTests 3 (archive, trash, body-edit — exactly the briefed failure set), passedTests 2. - GREEN focused @
becad45: same focused invocation → ** TEST SUCCEEDED **, exit 0; 5/5 passed, 0 failed. - GREEN full @
becad45(code head; the later docs commit adds no compiled code): full-only-testing:MuseionTests→ ** TEST SUCCEEDED **, exit 0; xcresult summary: totalTestCount 686, passedTests 686, failedTests 0, skippedTests 0 (baseline 681 + the 5 new pins, zero confounds). - swiftlint: 279 violations / 60 serious in 141 files at base; identical counts at the fix head (the two PostsModel warnings and one PostsPaneView file-length warning pre-exist, only their line counts grew). swiftformat: 0 files require formatting, touched and whole-tree.
- Known flake EditorSessionTests/debounce not encountered in either full run on this base.