Repository navigation
fix: rebuild from history past echoes of the Run's own steers and notes - #162
Conversation
Cursor answers every delivered inject_context_action with a user_message_appended frame that echoes its message_id. That frame marked the whole Run opaque, so once a Run had delivered an early steer or a host note, a cut right after a tool result write could no longer rebuild from host history and the turn ended as "automatic retry unsafe". Match the echo to the Run's own delivered injection (same message_id and text, nothing else) and keep it as plain replay state. At history-check time the rebuild goes ahead only when the seeded prompt holds each one: a promoted steer's copy at its promotion boundary, or a note's text, or a note the Run still tracks and carries over. Unmatched, duplicate, undelivered or extra-field echoes keep the refusal. Transport replay and checkpoint resume still treat the echo as a stateful barrier; a failed attempt whose only barriers were such echoes may reach the history check. Every cause that makes history unsafe is now a recovery: trace line. Fixes #159.
The fixture linked /usr/bin and /bin into a private PATH and skipped a name only when fs.existsSync saw it. existsSync follows links, so a broken link in /usr/bin (the current ubuntu-latest image ships one) read as missing and the /bin pass linked the same name again: EEXIST. The setup also ran outside try, so the failure left its temp directory behind. Dedupe by name and set up inside try.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
analyzeReplayFrame reads an echo only from a frame validInteractionUpdateWire accepted, which already proved update #6 holds exactly one length-delimited user_message #1. appendedEcho checked that again, and its fallback branch could never run (Codecov: the one uncovered patch line). State the precondition instead, and cover an empty user_message.
There was a problem hiding this comment.
No actionable findings.
Checks:
- diff: passed. The diff matches the description and issue 159. A matched echo of this Run's delivered steer or host note stays a stateful barrier, and a history rebuild proceeds only when the seeded prompt holds it. Unmatched, duplicate, undelivered, and extra-field echoes still refuse. The description's statement that fields 24-26 are accepted only as varints matches appendedEcho.
- harness: passed. Scripts ran from harness commit 6915cbb. There were no earlier review threads on this pull request.
- isolated-check: passed. Install, build, and typecheck passed. The new echo, steer, and host-note rebuild tests passed. The wrapper exited 1 with 3264 pass, 10 skip, and 11 fail, all in review-eval or isolate-run self-tests: the archive has no git metadata, and nested user namespaces are refused. Required CI Typecheck, test, build passed on this head. On a normal checkout those self-tests passed except one opencode tool-path case the archive did not mount and therefore skipped.
- native-runner: skipped. test-harness.py --diagnose reported Linux, backend docker, not ready: node is not installed and no local Docker engine is available. The native runner does not apply. Contributor execution used isolated-check.sh.
- adversarial: passed. Candidate, omission, and failed-work retry passes finished. The forced credential failure during a note rebuild left the note deferred, and the ordinary retry seeded it once.
- live: skipped. The harness forwards CURSOR_API_KEY only after isolated-check.sh exits 0. The wrapper exited 1 on archive self-tests, so the live gate did not run and the key was not passed. The cut after a result write was not observed on a live Cursor Run.
Limitations:
- No live OpenCode prompt was run. The installed CLI is 2.2.5, and it was not given a prompt or the API key.
- Fields 24-26 were checked as varints with independent fixture bytes, not a frame captured from this run. Another wire type fails closed.
- Echo state is in-memory session state. A process restart was not exercised.
|
I ran the 2.x live check on e1066a9 (OpenCode 2.2.5 through T3, Opus 5.5, a real Cursor account), with a test-only patch that cuts the Run 30 ms after a shell result once a host note of that Run was delivered. With a nested |
|
@nkoynov I'll reopen the issue. As I do not use T3, can you share a little more info how to reproduce? |
|
Sure, no T3 needed. I redid it with plain Patch: branch
Steps (script: https://gist.github.com/nkoynov/f2ebd14a766894999cfe4d22f7cd221c): The steer is a second What we saw:
Lines to look for (need |
|
Follow-up on the AwaitShell case: our fork rebuilds it. Its history check counts only execs that went to the host ( |
Follow-up to oakimov#162. A Run cut right after a tool result could still not rebuild from host history when Cursor had earlier waited on a background shell: each AwaitShell poll of the shell's terminal record is an exec the provider answers itself, and the history check wanted a host result for every exec (`missing-host-results`). Mark those reads and leave them out of that check. A poll in the cut attempt itself stays a barrier. Fixes oakimov#159.
Fixes #159.
Problem
When Cursor cuts a Run right after a tool result is written, the only safe recovery is a rebuild from host history. That rebuild was refused (
opaque-activity) whenever the Run had earlier delivered an early steer or a host note. Cursor answers every deliveredinject_context_actionwithuser_message_appended, and that frame marked the whole Run as history-unsafe. The two refused Runs in the report were caused by host notes (background shell notices), not steers, so this covers both.Fix
message_idand text, Cursor reported itdelivered, and theUserMessageholds only text, id and Cursor's echo metadata (fix(opencode2): support stable 2.0.x without ctx.catalog #24–HTTP/2 Run stream ignores HTTPS_PROXY / NO_PROXY (connect timeout behind an HTTP proxy) #26). Each injection matches once.replayBarrierEchoesOnly). Text, tool rows or any other frame in that attempt keep it final.recovery:line (history-unsafe,appended-echo,appended-unmatched,appended-not-in-history), so it shows withCURSOR_PROVIDER_RECOVERY_DEBUG=1.Nothing new is sent on normal turns; the injection's
message_idwas already sent and is now remembered. A rebuild seeds host history as before. Both majors share this path: 1.x has host notes but no early steers.Verification
test/replay-safety.test.ts).test/run-error-host.test.ts): rebuilds when the note is still tracked, or checkpointed but still in history. Refuses for a wrong id, a duplicate echo, an extra field, an echo beforedelivered, and a note dropped from history.test/early-steer.test.ts): a promoted steer rebuilds with the steer sent once and nothing re-injected; an unpromoted one is refused.mainalready has there; fix: run the full checks on Linux, macOS and Windows hosts #161 fixes those.Not yet done: the live OpenCode 2.x check from the issue (steer mid-Run, then force a cut after a later result write); the reporter offered to run it. The
#24–#26echo fields are accepted only as varints, per the recorded frame described in the issue; a different live wire type fails closed and shows up asappended-unmatched layout=….