Repository navigation
feat(testing): let a script make the scripted runtime's process exit on its own - #845
Closed
TennyZhuang wants to merge 1 commit into
Closed
TennyZhuang wants to merge 1 commit into
TennyZhuang wants to merge 1 commit into
Conversation
…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]>
This was referenced Nov 16, 2026
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]>
Contributor
|
Closed by Otter, an agent of 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.
|
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.
What changes and why
Today
scriptedRuntime(@botiverse/oar/testing) recordsexitedonly 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 noreasonand no synthesizedturn_ended. There is no new record shape. Everything after that comes from the existing kernel and folds:turn_ended.awaitTurnEndandstatus()end it asfailed: 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 notool_call_ended.turn.exitand calls it after the turn has ended, the same pattern asturn.task. The status stays idle and keeps the last turn's outcome.runtime_exitedby the kernel's reachability rule.acceptedat once, as inprocessSessionLifecycleand record-stream.md ("After exit it is recorded and answeredacceptedat once"). There is no secondexited. A second dispose is still a no-op.turn.task) are no longer recorded after an exit. The predicate is nowkernel.unreachable() === nullinstead of a private!disposed, so reachability is read off the stream. This also let the task emitter reuse the existingframehelper.exit, or anexitafter dispose began, records nothing.The
packages/oar/README.mdentry for@botiverse/oar/testingmentionsturn.exit.How it was verified
tests/scripted-exit.test.ts(6 tests):rawEvents) see the exitruntime_exitedaccepted, a second exit records nothing, and so does a second dispose!disposedpredicate.toMatchInlineSnapshot.CI=1 pnpm run checkpassed: 495 test files passed / 120 skipped, 4455 tests passed / 595 skipped, mock behavior 18 passed / 1 skipped.OAR_TEST=scripted pnpm sea-trialpassed (17 passed, 2 skipped).15d762c. The branch has since been rebased onto83efa1e(current main) with no conflicts; on the rebased commit I re-ran typecheck, lint, the scripted test files andOAR_TEST=scripted pnpm sea-trial(17 passed, 2 skipped), all passing. The fullcheckwas not re-run after the rebase.For reviewers to look at closely
exitlives onScriptedTurn, 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 exampleScriptedRuntimeOptions.onSession(handle)) because it is the smallest addition and mirrorsturn.task. If you'd rather have a session-level handle, it's a small change.null(signal or no number) stays available explicitly.ScriptedTurnis additive for hosts that receive turns. It would break only a host that buildsScriptedTurnobjects itself.accepted; before, the scripted runtime always answeredexited {code: 0}. Dispose without an exit is unchanged.scripted-runtime.tsis at 298 lines against the 300max-linesrule. 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 besidescripted-tasks.ts).🤖 Generated with Claude Code