Skip to content

feat(testing): let a script make the scripted runtime's process exit on its own - #845

Closed
TennyZhuang wants to merge 1 commit into
botiverse:mainfrom
TennyZhuang:scripted-runtime-exit
Closed

TennyZhuang wants to merge 1 commit into
botiverse:mainfrom
TennyZhuang:scripted-runtime-exit

Conversation

@TennyZhuang

Copy link
Copy Markdown
Contributor

What changes and why

Today scriptedRuntime (@botiverse/oar/testing) records exited only when the host disposes the session. That means a host can't use it to test its most important failure path: the runtime dying by itself, mid-turn or while idle.

This PR adds one member to the script's API: ScriptedTurn.exit(code?: number | null), with a default code of 1. It records the exit the way the process adapters record an exit nobody requested (shared/process-session.ts, shared/stream-json/session.ts, shared/acp/session.ts): kernel.respond("", { kind: "exited", code }), a standalone response with no reason and no synthesized turn_ended. There is no new record shape. Everything after that comes from the existing kernel and folds:

  • A running turn gets no turn_ended. awaitTurnEnd and status() end it as failed: runtime_exited ("runtime exited"), as for a real process death with no stop request. The turn's signal aborts after the exit is recorded. Nothing the script emits afterwards is recorded, and a tool that settles afterwards gets no tool_call_ended.
  • Queued inputs held by the runtime never run, because the process that held them is gone.
  • While idle: a script keeps turn.exit and calls it after the turn has ended, the same pattern as turn.task. The status stays idle and keeps the last turn's outcome.
  • Later controls: prompt, steer, queue, withdraw and abort are rejected runtime_exited by the kernel's reachability rule.
  • Dispose after an exit is recorded and answered accepted at once, as in processSessionLifecycle and record-stream.md ("After exit it is recorded and answered accepted at once"). There is no second exited. A second dispose is still a no-op.
  • Task reports (turn.task) are no longer recorded after an exit. The predicate is now kernel.unreachable() === null instead of a private !disposed, so reachability is read off the stream. This also let the task emitter reuse the existing frame helper.
  • A second exit, or an exit after dispose began, records nothing.

The packages/oar/README.md entry for @botiverse/oar/testing mentions turn.exit.

How it was verified

  • New tests/scripted-exit.test.ts (6 tests):
    • exit mid-turn: outcome, events, status, the exited record, signal aborted, queued input not run, observers (rawEvents) see the exit
    • exit while idle: the last outcome is kept
    • every control after an exit is rejected runtime_exited
    • dispose after an exit is answered accepted, a second exit records nothing, and so does a second dispose
    • a task reports nothing after the exit. This test fails with the old !disposed predicate.
  • Shapes are pinned with toMatchInlineSnapshot.
  • CI=1 pnpm run check passed: 495 test files passed / 120 skipped, 4455 tests passed / 595 skipped, mock behavior 18 passed / 1 skipped.
  • OAR_TEST=scripted pnpm sea-trial passed (17 passed, 2 skipped).
  • These full runs were on 15d762c. The branch has since been rebased onto 83efa1e (current main) with no conflicts; on the rebased commit I re-ran typecheck, lint, the scripted test files and OAR_TEST=scripted pnpm sea-trial (17 passed, 2 skipped), all passing. The full check was not re-run after the rebase.

For reviewers to look at closely

  • API shape. exit lives on ScriptedTurn, so an exit while idle needs a kept function from an earlier turn. A session that never ran a turn can't exit. I chose this over a new session-level hook (for example ScriptedRuntimeOptions.onSession(handle)) because it is the smallest addition and mirrors turn.task. If you'd rather have a session-level handle, it's a small change.
  • Default code 1. It means "a non-zero exit". null (signal or no number) stays available explicitly.
  • Adding a required member to ScriptedTurn is additive for hosts that receive turns. It would break only a host that builds ScriptedTurn objects itself.
  • Dispose answer. Dispose after an exit now answers accepted; before, the scripted runtime always answered exited {code: 0}. Dispose without an exit is unchanged.
  • File length. scripted-runtime.ts is at 298 lines against the 300 max-lines rule. A few comments are trailing ones to stay under it. I merged this branch with the effort-refusal branch locally: it merges cleanly, comes to exactly 300 lines, and lint and both test files pass. Whichever lands second leaves no headroom; the next addition to this file will probably need to split it (for example, moving the exit and dispose bookkeeping into a helper beside scripted-tasks.ts).

🤖 Generated with Claude Code

…on its own

`scriptedRuntime` recorded `exited` only when the host disposed the
session, so a host could not test its most important failure path: the
runtime dying by itself, mid-turn or while idle.

`ScriptedTurn.exit(code = 1)` records the exit as the process adapters
record one nobody requested: a standalone `exited` response (requestId "",
no reason) and no synthesized `turn_ended`. The existing folds then end a
running turn `failed: runtime_exited`, the kernel rejects later controls
`runtime_exited`, and observers see the response. Held queued inputs never
run, the turn's signal aborts, and task reports stop (read off the stream,
not a private flag). Kept past its turn, `exit` ends an idle session.
Dispose after an exit is recorded and answered `accepted`, as the record
contract says.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stamp-build Bot added a commit that referenced this pull request Nov 16, 2026
…847)

<!-- stamp:review:v1 -->
<sup><img src="https://cdn.slock.ai/avatars/6aabf32c-20bc-4cba-b55a-2aa72b60999b/8ba4452ceb890f1930886ef4286fdb99.webp" width="16" height="16" align="absmiddle" alt=""> <b>Otter</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_b8d81bbbd635dd7c987fb912cf5a57c3"><picture><source media="(prefers-color-scheme: dark)" srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg" width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp →</a></sup>

---
<!-- /stamp:review:v1 -->

Hosts could only make a scripted session exit by disposing it, so they could not exercise an unexpected runtime exit. Add `ScriptedTurn.exit(code?)`: a standalone `exited` response ends an active turn through the existing folds, discards held inputs, aborts the script signal and suppresses later frames and task reports. An exit while idle keeps the previous turn outcome; disposal after exit is accepted without a second exit record.

Unchanged cherry-pick of TennyZhuang's #845 (`bc446c43a72f7cf1a779d5141341b805cb50e587`), preserving the original author and commit message. Thanks to TennyZhuang and Airwing for the implementation and regression cases. This Stamp PR supplies the repository CI and review path; the original PR will be closed with thanks after this merges.

Validation: full `CI=1 pnpm run check` passed (4,481 unit tests and 18 mock behavior cases); `OAR_TEST=scripted pnpm sea-trial` passed 17 cases with 2 expected skips. Six exit regressions cover active/idle exit, queue dropping, observers, rejected controls, disposal and late task reports. The cherry-picked tree matches the reviewed fork commit byte for byte.

Merge before the companion effort-refusal change #848 (from #846). That change will be rebased onto this merge and checked again before merging.

Co-authored-by: TennyZhuang <[email protected]>
@stamp-build

stamp-build Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Closed by Otter, an agent of open-agent-runtime that did not open it, through Stamp.

Reason:

Merged through #847 as 8e7db65 after all 41 checks passed. Thank you, TennyZhuang and Airwing, for the implementation and regression coverage. The original commit was cherry-picked unchanged with authorship preserved; closing this fork PR as completed.


Otter commented through Stamp · server open-agent-runtime · head when posted bc446c4
View in Stamp →

@stamp-build stamp-build Bot closed this Nov 16, 2026
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