Repository navigation
fix(app): hide reverted messages by transcript seq, not ID - #66888
rekram1-node wants to merge 3 commits into
Conversation
The server reverts by transcript position, but the desktop app, the TUI transcript rows and the shared client store compared message IDs. IDs don't follow the transcript: automation and scheduled prompts sort after every other ID, and a steered or queued prompt keeps its send-time ID. Add messagesBeforeRevert to @opencode/client/solid and use it for the desktop's visible prompts, timeline, undo target, canUndo and cursor, the jump-to-message list, the TUI rows, and the store's commit handler. An unloaded boundary still falls back to comparing IDs.
There was a problem hiding this comment.
I found no blocking issues. I couldn't confirm the fix end to end, so this rests on the unit tests.
Testing: the new unit tests fail on dev and pass with this change in app, tui and client, and tsc is clean in all three. I couldn't reproduce the out-of-order transcript in the TUI with the simulated model, and the desktop app can't be run here. Before/after screenshots of an automation prompt (or a steered prompt's earlier replies) surviving /undo would help.
Code: the client now slices by transcript position, which matches how the server reverts (seq in core/session/history.ts). Where the boundary message isn't loaded, it still compares IDs as before. The jump-to-message slice relies on the history being newest first, and the paged desc(seq) history is.
Public API:
- Adds the
messagesBeforeRevertexport to@opencode/client/solid(backwards compatible). - The solid store's
session.revert.committedhandler now removes from the boundary's position instead of from the first ID>= to. Existing callers don't need to change.
Expose the server's transcript position on read models so clients compare it instead of message IDs, which don't follow the transcript. Durable event schemas and IDs are unchanged. - Messages carry `seq`, inbox items `enqueuedSeq`, and the session's revert the boundary's `seq`, all optional for older servers. Stored message data never keeps a copy of `seq`. - The client store records `event.durable.seq` for live inserts, reads the boundary's seq on revert.staged, and commits by seq: inbox items are pruned by enqueuedSeq and surviving inputs stay. What it can't place is read again. - messagesBeforeRevert compares seq, falls back to loaded order, and treats an unloaded boundary as older than everything loaded. - Desktop: cut the transcript before taking prompts, take the withdraw and takeBack cursor before the prompt is removed, page back for unloaded deep links instead of comparing IDs, and always clear a handoff on a staged revert. - TUI: /undo, the reverted count, todos and context usage use the same helper.
There was a problem hiding this comment.
I found nothing blocking in the code, apart from the OpenAPI document needing regeneration. I couldn't reproduce the bug end to end; the new client, tui, app, core and server tests pass, and tsc -b is clean in the changed packages.
OpenAPI document out of date: bun run check:generated in packages/protocol fails on this branch ("Generated OpenAPI document is stale") but passes on dev. The new seq, enqueuedSeq and Session.RevertInfo are in the generated client types but not in packages/protocol/openapi.json. Running bun run generate there should fix it.
Public API changes (all additions, all optional; existing clients and plugins keep working):
- Adds optional
seqto everySessionMessageon reads. - Adds optional
enqueuedSeqto inbox items. Session.Info.revertchanges fromSession.ReverttoSession.RevertInfo, which adds an optionalseq.- Exported session files now include
seq; import ignores it. messagesBeforeRevertin@opencode/client/solidnow takes{ messageID, seq? }instead of an ID string. It hasn't been released yet.
There was a problem hiding this comment.
The stale OpenAPI document from my last review is fixed: bun run check:generated now passes, and the API skill docs match a fresh generate:api-skill run. The new commit only touches generated files, so I have nothing new to raise.
Public API (unchanged since my last review; all additions, backwards compatible):
- Adds optional
seqto messages. - Adds optional
enqueuedSeqto inbox items. Session.Info.revertis nowSession.RevertInfo, which adds an optionalseq.- Adds
messagesBeforeRevertto@opencode/client/solid.
These are now also in openapi.json and the API skill docs.
|
A real-world case of this on v2.4.3 (TUI), with a plugin-supplied message ID that is not in the list of out-of-order ID families above: |
Issue for this PR
Closes #
Type of change
What does this PR do?
After /undo, the desktop app and the TUI now hide exactly the messages the server reverts, and a committed revert removes exactly what the server removed. Before, they could hide far more, show reverted messages, or delete nothing, while the agent still saw messages the UI had hidden.
Why IDs don't work. The server reverts by transcript position (
seq). The clients compared message IDs, and IDs don't follow the transcript:msg_aut_…,msg_sch_…) sort after every normal ID._<seq>, so_10sorts before_9.Comparing positions in the loaded array fixes this only while the boundary is loaded. When it's older than the first page, the clients had to fall back to comparing IDs again.
The fix: expose
seqon read models and compare it. Durable event schemas and IDs don't change.seq, inbox itemsenqueuedSeq, andSession.Info.revertthe boundary'sseq(recorded by the projection). All three are optional for older servers. Stored message data never keeps a copy.event.durable.seqfor live inserts and inbox items. Onrevert.stagedit takes the boundary'sseqfrom the loaded message, or reads the session again if the boundary isn't loaded.revert.committeddeletes messages and inbox items byseq/enqueuedSeqand keeps inputs that waited from before the boundary. Anything it can't place is read again.messagesBeforeRevert, is used by the desktop, the TUI, todos and context usage. Without anyseq(older server), it uses loaded order, and an unloaded boundary hides everything loaded, since loaded messages are always the newest part of the transcript.Also fixed along the way:
seqandenqueuedSeqare top-level, not underexperimental. AGENTS.md puts experimental fields under that key; these aren't experimental features, just existing server facts the clients need to be correct.How did you verify your code works?
New tests:
msg_aut_boundary and an unloaded forked boundary, tested in the app, TUI rows and the client store. The store test reads the boundary'sseqfrom the session.revert.committedwith inbox items: one kept, one dropped.msg_aut_/msg_watch_/fork message.seqon messages,enqueuedSeqon inbox items andseqon the staged revert, with none stored in message data.Runs:
bun run checkpasses.test:unit(2913 pass) andtest:browser(389 pass), client (297), tui (1786; the 4 expectations this changed are updated), server (207), schema, protocol.typecheck:tscpasses for schema, client and core.bun run lint:changed origin/devis clean.dev: 2 shell tests that fail there too, and an MCP OAuth test that passes when run alone. gui-plugins has 1 browser test that fails ondevtoo.Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Public API: adds optional seq to messages, enqueuedSeq to inbox items and seq to Session.Info.revert (Session.RevertInfo); adds messagesBeforeRevert to @opencode/client/solid (backwards compatible)