Skip to content

Rebuild from history after a cut when the Run delivered an early steer #159

Closed

Description

@oakimov

From discussion #140 (thanks @nkoynov). We'll take the narrow fix here, a history rebuild past the provider's own steers, rather than answering a resumed Run's repeated exec from a stored reply.

Problem

A Run Cursor cuts right after a host tool result write, before its next checkpoint, can only recover through a history rebuild: writing the result revokes the step's last checkpoint, because resuming it would run the tool again. The rebuild is refused with reason=opaque-activity whenever the Run earlier delivered an OpenCode 2.x early steer, so the turn ends with "automatic retry unsafe".

The steer is injected as inject_context_action.user_context.user_message (language-model.ts:4674). Cursor answers with InteractionUpdate.user_message_appended (#6). That frame is classified stateful-interaction (replay-safety.ts:349-350) with historyRepresentable=false, which sets historyRebaseUnsafe for the rest of the Run (replay-safety.ts:103-107). The history check then stops at opaque-activity (language-model.ts:1434).

Yet the steer is not opaque. Once OpenCode promotes its own copy after the step's tool results, the provider marks the record promoted (language-model.ts:4867), and a rebase already counts on host history holding it (host-steer.ts:161-166).

In the reporter's logs for 10-26 to 10-29 (Opus 5.5 1M, OpenCode 2.1/2.2), 3 of 22 remote stream cancels hit a result write with no usable checkpoint. One rebuilt. The other two were refused only because of steers delivered 2 to 11 minutes earlier in the same Run.

Cursor CLI

Cursor CLI resumes its latest checkpoint after any retryable error and runs whatever Cursor asks for again. In Cursor CLI 2026.09.28, user_message_appended commits the pending turn and starts one from the user message (replay-safety.ts:180-181). It has no history rebuild, so there's nothing to copy here; the fix only widens our own rebuild guard.

Scope

In scope: user_message_appended frames that echo an early steer this provider injected into the same Run, on the history-rebuild path.

Out of scope:

  • Transport replay and checkpoint resume. The frame stays a stateful barrier.
  • Answering a resumed Run's repeated exec from a stored reply (the discussion's first proposal).
  • Any user_message_appended we didn't inject, and the other stateful-interaction sources (interaction answers, plan review, agent hand-off).

Requirements

  1. Match the echo to its injection. An appended message counts as a steer only if it belongs to a tracked early steer of this Run that Cursor reported delivered, and the frame holds nothing but user_message. Match on the message_id we sent if Cursor echoes it; otherwise on exact text (carriesSteer) with one appended frame per record. Anything ambiguous or unmatched keeps today's behavior.
  2. Decide at history-check time, not frame time. Record the matched steers in ReplaySafetyState (plain data, survives host tool steps) instead of setting historyRebaseUnsafe. The rebuild may proceed only if host history in the prompt being rebuilt holds every one of them (the record is promoted and its copy is in that prompt). A steer appended in the cut step, before OpenCode promotes it, still blocks the rebuild.
  3. Every other guard is unchanged: no pending execs, a checkpoint revoked only by host results, every observed exec has a completed result, every announced display call is claimed.
  4. No duplicate steer. After the rebuild, the steer appears once (host history), is not re-injected, and its receipt state stays consistent with handOverEarlySteers(…, undefined) and settleEarlySteers.
  5. Diagnostics. Trace every cause that sets historyRebaseUnsafe, not just the first barrier of a pump pass. The reporter couldn't rule out a second cause because only the first is logged.
  6. Prompt cache. Nothing new is sent on normal turns. A rebuild seeds from host history as it does today.

Open questions

  • Does Cursor echo message_id in user_message_appended? We need independent wire evidence (a captured frame or the Cursor CLI's handling) before matching on it. Text plus a preceding delivered state is the fallback.
  • Host notes: do user_context host-note injections also produce user_message_appended? If so, they're a separate case: host history doesn't hold those notes the same way.

Done when

  • Unit tests (test/parallel-pump.test.ts or test/replay-safety.test.ts): a promoted steer followed by a cut after a result write rebuilds from history; an unpromoted steer, an unmatched appended message, a duplicate echo and extra fields each still fail with opaque-activity; the steer is sent once after the rebuild.
  • A live check on OpenCode 2.x: steer mid-Run, then force a cut after a later result write, and the turn recovers through the history rebuild with no tool run twice. Also confirm OpenCode 1.x behaves as before.
  • Unreleased changelog entry under Fixed.

Activity

  1. added
    bug
    on Nov 5, 2026
  2. nkoynov commented on Nov 5, 2026

    @nkoynov
    Contributor

    Both have answers from data we already had.

    Cursor echoes the id. A real recording from Oct 7 (OpenCode 2.0.24) has our inject_context_action with message_id 4cff5810-…, and at delivered Cursor sends user_message_appended with that id in UserMessage field 2, the same text, and fields 24–26 (a flag and two timestamps). Cursor CLI 2026.11.05 relies on it: it drops the echo of a steer it already showed by deleting userMessage.messageId from its set of delivered steer ids.

    Host notes produce the frame too. In our provider logs from Oct 19 to Nov 5, every delivered injection got exactly one user_message_appended, a median 1 ms after delivered (3,453 host notes, 340 early steers), and there were none anywhere else. The note echoes have the size of the same layout with the id, so message_id can tell a note from a steer.

    That corrects what I wrote in #140: the four appends in those two refused Runs were host notes (OpenCode's background shell completion notices), not steers. Our fork logs every appended frame as "steer: …", which misled me. So a steer-only fix wouldn't have rebuilt either Run, though whether notes can be covered the same way is your call.

    I can run the 2.x live check from "Done when" once you have a branch. We have no live 1.x setup.

  3. reopened this on Nov 7, 2026
  4. added 2 commits that reference this issue on Nov 24, 2026
    1688a1d
    f58ba60
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions