Repository navigation
fix(testing): emit no tool end after a scripted turn has ended - #25
Merged
Merged
Conversation
scriptedRuntime's turn.tool() checked that its turn was live only before starting. An abort or dispose ends the turn at once (abortActive records turn_ended without waiting for the script), so a tool whose work was still in flight settled afterwards and emitted its scripted/tool_end frame anyway: work sleeping on turn.signal rejects with an AbortError and the catch branch recorded tool_call_ended failed; work that ignores the signal returned and the ok branch recorded tool_call_ended ok. The status fold is total: it adopts a mid-turn event seen while idle (a mid-turn subscriber, a queued turn). So the late tool_call_ended reopened the ended turn as a phantom one: session.status() went back to running/waiting_model with no turn_ended ever to follow, and awaitIdle() waited forever; the session view opened a turn segment for it too. Had the host already prompted again, the late end landed in the next turn instead, and since callIds restart per turn it ended that turn's still-running call-1 with the old call's output. tool() now checks live() again once the work settles, as say() and think() already do: after the turn ended nothing more is recorded, and a failure is still rethrown so the script stops. The interrupted call keeps its tool_call_started with no end; the ScriptedTurn docs say so. Found by rowrow's integration tests. tests/scripted-runtime.test.ts pins both branches (a tool failing after an abort, a tool returning after dispose); both failed before the fix with a trailing tool_call_ended and a running status. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
scriptedRuntime'sturn.tool()recorded itstool_call_endedeven when its work settled after the turn had already ended. It now records nothing in that case, assayandthinkalready do.The bug: an abort or dispose ends a scripted turn at once:
abortActive()recordsturn_ended {aborted}without waiting for the script.tool()checkedlive()only before starting, so a tool whose work was still in flight emitted itsscripted/tool_endframe afterwards anyway:await turn.tool("Bash", "…", () => sleep(5000, { signal: turn.signal }))) rejects with anAbortError, and thecatchbranch recordedtool_call_ended {failed};okbranch recordedtool_call_ended {ok}.Why it matters: the status fold is total. It adopts a mid-turn event seen while idle (
observe/agent-status.ts), so the late end reopened the ended turn as a phantom one:session.status()flipped back torunning/waiting_modelwith noturn_endedever to follow, soawaitIdle()never resolved. The session view opened a turn segment for the late end too.callIds restart per turn, so it ended that turn's still-runningcall-1, with the old call's output.The fix:
tool()checkslive()again once the work settles. If the turn has ended, nothing is recorded, and a failure is still rethrown so the script stops. The interrupted call keeps itstool_call_startedwith no end. TheScriptedTurndocs now say so, both ontooland for the turn as a whole.Found by the integration tests of rowrow.
Evidence:
tests/scripted-runtime.test.tsgains one regression test per branch: a tool failing after an abort, and a tool returning after dispose. Both failed before the fix, with a trailingtool_call_endedand arunningstatus. Both pass after it, 25/25 on repeated runs.awaitIdle()was still pending 1 s after the abort. With a next turn running, the stale end marked that turn's still-runningcall-1asokwith the old output. After the fix,awaitIdle()resolves at once and that call staysrunning.OAR_TEST=scripted pnpm sea-trial: 17/17 clean.pnpm run checkpasses: typecheck, lint, vitest (362 passed, 27 skipped), and the mock sea-trial (17/17 clean).🤖 Generated with Claude Code