Repository navigation
Description
This follows on from discussion #140. Thanks again @nkoynov for the original trace and the VM matrix, and for the live A/B runs on #162 and #164. #159 covered the cuts that were refused as opaque-activity. This issue covers a gap that is still open in the same recovery path.
Problem
Cursor can cut a Run right after a host tool result is written, before its next checkpoint. The only recovery is a history rebuild, and the rebuild requires every exec the Run saw to have a completed host result in the prompt. The only execs exempt from that rule are the terminal-record reads that #164 added (terminalRead). Every other exec the provider answers itself is still recorded (language-model.ts:6202-6203, replay-safety.ts:152-160) but never gets a host result. So any one of them earlier in the Run makes the rebuild fail with missing-host-results (language-model.ts:1449-1460), and the turn ends with "automatic retry unsafe".
These are the execs the provider answers without the host:
| Answer | Source | What host history has |
|---|---|---|
| Empty-file read before a new file's edit | recoverCorrelatedEditRead (L5384) |
The edit's own host result (same display call) |
| Task attachment read (placeholder bytes) | answerTaskAttachmentRead (L5460) |
The Task's host result |
Typed file_not_found / invalid_file for a missing read target |
rejectMissingReadTarget (L5497) |
Nothing; it is a read-only observation |
Runtime metadata reads other than terminal records (spill files, catalogs), native or through MCP read |
runtimeExecMessages (L6707, L6764) |
Nothing; read-only |
Refusals (rejectExec: misplaced shell command, missing arguments, a held call cancelled after a refused file change, plan exit blocked) |
L6679 | Nothing; these carry a decision, and plan exit also sets planReviewDeclined |
list_mcp_resources and other non-file execs |
Nothing; #164 kept these refused on purpose (test unrepresented-exec) |
Reproduced on main with a fixture. In the post-result drop matrix in test/run-error-host.test.ts, Cursor sends a provider-answered read between the two host shells, and the Run is cut after the second result. On main (2d228b4), both of these cases are refused with reason=missing-host-results execs=3 results=2:
missing-read: aread_argsfor a path that does not exist. The provider answers it withfile_not_found.new-file-edit: the case from Resume a Run Cursor cuts right after a tool result, instead of ending the turn #140's VM matrix. Anedit_tool_callis followed by its read of a new file, which the provider answers with an empty file, and then the write, which goes to the host.
Correction (2026-11-09): An earlier version of this section said the missing-path case was answered with
file_not_found. That fixture advertised onlybash, so the provider actually refused the read as an unavailable tool (the "Refusals" row). Both cases above advertiseread(andwritefor the edit) and exercise the intended paths.
Proposal
Generalize recordTerminalRead so the history check can tell why each exec has no host result:
- At answer time, record the kind of provider answer on the exec (
terminal-read,edit-handshake,task-attachment,missing-read,runtime-read,refusal). This is plain data inReplaySafetyState, so it survives host tool steps liketerminalReaddoes. - At history-check time:
edit-handshakeandtask-attachmentare exempt only when the exec that owns the same display call has a completed host result in the prompt being rebuilt. Without that result, the check refuses as today.missing-readandruntime-readare exempt as side-effect-free reads, the same reasoning fix: rebuild from history past AwaitShell's terminal-record polls (follow-up to #162) #164 used for terminal reads.refusal,list_mcp_resourcesand anything without a recorded kind staymissing-host-results.
- A provider answer in the cut attempt itself, after the last delivered result, still blocks the rebuild, as
terminal-poll-after-resultdoes today. - The trace line lists counts per kind next to
terminalReads=.
Scope
In scope: the history-rebuild guard in canRebaseFromHistory and the replay-safety records it reads. Both majors share this path.
Out of scope:
- Transport replay and checkpoint resume.
- Answering a resumed Run's repeated exec from a stored reply (Resume a Run Cursor cuts right after a tool result, instead of ending the turn #140's first proposal; Rebuild from history after a cut when the Run delivered an early steer #159 already set it aside).
- Changing how any of these execs are answered.
Open questions
- Should missing-read and runtime reads be exempt? A rebuilt Run loses those observations, so Cursor may ask for them again. That costs one exec, not a side effect. The alternative is to exempt only the two kinds whose host result already holds the outcome.
- Should refusals stay final? A refusal the model never sees again could lead it to repeat the same malformed call, which would then be refused again. It is safe but noisy. Plan-exit refusals change mode state, so they stay final either way.
- How often does this happen live? @nkoynov, if your logs from the period after fix: rebuild from history past AwaitShell's terminal-record polls (follow-up to #162) #164 have
history-check reason=missing-host-resultslines, the exec kinds in those Runs would show which rows matter. Your fork'shostExecs(c11480f) leaves out every exec that did not go to the host. This proposal is narrower on purpose.
Done when
test/run-error-host.test.tspost-result matrix:- These cases rebuild:
missing-read, anew-file-edit(edit display call with handshake read, then the write's host result), and atask-attachmentread whose Task result is in history. - These cases are still refused: a handshake whose write result is missing from history, a refusal,
unrepresented-exec, and any provider answer in the cut attempt.
- These cases rebuild:
- The seed holds every host result once, and nothing runs twice.
- A live check on OpenCode 2.x with the test-only cut: create a new file, then cut after the write's result. The turn recovers with
kind=rebase, and the file is written once. - An Unreleased changelog entry under Fixed.
Activity
nkoynov commentedon Nov 9, 2026
Numbers for question 3, from our host logs Nov 2–9. Those builds still had the fork's host-exec-only check (c11480f), so there are no
missing-host-resultslines; I classified the execs from the exec lines of each Run instead.82 Runs were rebuilt from history after a post-result cut. 25 of them (30%) had execs the provider answered itself, so main would refuse them:
file_not_found): 3 in 1 Runforce_background_shell: 1 in 1 Run (not in your table; under the proposal it stays refused, which seems fine)No Task attachment reads, spill or catalog reads, refusals or
list_mcp_resourcesin any of them.So for us the handshake row is the one that matters. The proposal as written would rebuild 23 of the 25; exempting only handshakes and Task attachments gets 22. I can't say anything about refusals from this data. Happy to run the live new-file cut on 2.x when you have a branch.
oakimov commentedon Nov 9, 2026
Fixed by #174 (branch
fix/rebuild-provider-answers-172, 90ff0d5). Thanks @nkoynov, your numbers settled the scope.The rebuild now goes past three kinds of read the provider answers itself:
Refusals, the soft-denied
force_background_shell, spill or catalog reads, andlist_mcp_resourcesstill refuse, as do any of these answers in the cut attempt.@nkoynov, when you have time, could you run the live new-file cut on OpenCode 2.x against that branch? I'm asking only for a test run, not a review. Ask the model to create a new file, and use your test-only cut 30 ms after the write's result. Expected:
recovery: history-check ... reason=completed-tool-results ... editHandshakes=1;recovery: reopened ... kind=rebase;On
mainthe same cut ends withreason=missing-host-results. A missing-file read before the cut should showmissingReads=the same way.fix(recovery): rebuild a post-result cut past execs the provider answ…
fix: rebuild from history past reads the provider answered itself