Skip to content

tui: hitting Esc to interrupt deletes multiple messages and ruins sessions #66824

Not planned

Description

@uriva

Summary

In OpenCode v2.4.2 TUI, pressing Esc (double-Esc) to interrupt a running session sometimes deletes not just the latest prompt, but a large portion of prior messages, ruining the session. This started happening after v2.4.2 introduced automatic revert.stage + revert.commit on interrupt (#65505).

Environment

  • opencode version: 2.4.2
  • Client: TUI
  • Model and provider: Observed across multiple sessions (not model-specific)
  • OS: Linux 7.0.0-44-generic suggestion: Permission Required -> Approve / Request Changed / Deny #44-Ubuntu SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
  • Terminal: TERM_PROGRAM=tmux, TERM=tmux-256color, COLORTERM=truecolor
  • Shell: /bin/bash
  • Install/channel: latest (release)
  • Active plugins: ~/.config/opencode/plugins/alice-and-bot/index.js (no terminal plugins in ~/.config/opencode/cli.json; no local .opencode/plugins/)

Reproduction

  1. Run a multi-turn session in the TUI on v2.4.2.
  2. While the session is running (for example, after steering/queuing a prompt while an earlier turn is still producing messages, or interrupting during active work with an empty composer), press Esc twice to interrupt.
  3. Observe session.revert.stage (files=false) followed immediately by session.revert.commit firing on the server.
  4. Sometimes only the last prompt is removed, and other times many messages are deleted from the session with no way to /redo.

Expected Behavior

Pressing Esc during a running process should safely interrupt execution without deleting earlier conversation messages or permanently destroying session history.

Actual Behavior

Pressing Esc during active processes triggers an immediate committed revert (session.revert.stage with files=false + session.revert.commit), which sometimes deletes just the last message and in several cases deleted many messages and ruined the session. Because the revert is committed immediately, there is no staged revert / /redo recovery.

Additional Context

Relevant opencode.log excerpt

Repeated session.revert.stage (files=false) + session.revert.commit pairs triggered by Esc interrupts on v2.4.2 (the files=false path introduced in #65505):

timestamp=2026-11-26T11:36:53.389Z level=INFO run=38fe594a message=session.revert.stage sessionID=ses_de85b1fadffeezi7dYbG80YYYC messageID=msg_217a4e057001dRtEW3xHrKdgex files=false http.span=1 role=server
timestamp=2026-11-26T11:36:53.393Z level=INFO run=38fe594a message=session.revert.commit sessionID=ses_de85b1fadffeezi7dYbG80YYYC http.span=1 role=server
timestamp=2026-11-26T13:51:06.788Z level=INFO run=38fe594a message=session.revert.stage sessionID=ses_deaab203cffevKIcxpXHmT5dIg messageID=msg_2181fbbcc001D7ku86hD169be5 files=false http.span=1 role=server
timestamp=2026-11-26T13:51:06.790Z level=INFO run=38fe594a message=session.revert.commit sessionID=ses_deaab203cffevKIcxpXHmT5dIg http.span=0 role=server
timestamp=2026-11-27T11:27:27.880Z level=INFO run=38fe594a message=session.revert.stage sessionID=ses_de34ee8ddffeL562xAY9oo6NRc messageID=msg_21cc28077001R1Pzo5pTneGL6v files=false http.span=1 role=server
timestamp=2026-11-27T11:27:27.884Z level=INFO run=38fe594a message=session.revert.commit sessionID=ses_de34ee8ddffeL562xAY9oo6NRc http.span=1 role=server
timestamp=2026-11-27T13:40:00.083Z level=INFO run=38fe594a message=session.revert.stage sessionID=ses_de2f3756bffe80E9QQ3E5XtTpQ messageID=msg_21d3bd4bf001Z7hvvBtMGyLosc files=false http.span=2 role=server
timestamp=2026-11-27T13:40:00.097Z level=INFO run=38fe594a message=session.revert.commit sessionID=ses_de2f3756bffe80E9QQ3E5XtTpQ http.span=0 role=server
timestamp=2026-11-27T14:21:31.212Z level=INFO run=38fe594a message=session.revert.stage sessionID=ses_deb0f4baeffeHQQi2kIslSYaPk messageID=msg_21d61cff9001m9SGAi6m1PpF2a files=false http.span=1 role=server
timestamp=2026-11-27T14:21:31.215Z level=INFO run=38fe594a message=session.revert.commit sessionID=ses_deb0f4baeffeHQQi2kIslSYaPk http.span=0 role=server

Possible root causes spotted in v2.4.2

  1. ID string comparison in session.revert.committed (packages/client/src/solid/data.ts):
    • session.inbox.delivered moves a delivered queued/steered user message to the end of draft while keeping its earlier admission id (which sorts before assistant messages produced while it waited).
    • session.revert.committed then splices using draft.findIndex((item) => item.id >= event.data.to) instead of the boundary's position (index.get(event.data.to)), dropping every message in between from the client store. (Related open PR: fix(app): order messages by position, not by ID string #57581.)
    • Once the client message list is truncated, a subsequent Esc or /undo selects an earlier user message from data.session.message.list(sessionID) and commits a server-side revert to that earlier boundary.
  2. Unrecoverable auto-commit in packages/tui/src/component/prompt/index.tsx (feat: undo when interrupting before the model answers #65505):
    • interrupt() immediately calls revert.stage(..., files: false) + revert.commit() with no /redo and no way to disable it.
    • Its answered check inspects client-side data.session.message.list(sessionID) right after session.wait() (potential race before final SSE deltas arrive) and does not account for non-user/non-assistant message types such as skill.

Frequency

Intermittent (multi-message deletion happened a couple of times since updating to v2.4.2; single-message take-back happens frequently on Esc).

Activity

  1. added
    area/tui
    type/bug
    version/v2
    on Nov 27, 2026
  2. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report and the logs. I couldn't reproduce the multi-message loss yet.

    On 2.4.2 I tried this in the TUI with a simulated model:

    1. Send a prompt; the model starts a shell command.
    2. While that is still running, send a second prompt (it is steered in at the next step).
    3. While the model is only thinking about the second prompt, press Esc twice with an empty composer.

    Only the second prompt was taken back and put back in the composer. The first prompt and its command result stayed, both in that TUI and in a second TUI that loaded the session fresh from the server. That is the take-back working as #65505 intended. I couldn't produce the message ordering that the ID-string comparison in session.revert.committed would need to cut more than that.

    A few things would help narrow it down:

    • In a session where it happened, was the prompt you sent during the running turn steered into that turn, or queued until the turn ended? Did the earlier turn involve several tool calls?
    • Does your alice-and-bot plugin add messages to the session (for example synthetic messages with its own msg_... IDs)? A comment on fix(app): order messages by position, not by ID string #57581 reports that plugin-made message IDs trigger this kind of client-side cut.
    • Right after it happens, if you quit and reopen the session, are the missing messages back, or still gone? This tells us whether they were only hidden in the TUI or actually deleted on the server.
    • If you still have one of the affected sessions, the list of its message IDs and types in order around the boundary from your log (e.g. msg_21d3bd4bf001Z7hvvBtMGyLosc) would help a lot.

    Related:

  3. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    We haven't heard back on the questions above, so I'm closing this issue for now.

    I tried this on 2.4.2: a prompt steered in while a turn was running, then Esc pressed twice with an empty composer. Only that last prompt was taken back. I couldn't reproduce earlier messages being lost, and without your answers I can't narrow down what is different in your sessions. The questions were whether the prompt was steered or queued, whether alice-and-bot adds messages, and whether the messages come back after you reopen the session.

    If it happens again, please send those details. The ordered message IDs and types around the revert boundary would help most. The open PR #57581 changes the code that decides which messages a committed revert removes, so it is worth watching too.

    Replying here reopens this issue.

  4. Guembri01 commented on Nov 27, 2026

    @Guembri01

    Fixed root cause 1 from your analysis, on branch revert-transcript-order (4f7c4d9-ish head, pushed).

    You were right about the scan. session.revert.committed did:

    const position = draft.findIndex((item) => item.id >= event.data.to)

    but session.inbox.delivered moves a steered prompt to the end of the transcript and keeps the id it was admitted with, so the transcript can hold a later-id assistant turn before an earlier-id prompt. A revert at that prompt then started at the assistant turn in front of it and removed it too — the client list loses messages the server never reverted. From there the next interrupt takes the last user message of the shortened list as its boundary, which is the multi-message revert you saw.

    It now splices at the boundary's position from the same index the other handlers use, and leaves the list alone when the boundary is not loaded.

    New test in packages/client/test/solid-revert-order.test.ts builds exactly that state with events (enqueued → step.started → delivered) and asserts a committed revert at the steered prompt leaves the assistant turn. With data.ts reverted it fails (list empty, both removed); with the change it passes. packages/client is 290 pass, packages/tui data.test.tsx 50 pass, typecheck and oxlint clean.

    I did not touch root cause 2: interrupt() committing instead of leaving a staged revert is the behaviour #65505 chose, and changing that is a product decision. This removes the client-side truncation that made the take-back over-reach.

    PR creation is returning 404 for this account right now, so it waits as a branch with the body written.

  5. 4rt3mi5 commented on Nov 30, 2026

    @4rt3mi5

    Answers to the three questions above, from a case on v2.4.3 (TUI, Ubuntu 24.04 / WSL2) where the transcript lost 109 messages after an Esc interrupt while the server kept all of them.

    Was the prompt steered or queued? Did the earlier turn involve tool calls?
    The earlier turn had finished normally (idle, outcome succeeded) after many tool calls and two subagents. The prompt that got taken back was sent after that, as its own turn. I pressed Esc with an empty composer about two minutes later, while the model was still thinking. No shell command had run in that turn (no output files were written, and the revert reported files=false), so the take-back itself was the intended #65505 behaviour. The damage is entirely the client-side cut.

    Does a plugin add messages with its own msg_… IDs?
    Yes. oh-my-opencode-slim injects synthetic <subagent-update …> notices whose IDs look like msg_omos_7a3e6130-3831-463d-91f0-e8aaa2905c77 (UUID suffix, metadata: {"oh-my-opencode-slim.internalInitiator": true}). They sort after every time-based msg_22… ID.

    Are the missing messages back after reopening the session?
    Yes. They never left the server: the rows were still in session_message, and GET /api/session/<id>/message still returned them. After closing and reopening the TUI, all 109 messages were back, and the log shows no further revert.

    Ordered IDs around the boundary (local time, UTC+8):

    seq type time id
    6597 idle 11-30 22:58:44 msg_22cf727ab001SP3f72HKKLCcRM
    6600 synthetic (plugin) 11-30 23:01:59 msg_omos_7a3e6130-3831-463d-91f0-e8aaa2905c77
    6600–7644 109 messages over 142 minutes, starting with the plugin message above 11-30 23:01:59 → 12-01 01:23:59 last: msg_22d7c223d001PomlRcZe3H3hV0
    — user (boundary) sent after 01:23:59 msg_22d7e035c001JvyuhemLKvk5yQ

    Log:

    timestamp=2026-11-30T17:26:07.144Z level=INFO message=session.revert.stage sessionID=ses_f56f38107ffe0gcmz8qDU70PJ4 messageID=msg_22d7e035c001JvyuhemLKvk5yQ files=false http.span=2 role=server
    timestamp=2026-11-30T17:26:07.246Z level=INFO message=session.revert.commit sessionID=ses_f56f38107ffe0gcmz8qDU70PJ4 http.span=1 role=server
    

    After this, the TUI showed the transcript ending at seq 6597, right before the first msg_omos_… in the loaded list (the session had been compacted at 09:43, so the list starts after that). That is exactly where findIndex((R) => R.id >= to) lands when the boundary is msg_22d7e035… and a msg_omos_… message sits earlier in the list. The boundary message is gone from the DB as intended; seq 6600–7644 are all still there.

    This is still the code in the v2.4.3 binary and on dev (packages/client/src/solid/data.ts):

    case "session.revert.committed": /* … */ ne.update(a.data.sessionID,(f,S)=>{let M=f.findIndex((R)=>R.id>=a.data.to);if(M===-1)return;for(let R of f.splice(M))S.delete(R.id)})

    Plugin-supplied IDs like msg_omos_… are one more family of IDs that sort out of transcript order, next to msg_aut_… / msg_sch_…. Comparing seq as in #66888 (or position as in #66168 / #57581) covers it.

    Worth having in this issue too: with the client list cut like this, the next Esc or /undo picks the last visible user message (22:55 in my case) as the boundary and would commit a server-side revert of three hours of real history. That is probably the "multiple messages" case in the title.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tuiplatform/linuxseverity:hightype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions