Repository navigation
fix(desktop): acknowledge revision roots without replaying old messages - #1922
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new acknowledgement can create an empty cache entry for unloaded background sessions, causing prefetch to skip loading their transcripts and leaving the session state incorrect.
1 open issue
What changed in this PR
This PR prevents regenerated historical user prompts from being appended to the end of the renderer transcript. It uses an exact-row persistence acknowledgement while preserving revision history, normal message delivery, and bounded-history behavior.
Changes:
- Replaces archive-triggered
message_endevents withuser_message_persistedacknowledgements. - Adds projection regression tests and a real-Host end-to-end scenario.
- Documents the loaded-history semantics and records the fix in unreleased changes.
- Review note: Background sessions with no retained or cached transcript may still create an empty live cache entry through the acknowledgement handler, causing later prefetching to skip loading that session. The handler should reconcile only existing projections or avoid caching when all projections are absent.
| File | Description |
|---|---|
scripts/e2e-regenerate-root.mjs |
Exercises the real Host, persistence, and renderer projection flow with a large synthetic transcript. |
docs/spec/06-delivery/04-e2e-test-plan.md |
Documents the bounded-history regression scenario and validation command. |
docs/spec/03-runtime/04-data-storage.md |
Defines acknowledgement and loaded-history boundary semantics. |
docs/project/unreleased.md |
Records the user-visible stale-root projection fix. |
apps/desktop/test/regenerate-root-projection.test.mjs |
Covers active, background, cached, unloaded, deleted, and ordinary message projection behavior. |
apps/desktop/electron/main/runtime/event-persistence.ts |
Emits in-place persistence acknowledgements for archived revision roots. |
Review effort: Lite
| sessionId: envelope.sessionId, | ||
| ts: Date.now(), | ||
| event: { type: "message_end", message: root }, | ||
| event: { type: "user_message_persisted", optimisticMessageId: root.id, message: root }, |
muzimu217
left a comment
There was a problem hiding this comment.
The event swap is the right fix, and it is right for a reason worth naming: message_end is a terminal append for a row the renderer is expected to have just streamed, so its handler has to materialize an unknown id somewhere — and for a revision root outside the loaded window, "somewhere" is the tail. user_message_persisted is a pager stamp, and reconcilePersistedUserMessage returns the array untouched unless the exact optimistic id is already a user row (lib/session-transcript.ts:148-157), so an unloaded or deleted root stays absent by construction rather than by a new special case.
The early return is a second fix and I would call it out in the description: previously a session with no projection fell through to reconcile([]) and got an empty entry cached, which makes a background session look loaded and suppresses the later prefetch that would have read the Host. Returning before touching the cache keeps "no projection" meaning no projection.
I also checked that skipping liveSessionTranscripts.add on that early return does not strand a background session: the set is also populated from the running-state transition (session-runtime.ts:209) and from the other event paths (events-slice.ts:138, :309), so a live turn still marks its session live before any revision acknowledgement arrives.
Driving the real event-persistence and events-slice with only the host RPC stubbed is the correct boundary for this bug — the projection logic is what was wrong, and a mocked store would have hidden exactly the tail-upsert behavior being fixed.

After regenerating an older prompt, later turn completion can append that prompt after the latest reply when its root is outside the renderer's loaded history window.
session.saveActiveRevisionreturns the most recent revision-bearing root, and Main currently broadcasts it as a newmessage_end; the renderer upserts an unknown ID at the tail.Send the existing
user_message_persistedacknowledgement with the root's current message ID instead. It updates the pager only where that exact user row is already present in the active transcript, retained pane, or session cache. An unloaded or subsequently deleted root stays absent. If a background session has no projection at all, the acknowledgement leaves both its cache and live marker absent so later prefetch still reads the Host. Normal user-message delivery still appends, and revision families and stored branches remain intact.The reported 3,484 − 2,829 = 655 arithmetic is reproduced by the live branch's suffix length; current main does not use
message_countto infer a root. This change fixes the reproduced event-to-projection failure without deleting historical revisions or filtering messages by timestamp.The review identified a cache edge case in the existing acknowledgement handler: an unloaded background session could gain an empty cache entry and skip later prefetch. A new red test confirmed it. The handler now reconciles only when an active, retained, or cached projection exists; both the regression test and real-Host E2E assert that subsequent prefetch actually reads durable history.
Validation
apps/desktop).Local validation uses macOS arm64 and Node 26.12.1. The E2E drives real Host RPC, Main persistence, and renderer projection code using synthetic messages in a temporary profile; it does not call a provider or run the full Desktop GUI. The Windows release installer has not been tested locally.
CI status
All six checks pass on current head
678a05fc854abe4b3e093928e9b4a7201ef15d93:Runs: CI, Docs, PR base. GitHub merge candidate
77ac79ca1fccbd8267b647541b7f24fd59107740has the same complete Git tree as the tested head.Historical failure: on the initial commit, the Electron certificate fixture hung and was killed after 65 seconds. Its complete build source graph (191 project files) was identical to
origin/main; no certificate or proxy code was changed for this PR. The current-head Electron job completes successfully. No failed check is counted as a pass.Refs #1870