Repository navigation
fix: rebuild from history past AwaitShell's terminal-record polls (follow-up to #162) - #164
Conversation
Follow-up to #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 #159.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
No actionable findings.
Checks:
- diff: passed. Read the recovery diff, its callers in the shared pump, and the in-scope review rules. The behavioral claims match the code. No actionable findings.
- description-accuracy: passed. The description matches the diff. It names isTerminalRecordRead, recordTerminalRead, and the history-check terminalReads count. It says a poll in the cut attempt and other self-answered execs such as list_mcp_resources still refuse, which the scripted runs confirmed. It names terminal-poll, terminal-poll-after-result, the promoted-steer case, and the isTerminalRecordRead unit test. Its 3297 passing tests equal this Linux suite's 3302 minus five tests in test/review-scripts.test.ts that are skipped off Linux. Its note that a live steer-await run was still open is what the live A/B below answers.
- adversarial: passed. Validated the cut-attempt, list_mcp_resources, false-green, cache, and MCP-read candidates, then checked later uses of the mark and both forced recovery outcomes.
- install: passed (exit 0). Isolated bun install --frozen-lockfile --ignore-scripts on the reviewed commit installed 45 packages. The same step passed on the earlier isolated runs.
- build: passed (exit 0). Isolated bun run build (tsc) passed on the reviewed commit.
- typecheck: passed (exit 0). Isolated bun run typecheck passed for the source project and tsconfig.test.json.
- unit-tests: passed (exit 0). Isolated bun test on the reviewed commit, both the rerun and the --live suite: 3302 pass, 0 fail, exit 0 (18665 expects, 126 files on the --live suite). Main on this machine was 3298 pass, 0 fail, exit 0. The description's 3297 equals this Linux count minus five tests skipped off Linux.
- isolated-suite-first: failed (exit 1). The first isolated bun test on the reviewed commit was 3301 pass, 1 fail, exit 1. The failure was test/model-selection-run.test.ts, the unchanged scenario for 1m with fast=true and max=false: expected max_mode false and received true. That file is outside the diff.
Failure cause: environment. test/model-selection-run.test.ts is outside the diff. A second isolated run and the --live suite of this commit both passed 3302 tests with 0 failures, and main passed 3298 with 0 failures. The assertion matches a parallel clash on the process-wide model cache. - live: passed (exit 0). Harness live test on the reviewed commit: OpenCode 2.2.6, plugin-opencode2.js 0.8.6, PLUGIN_INIT_COUNT=1, LIVE_TEST=passed. The assistant reply was pong, model cursor/composer-2.5, opencode_exit=0.
- live-ab: passed (exit 0). @nkoynov, thank you for the repro. This is the live confirmation you asked for. The driver was your repro-162.py steer-await mode from the gist linked on #162, unchanged, sha256 ab28087c4900dff72d478a31615e1a3655ca92bb55f6a98742b4266cddd11048, with the test-only cut from bb73b91 applied in throwaway worktrees and not committed. OpenCode 2.2.6 loaded plugin-opencode2.js 0.8.6 with PLUGIN_INIT_COUNT=1. Main e1066a9 refused twice. First: recovery: history-check reason=missing-host-results execs=83 results=2 pending=0; recovery: suppressed; automatic retry unsafe (attempt 1/14). Second: the same check with execs=84 results=2, then suppressed. This commit rebuilt twice. First: recovery: history-check reason=completed-tool-results execs=2 terminalReads=71 results=2 pending=0; recovery: reopened kind=rebase reason=completed-tool-results. Second: the same check with terminalReads=61, then kind=rebase reason=completed-tool-results. On each of those four runs the steer was sent once (1 trailing tool result before 1 early steer) and was not injected again after the cut. The two rebuilds kept a single S2 in counter.txt and the reply included HERON-58. AwaitShell polls were in the log: variant=await_tool_call and runtime metadata read_args, 81 and 82 reads on the two refusals and 71 and 61 on the two rebuilds. Other runs resumed from an unrevoked checkpoint because of the 30 ms cut race and did not reach this path. Those PR checks still logged terminalReads of 79, 82, 82, 69, 71, 79, and 72.
Limitations:
- An MCP read of a terminal record (mcp_args) is answered and is not marked terminalRead, so it still counts as a missing host result. That non-exemption matches the description and is a note, not a finding. There is no wire evidence that AwaitShell uses that path.
- The 30 ms test cut sometimes lands while a checkpoint is still valid. Those runs resume and do not exercise the history rebuild. The two refusals and two rebuilds above are the runs that reached it.
- The harness pong loaded the isolation archive of this commit. The A/B loaded the same two commits from throwaway worktrees inside the isolation boundary. CURSOR_API_KEY stayed inside that boundary.
|
I ran it on f58ba60 with the cut patch on top, plain On Small thing: in |
Follow-up to #162. Fixes #159.
Problem
#162 let a Run that Cursor cuts right after a tool result rebuild from host history past echoes of its own steers and notes. @nkoynov's live check confirmed that for notes and steers, but found one case still refused: a steer taken while Cursor waits on a background shell (AwaitShell), promoted, then a cut after the next shell result. The trace was
history-check reason=missing-host-results execs=60 results=2.AwaitShell watches the shell by reading its terminal record over and over. The provider answers each of those reads itself (
runtimeExecMessages), so none of them gets a host result. The history check wanted a host result for every exec the Run saw, so the 58 polls made it refuse. #162's tests had no Cursor-side wait, so they never hit this.Fix
isTerminalRecordRead(src/runtime-files.ts) recognises a nativeread_argsof a host shell's terminal record. Spill reads and writes, other names underterminals/and paths outside the runtime root don't count.AttemptReplaySafety.recordTerminalReadmarks that exec. The history check leaves marked execs out when it asks for host results. They still claim their display call as before.list_mcp_resources) still refuse, and so do missing host results.recovery: history-checkline now also printsterminalReads=N.Nothing new is sent on normal turns, and a rebuild seeds host history as before, so prompt caching is unaffected. Both majors share this path.
Verification
test/run-error-host.test.ts:terminal-poll(three polls between two host shells, then a cut) now rebuilds. Before the fix it failed withmissing-host-results execs=5 results=2.terminal-poll-after-result(a poll in the cut attempt) is still refused.test/early-steer.test.ts: the reported case, a promoted steer during AwaitShell polls followed by a cut. It rebuilds with the steer sent once and nothing re-injected. It fails without the fix.test/runtime-files.test.ts: unit test forisTerminalRecordRead.bun run typecheck,bun run buildandbun testpass (3297 tests, 0 failures).Not covered:
repro-162.py steer-awaitagainst this branch would confirm it.read(mcp_args) is not exempted. I have no wire evidence that AwaitShell uses that path.