Skip to content

Rebuild from history after a cut when the Run has execs the provider answered itself #172

Closed

Description

@oakimov

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:

Correction (2026-11-09): An earlier version of this section said the missing-path case was answered with file_not_found. That fixture advertised only bash, so the provider actually refused the read as an unavailable tool (the "Refusals" row). Both cases above advertise read (and write for 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 in ReplaySafetyState, so it survives host tool steps like terminalRead does.
  • At history-check time:
    • edit-handshake and task-attachment are 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-read and runtime-read are 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_resources and anything without a recorded kind stay missing-host-results.
  • A provider answer in the cut attempt itself, after the last delivered result, still blocks the rebuild, as terminal-poll-after-result does 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:

Open questions

  1. 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.
  2. 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.
  3. 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-results lines, the exec kinds in those Runs would show which rows matter. Your fork's hostExecs (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.ts post-result matrix:
    • These cases rebuild: missing-read, a new-file-edit (edit display call with handshake read, then the write's host result), and a task-attachment read 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.
  • 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

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

    @nkoynov
    Contributor

    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-results lines; 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:

    • empty read before a new file's edit: 46 execs in 24 Runs, the only kind in 22 of them. Each one's write went to the host and its result was in the same Run.
    • missing read target (file_not_found): 3 in 1 Run
    • terminal-record read: 2 in 1 Run, one of them in the cut attempt
    • soft-denied force_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_resources in 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.

  3. oakimov commented on Nov 9, 2026

    @oakimov
    OwnerAuthor

    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:

    • missing-target reads;
    • the empty read before a new file's edit, once that edit's write result is in history;
    • Task attachment reads, once the Task's result is in history.

    Refusals, the soft-denied force_background_shell, spill or catalog reads, and list_mcp_resources still 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;
    • the file written once.

    On main the same cut ends with reason=missing-host-results. A missing-file read before the cut should show missingReads= the same way.

  4. added a commit that references this issue on Nov 24, 2026
    90ff0d5
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