Repository navigation
Description
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_appendedwe didn't inject, and the otherstateful-interactionsources (interaction answers, plan review, agent hand-off).
Requirements
- 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 butuser_message. Match on themessage_idwe sent if Cursor echoes it; otherwise on exact text (carriesSteer) with one appended frame per record. Anything ambiguous or unmatched keeps today's behavior. - Decide at history-check time, not frame time. Record the matched steers in
ReplaySafetyState(plain data, survives host tool steps) instead of settinghistoryRebaseUnsafe. The rebuild may proceed only if host history in the prompt being rebuilt holds every one of them (the record ispromotedand its copy is in that prompt). A steer appended in the cut step, before OpenCode promotes it, still blocks the rebuild. - 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.
- 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)andsettleEarlySteers. - 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. - 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_idinuser_message_appended? We need independent wire evidence (a captured frame or the Cursor CLI's handling) before matching on it. Text plus a precedingdeliveredstate is the fallback. - Host notes: do
user_contexthost-note injections also produceuser_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.tsortest/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 withopaque-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
nkoynov commentedon Nov 5, 2026
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_actionwithmessage_id4cff5810-…, and atdeliveredCursor sendsuser_message_appendedwith that id inUserMessagefield 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 deletinguserMessage.messageIdfrom 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 afterdelivered(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, somessage_idcan 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.
fix: rebuild from history past echoes of the Run's own steers and notes
fix: rebuild from history past AwaitShell's terminal-record polls