From 93d97f2e35cde1b25204d142be5b42b3e924c087 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 11 Nov 2026 22:21:46 +0100 Subject: [PATCH] docs(devlog): library search stale-after-mutation fix 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. --- CHANGELOG.md | 2 ++ ...library-search-stale-after-mutation_log.md | 27 +++++++++++++++++++ docs/devlog/INDEX.md | 1 + 3 files changed, 30 insertions(+) create mode 100644 docs/devlog/20261111-fix-library-search-stale-after-mutation_log.md diff --git a/CHANGELOG.md b/CHANGELOG.md index fceb4e6..3e8aad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. The format ### Fixed +- **search:** Library search results no longer go stale after library writes (finding `museion/library-search-stale-after-mutation`, the #144/#157 mounted gap) — the search snapshot's only task identity was the trimmed query, so nothing re-ran the sweep when the library moved underneath it: archiving or trashing a piece from a result row's own context menu left it sitting in the non-archived results after the rescan, and new, renamed, or externally edited pieces never entered or left the results until the query changed or the pane remounted. The #179 write rail's rescan now bumps a content revision whenever a scan sees the library change — a Post-list change OR any re-read post.md, so a body-only edit (which parses to an equal Post and is invisible to #143's equality-gated assignment) counts — and the mounted sweep keys on query + Home + that revision, rendering a landed snapshot only while it stays fresh for the current key (stale rows drop to the recompute spinner; panes never regroup — the assignment skip is untouched). +5 tests (pure key/gate pin; controller-level archive, trash, and same-query body-edit pins over the real rescan rail, red-first; an unchanged-rescan guard). Suite 686 + - **session:** a deferred nil scope drains as an explicit clear (PR #184, finding class #176) — `pendingScopePieceTitle: String?` let "a scope request is pending" and "which piece it targets" ride the same optionality, so a nil-target request (the writer leaves the piece mid-stream or mid-replay: New Post, unsaved draft, external guest, nothing open) deferred correctly but at drain time read as "no pending request" and returned without touching `activeEntry` — the old piece's conversation stayed live under a nothing-open context, at all four drain sites. Pending-ness now rides `PendingScope` (`.none` | `.scope(String?)`): a nil target is an explicit clear everywhere it drains. Finish-audit fanout (3 reviewers): dead `Equatable` cut, the same-turn `pendingRestart` ceiling documented at the drain (the scope is lost in respawn's `.starting` window — consume-at-apply is the upgrade path), and the titled-apply half pinned for the first time over a new `hangOnPromptLoad` rig mode (prompt parks, load answers; flip-verified). Suite 654 (PR #184) ### Changed diff --git a/docs/devlog/20261111-fix-library-search-stale-after-mutation_log.md b/docs/devlog/20261111-fix-library-search-stale-after-mutation_log.md new file mode 100644 index 0000000..18b7702 --- /dev/null +++ b/docs/devlog/20261111-fix-library-search-stale-after-mutation_log.md @@ -0,0 +1,27 @@ +# 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-gated `posts` assignment 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 bumps `contentRevision` whenever 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). The `posts`-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) and `LibrarySearch.Snapshot` (key + results) with `isFresh(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 full `searchKey` (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 while `isFresh(for: searchKey)` — stale rows drop to the recompute spinner instead of lingering. A mid-sweep key change cancels at the existing `Task.isCancelled` guards, and even a raced assignment cannot render — the body-side gate refuses it. +- **Tests** (MuseionTests/LibrarySearchTests.swift, new `LibrarySearchSnapshotTests` suite): the pure key/gate pin, plus controller-level pins over the real rescan rail (`makeModelHome` + `pollUntil` convention) proving archive, trash, and a same-query body edit each move the revision through the standing-snapshot `isFresh` gate; 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 /dd-base -resultBundlePath /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. diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index cb448ad..076209e 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| +| 2026-11-11 | fix | [20261111-fix-library-search-stale-after-mutation_log.md](20261111-fix-library-search-stale-after-mutation_log.md) | Search snapshots re-key on Home + a rescan-rail content revision (list change OR re-read post.md — body-only edits included); stale rows drop to the recompute spinner (#144/#157 mounted gap) | | 2026-11-10 | follow-up | [20261110-issue179-followup-bind-root-task_log.md](20261110-issue179-followup-bind-root-task_log.md) | Bind hoisted to the WorkspaceView root task (stale watchedHome after repoint); PR #185 closed as superseded by 5bf0955 | | 2026-11-10 | issue | [20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md](20261110-pr184-deferred-empty-piece-scope-lost-audit_log.md) | PR #184 finish-audit: dead Equatable cut, restart-race ceiling named, titled-apply pin + hangOnPromptLoad rig mode | | 2026-11-10 | issue | [20261110-issue182-profilelayout-config-set-rail_log.md](20261110-issue182-profilelayout-config-set-rail_log.md) | ProfileLayout owns every profile path; HermesConfigRail owns the config-set CLI contract; audited, 684 green (#182) |