Skip to content

fix(testing): emit no tool end after a scripted turn has ended - #25

Merged
xxchan merged 1 commit into
mainfrom
fix/scripted-no-frames-after-turn-end
Sep 29, 2026
Merged

xxchan merged 1 commit into
mainfrom
fix/scripted-no-frames-after-turn-end

Conversation

@xxchan

@xxchan xxchan commented Sep 29, 2026

Copy link
Copy Markdown
Member

scriptedRuntime's turn.tool() recorded its tool_call_ended even when its work settled after the turn had already ended. It now records nothing in that case, as say and think already do.

The bug: an abort or dispose ends a scripted turn at once: abortActive() records turn_ended {aborted} without waiting for the script. tool() checked live() only before starting, so a tool whose work was still in flight emitted its scripted/tool_end frame afterwards anyway:

  • work that sleeps on the signal (await turn.tool("Bash", "…", () => sleep(5000, { signal: turn.signal }))) rejects with an AbortError, and the catch branch recorded tool_call_ended {failed};
  • work that ignores the signal returns later, and the ok branch recorded tool_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 to running/waiting_model with no turn_ended ever to follow, so awaitIdle() never resolved. The session view opened a turn segment for the late end too.
  • If the host had already prompted again, the late end landed in the next turn instead. callIds restart per turn, so it ended that turn's still-running call-1, with the old call's output.

The fix: tool() checks live() 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 its tool_call_started with no end. The ScriptedTurn docs now say so, both on tool and for the turn as a whole.

Found by the integration tests of rowrow.

Evidence:

  • tests/scripted-runtime.test.ts gains one regression test per branch: a tool failing after an abort, and a tool returning after dispose. Both failed before the fix, with a trailing tool_call_ended and a running status. Both pass after it, 25/25 on repeated runs.
  • Ad-hoc check, not committed. Before the fix, awaitIdle() was still pending 1 s after the abort. With a next turn running, the stale end marked that turn's still-running call-1 as ok with the old output. After the fix, awaitIdle() resolves at once and that call stays running.
  • OAR_TEST=scripted pnpm sea-trial: 17/17 clean.
  • pnpm run check passes: typecheck, lint, vitest (362 passed, 27 skipped), and the mock sea-trial (17/17 clean).

🤖 Generated with Claude Code

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]>
@xxchan
xxchan merged commit 7617811 into main Sep 29, 2026
12 checks passed
@xxchan
xxchan deleted the fix/scripted-no-frames-after-turn-end branch September 29, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant