Repository navigation
fix(sessions): keep selectSession from reverting edits made during its detail read - #2274
SeanLiu326 wants to merge 3 commits into
Conversation
…s detail read selectSession awaited the bounded detail read and then re-cached and committed its window unconditionally. An idle-session edit (message delete, revision switch) that landed while the read was in flight replaces the transcript cache entry, so committing the stale window reverted the edit on screen and in the cache. vastsa#2233 taught loadSessionDetail itself to refuse caching such a read; the caller-level commit now applies the same guard: when the cache entry moved during the read for an idle session, the commit keeps the edit writer's cache content and cached window instead. Pinned by session-select-stale-read.test.mjs driving the real slice (superseded read keeps the edit; uneventful re-select still hydrates; running sessions still merge the live tail).
There was a problem hiding this comment.
AIUO CodePilot · Preliminary review
Diff-only preliminary review of the selectSession stale-read guard and its tests. The caller-level cache-reference comparison is a reasonable mirror of the #2233 runtime guard, but one edge case is not covered: an edit that lands while a cold-cache read is in flight is still reverted, because the guard requires a pre-read cache entry. Verified against the added diff only; no tests, typecheck, runtime behavior, or repository state were checked.
- medium
apps/desktop/src/stores/slices/session\-slice\.ts:533: The guard requires `cacheBeforeDetailRead !== undefined`, so an idle-session edit that lands during a cold-cache read (no transcript cache entry captured before `await detailPromise`) cannot be detected. The edit writer's cache entry is then skipped by `cacheSessionTranscript`, but `commitSelection` still receives `selectedMessages`/`historyWindow`, i.e. the stale detail window, reverting the just-made edit on screen — the same #2273 shape this PR targets, only for the first-read path.
Evidence:const cacheBeforeDetailRead = runtime\.sessionTranscriptCache\.get\(id\);
Head: 9056cfd
Base: d128b12
CI: success; mergeable: true.
Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.
…e compare The guard required a captured cache entry before comparing, so a read that started with no transcript cache entry could never see the movement an in-flight idle edit makes (undefined -> entry). The runtime guard this mirrors (vastsa#2233) needs no such precondition; dropping it keeps the caller-level compare aligned with that semantics. Warm re-selects are unaffected: the comparison is the same reference check it always was, and a quiet read whose runtime write replaces the entry still resolves to the same window content.
|
Took the cold-cache edge from the review seriously and traced it through the real selection flow ( What the trace showed: in a plain re-select the cold-read capture is rarely Fix: the guard now uses the same plain reference comparison as the runtime guard it mirrors — New coverage ( |
… failure unrelated to this change)
|
The revert is real. Two issues with the guard: (1) the snapshot is taken just before |
|
Thanks @SeanLiu326 — both of your commits landed in #2358 with authorship preserved. On top: the stale-read baseline is taken before workspace alignment (covers the edit-during-alignment window from review), and an evicted cache entry is not treated as an edit. A loadSessionDetail-returned stale flag was not used because its baseline predates selectSession's own provisional commits, which would make a retained background pane look like an edit; a regression test pins that. Closing as superseded. |
Fixes #2273.
What
A bounded detail read that
selectSessionstarts on a warm re-select could silently revert an idle-session edit made while the read was in flight:deleteMessage/activateMessageRevisionreplaced the transcript cache entry andstate.messages, and the finished pre-edit read then re-cached and committed its stale window. #2233 fixed exactly this shape insideloadSessionDetail— but the runtime guard only skips the cache write and still returns the stale detail, andselectSession, the read's biggest caller, re-cached and committed it unconditionally. Its only continuation guard (navigationIntentIsCurrent) does not observe edits, and theliveMessagesmerge path engages for running sessions only, so an idle-session writer was unprotected.The fix
Mirror the runtime guard at the caller, inside
selectSessiononly (no new module):transcriptMovedWhileReading= an entry existed before the read, the entry is a different array now, and the session is idle (no live flag, not running);cacheSessionTranscriptwrite and commit the edit writer's cache content with its cached window (viacommitSelection's existing default) instead of the stale window. Otherwise the behavior is identical to before.Tests
session-select-stale-read.test.mjsdrives the real slice through the existing minimal store harness: (1) a superseded read keeps the edit in the cache,state.messages, and the window while the selection still completes; (2) an uneventful re-select still hydrates the read window and clearsselectingSessionId; (3) a running session still merges its live tail over the detail window.session-switch-performance.test.mjs's source pin updated from the old call shape to the guarded one (intent preserved: the final commit carries the loaded window unless superseded).node --testsession + transcript families green (34/34 in the six directly related suites, fullsession-*/transcript-*families in the run log);tsc -p apps/desktop/tsconfig.json --noEmitclean.Branch contains latest main
d128b12e2.