Skip to content

fix(app): hide reverted messages by transcript seq, not ID - #66888

Open
rekram1-node wants to merge 3 commits into
devfrom
revert-by-position
Open

rekram1-node wants to merge 3 commits into
devfrom
revert-by-position

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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:

  • Automation and scheduled prompts (msg_aut_…, msg_sch_…) sort after every normal ID.
  • Forked copies end in an unpadded _<seq>, so _10 sorts before _9.
  • A steered or queued prompt keeps its send-time ID but joins the transcript after replies with newer IDs.

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 seq on read models and compare it. Durable event schemas and IDs don't change.

  • Server: messages carry seq, inbox items enqueuedSeq, and Session.Info.revert the boundary's seq (recorded by the projection). All three are optional for older servers. Stored message data never keeps a copy.
  • Client store: records event.durable.seq for live inserts and inbox items. On revert.staged it takes the boundary's seq from the loaded message, or reads the session again if the boundary isn't loaded. revert.committed deletes messages and inbox items by seq/enqueuedSeq and keeps inputs that waited from before the boundary. Anything it can't place is read again.
  • One helper, messagesBeforeRevert, is used by the desktop, the TUI, todos and context usage. Without any seq (older server), it uses loaded order, and an unloaded boundary hides everything loaded, since loaded messages are always the newest part of the transcript.
- messages.filter((message) => message.id < boundary)
+ messages.filter((message) => message.seq < revert.seq)

Also fixed along the way:

  • The desktop cuts the transcript before taking prompts, because a revert can be staged on a reply.
  • Withdraw and take-back pick the cursor before the prompt is removed.
  • A deep link to an unloaded message pages back instead of being dropped by ID.
  • A staged revert always clears an unsent prompt's placeholder.

seq and enqueuedSeq are top-level, not under experimental. 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:

  • An unloaded msg_aut_ boundary and an unloaded forked boundary, tested in the app, TUI rows and the client store. The store test reads the boundary's seq from the session.
  • revert.committed with inbox items: one kept, one dropped.
  • Jump-to-message filtering, withdraw cursor selection, and a deep link to an unloaded msg_aut_/msg_watch_/fork message.
  • Core: seq on messages, enqueuedSeq on inbox items and seq on the staged revert, with none stored in message data.

Runs:

  • bun run check passes.
  • Tests: app test:unit (2913 pass) and test:browser (389 pass), client (297), tui (1786; the 4 expectations this changed are updated), server (207), schema, protocol.
  • typecheck:tsc passes for schema, client and core. bun run lint:changed origin/dev is clean.
  • Core has 3 failures, also seen on 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 on dev too.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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)

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.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 messagesBeforeRevert export to @opencode/client/solid (backwards compatible).
  • The solid store's session.revert.committed handler 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.
@rekram1-node rekram1-node changed the title fix(app): hide reverted messages by position, not ID fix(app): hide reverted messages by transcript seq, not ID Nov 27, 2026
@rekram1-node
rekram1-node enabled auto-merge (squash) November 27, 2026 22:27

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 seq to every SessionMessage on reads.
  • Adds optional enqueuedSeq to inbox items.
  • Session.Info.revert changes from Session.Revert to Session.RevertInfo, which adds an optional seq.
  • Exported session files now include seq; import ignores it.
  • messagesBeforeRevert in @opencode/client/solid now takes { messageID, seq? } instead of an ID string. It hasn't been released yet.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 seq to messages.
  • Adds optional enqueuedSeq to inbox items.
  • Session.Info.revert is now Session.RevertInfo, which adds an optional seq.
  • Adds messagesBeforeRevert to @opencode/client/solid.

These are now also in openapi.json and the API skill docs.

@4rt3mi5

4rt3mi5 commented Nov 30, 2026

Copy link
Copy Markdown

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: msg_omos_<uuid> from oh-my-opencode-slim. A committed Esc revert cut the client list at that message and hid 109 later messages (142 minutes) until the TUI was reopened, while the server kept every row. Ordered IDs and the log are in #66824 (comment). Comparing seq covers this ID family as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants