Repository navigation
fix(claude): end -p queries and idle sessions via stdin EOF and update 2.1.328 refresh note - #1061
Conversation
|
CHANGES at 38b0ab0: the three query paths are right, but the same bug remains on Claude's most frequent exit. Read the diff,
Follow-up, separate task: the same class on other runtimes OAR ends itself. Codex rotates ChatGPT refresh tokens in
|
|
Addressed both review items in
Verified locally with full
|
|
CHANGES at 0603156, one item. The rest is right. Read the diff and the shared shutdown code ( What is right: the call-site audit is what I asked for, and each kept The one change:
Please move it into Nit: the doc paragraph has a six-line parenthetical. Split it into plain sentences: the upstream state as of 2.1.328, then what OAR does, then the Windows and POSIX difference.
|
…e, Qoder, and Qwen
|
Consolidated all three stdin-EOF closers into one shared helper in
|
|
GO at 79cfbb4. Read the new commit. I will approve after the 0.125.0 tag exists, once CI is green at this head.
|
…endencies (#1071) <!-- stamp:review:v1 --> <sup><img src="https://api.raft.build/api/avatars/pixel/ZXll.svg" width="16" height="16" align="absmiddle" alt=""> <b>Lookout</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_b803efe30032eaa31fb1805a73392e4a"><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 --> ## Summary Fix `oxlint` `import/max-dependencies` (11 > 10) introduced on `main` when PR #1060 (`openClaudeModelRequests`) and PR #1061 (`closeLineProcess`) landed back-to-back in `packages/oar/src/runtimes/claude/session.ts`. Uses `globalThis.crypto.randomUUID()` (matching `packages/oar/src/runtimes/claude/account-usage.ts:186`) and removes the `node:crypto` import so `claude/session.ts` returns to 10 imports. ## Verification - Local `pnpm run typecheck && pnpm run lint`: passed with 0 errors and 0 warnings. Co-authored-by: Lookout <[email protected]>
…-lived queries, document EOF rule and codex#62688 (#1074) <!-- stamp:review:v1 --> <sup><img src="https://api.raft.build/api/avatars/pixel/ZXll.svg" width="16" height="16" align="absmiddle" alt=""> <b>Lookout</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_6709b13d383e9f3221135d12979ab4b2"><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 --> ## Summary Follow up on `#core:#371` / PR #1061 (`#core:#372`) by routing Codex short-lived queries and idle session disposal plus Factory's ACP account process through stdin EOF shutdown (`shutdown: "stdin"` / `closeLineProcess`), documenting the stdin-EOF eligibility rule in `docs/development.md`, and linking `openai/codex#62688` in `docs/runtimes/codex.md`. ## Changes & Measured EOF Evidence - **Codex (`packages/oar/src/runtimes/codex/app-server-client.ts`, `home-initialization.ts`, `session.ts`, `account-request.ts`, `account-usage.ts`, `list-models.ts`, `inventory.ts`, `login.ts`):** - Added `shutdown` to `AppServerProcessOptions` and `close()` (calling `closeLineProcess(child)`) to `AppServerClient` and `queuedClient`. - Idle `codexSession.dispose()` now uses `await client.close()` (stdin EOF with `killGraceMs()` fallback), while an active turn or manual compaction still kills immediately (`client.kill(); await client.exited;`), matching Claude/Qoder/Qwen. - Short-lived Codex `app-server` queries (`accountUsage`, `redeemLimitReset`, `listModels`, inventory) pass `shutdown: "stdin"`; `codexLogin` uses `await app.close()` (stdin EOF) on normal completion while keeping immediate `app.kill()` on cancel, timeout, or interaction failure so polling workers stop without waiting for `killGraceMs()`. - **Measured EOF exit (`#core:#371` audit):** `codex app-server` (`0.170.0` and `0.171.0`) exits cleanly (`code 0`) in 8 to 54 ms on stdin EOF (18 ms on `0.171.0`). - Regression tests: `tests/codex/codex-shutdown.test.ts`. - **Factory (`packages/oar/src/runtimes/factory/account.ts`):** - Added `shutdown: "stdin"` to `withDroidAcp`'s `spawnLineProcess` (matching `factory/client.ts:73`). - **Measured EOF exit (`#core:#371` audit):** `droid exec --output-format acp` (`1.16.0`) runs `owner-loss` -> `dispose()` and exits cleanly (`code 0`, 723 ms) on stdin EOF. - Regression test: `tests/factory/factory-account-shutdown.test.ts`. - **Docs (`docs/development.md`, `docs/runtimes/codex.md`):** - `docs/development.md`: added the rule that stdin EOF shutdown (`shutdown: "stdin"` / `closeLineProcess`) may only be used on runtimes measured to exit on stdin EOF; runtimes that stay open on EOF (such as CodeBuddy `--acp`) must not use it, and shared `startAcpProcess` must not enable it globally. - `docs/runtimes/codex.md`: documented idle EOF disposal, short-lived query EOF shutdown, and linked `https://github.com/openai/codex/issues/62688` noting that dropping an in-flight background `/oauth/token` refresh on exit (both stdin EOF and `SIGTERM`) is upstream Codex behavior (observed on `0.171.0`) that clean EOF shutdown from OAR cannot prevent. ## Call-Site Audit - **`startAppServerClient` (`packages/oar/src/runtimes/codex/`):** Checked all 5 callers (`session.ts`, `account-request.ts`, `list-models.ts`, `inventory.ts`, `login.ts`): idle session `dispose()` uses `closeLineProcess`, active turn `dispose()` keeps immediate `kill()`, `login.ts` uses `close()` on normal completion and `kill()` on cancel/timeout/interaction failure, and all 3 short-lived query callers (`account-request.ts`, `list-models.ts`, `inventory.ts`) pass `shutdown: "stdin"`. - **Factory `spawnLineProcess`:** Checked both call sites (`factory/client.ts:73` already had `shutdown: "stdin"`; `factory/account.ts:46` now adds `shutdown: "stdin"`). - **Unchanged by design (negative constraint):** `codebuddy --acp` (`2.173.0`) was measured staying open past 5 s on stdin EOF, so `shared/acp/process.ts` (`startAcpProcess`) is intentionally NOT changed globally. ## Verification - Local `CI=1 pnpm run check` on rebased head `e841fbed` (base `ce5a24b3`): `typecheck` passed, `oxlint --type-aware --deny-warnings` 0 errors / 0 warnings, `vitest run` 589 passed / 147 skipped (5541 passed / 703 skipped), mock `sea-trial` 19 passed / 1 skipped / 0 failed. Co-authored-by: Lookout <[email protected]>
|
New failure in post-merge full tests: workflow Newly failing:
Please fix. See logs: |
<!-- stamp:review:v1 --> <sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg" width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_010f166b1c3ba63a625f97aa49c7a328"><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 --> ## OAR 0.126.0 ### Behavior changes hosts should know - **`installation()` refuses programs that are not the vendor CLI, and every refusal is typed** (#1084). The `unsupported` snapshot now always carries a `code`, and the old untyped variant is gone, so custom runtime probes must set one: - `version_unsupported`: the vendor CLI is outside the supported range. This is the only code admitted to `checkUpdate()` and `upgrade()`. Hosts should show every other code as a setup problem, not reinstall. - `unrecognized_executable`: the program in the slot does not identify as the vendor CLI. Identity comes from its version output, so a wrapper (for example an `OAR_CLAUDE_BIN` script) that prints a bare version is now refused; Claude must print `(Claude Code)`. - `readiness_failed`: the runtime's readiness check (`--help`, `app-server --help`, `acp --help` and the like) exited nonzero, or `--version` failed where the runtime declares an identity or version policy. - Host refusals: `unsupported_platform`, `unsupported_node_version`, `unsupported_host` (for example Pi RPC inside a single executable or Electron, or Cursor subprocess mode inside a single executable) and `dependency_missing` (a required module such as Pi's RPC entry or Cursor's SDK cannot be resolved). Cursor now refuses Node below 22.13.0 in both modes. - **OpenCode now has a version range**: `>=1.18.30 <2.0.0 || >=2.0.27 <3.0.0`. Installs below 1.18.30, at 2.0.0 to 2.0.26, or on 3.x that worked before are now `version_unsupported`. - Candidate selection changed: a refused candidate falls through to the next one, and a vendor install that is only too old wins over a refusal of another kind. Antigravity, DSH, OpenCode, Qoder and Qwen gained a `--help` readiness probe, so an uncached probe starts one more process. - **`rateLimited` means the whole account is limited** (#1073). On Codex only the account bucket and its credits set it; a single-model bucket such as Spark stays in `windows`. On Claude only the five-hour and seven-day windows set it; per-model windows and `seven_day_oauth_apps` do not, and unlimited Extra Usage counts as headroom. `usedRatio` never rounds an unexhausted reading up to 1, and on Codex it no longer exceeds 1. Codex no longer reports `reauth_required` or `unsupported` for process exits, initialize failures or timeouts, and its usage and limit-reset errors carry the native `cause`. Grok reports `reauth_required` only for ACP code `-32000`, not for any error mentioning sign-in. Codex's legacy single-bucket view gets `scope: account`. Antigravity sets `rateLimited` when every group is exhausted and credits are at or below zero. - **`plan` is the name the runtime shows the user** (#1076). Claude reads `oauthAccount.planDisplayName` when the stored account matches the signed-in one, and falls back to the native plan code otherwise. Hosts that compared `plan` against native codes such as `max` will now see display names on `authStatus`, `login` and `accountUsage`. - **Idle sessions and short-lived queries end through stdin EOF** (#1061, #1074). Claude and Codex now end an idle session, and their query processes (usage, models, skills, inventory; on Codex also limit reset and a completed login), by closing stdin and killing the tree only after the kill grace. Factory's account process does the same. A session with an active turn is still stopped at once. Qoder and Qwen share the same path, so their grace moved from a fixed 5 s to the kill grace (10 s by default, `OAR_KILL_GRACE_MS`). - **Antigravity quota notices mid-turn fail the turn as `quota` with `resetsAt`** (#1068), after earlier tool work too. Normal text that quotes the notice still completes. ### New - **Credentials declared for every runtime** (#1085). `Runtime.credentials` on all 15 built-in runtimes lists its stores (`directoryEnv`, `fallbackDirectoryEnvs`, keychain `service`), its variables with the `provider` and logical `field` each belongs to (for stripping, redaction and error attribution), `scope` (`single_account` or `per_provider`), `management` (`native`, or `external`: no native login, the person or host supplies the credential), `signInPaste`, `usageDirectoryEnv` and key `interpolation`. `LoginAccount.accountId` is set on Claude (`oauthAccount.accountUuid`, only when the stored account matches the signed-in one) and on Codex (only when the login lives in Codex's default file store and the file's sign-in token matches the signed-in account). A missing `accountId` never means "no account". - **Latest model request** (#1060, #1072). Open with `modelRequests: "latest"` and call `Session.lastModelRequest()` for the last attributed root request, read on demand and redacted. Claude (2.1.274 and later; resume verified on 2.1.326) reads its own capture, which writes the body of every model call, child and auxiliary calls included, to a private directory. Pi SDK keeps the body after Pi and extensions have transformed it, for Anthropic Messages, OpenAI Chat Completions and OpenAI Responses models; other model APIs are refused at open. Pi RPC and all other runtimes declare the option refused. `RefusableSessionOption` gains `"modelRequests"`. - **Native session file** (#1065, #1086). `Session.nativeSessionFile()` returns the file Codex (0.169.0 and later) or Pi has saved, once it exists, on fresh, resumed and forked sessions, and still after disposal. It returns `null` for a path that contains a credential. The path is the runtime's own spelling and can differ between opens of the same session (Codex on Windows adds `\\?\` on resume); compare files by filesystem identity. - **Claude side questions** (#1066). `Runtime.sideQuestion` answers one question about a saved Claude session from a disposable native fork with no tools, no MCP servers, no slash commands and no user or project hooks. It makes its own provider request with Claude's default model unless `model` is given, and times out after 60 s by default. The source can be running or stopped and is left unchanged. Claude Code 2.1.326 and later. - **Codex applied file changes per path** (#1063) on `tool_call_ended.fileChanges` and the session view, with moves kept together. Codex 0.160.1 and later. - `SessionCapabilityDeclaration` gains `sideQuestion`, `fileChanges` and `nativeSessionFile`. New exported types include `ModelRequest`, `FileChange`, `SideQuestionOptions`, the installation refusal types and `CredentialField`. ### Fixes - **Steer and abort** (#1070). - Pi RPC no longer kills a live process 10 s after a refused abort, and Pi SDK aborts between `agent_end` and `agent_settled`. - Factory retries reach `droid` after a refused interrupt. - Cursor bounds `abort()` at 10 s. In subprocess mode it stops the child if the run ignores cancel; in-process, a hung cancel answers `accepted` after 10 s while the run may continue. A live native refusal is `runtime_refused`. - Codex abort refusals keep `session_not_found` and the native error. - DSH maps process exit to `runtime_exited`, answers a prompt sent while another is starting with `busy`, and answers idle steer with `no_active_turn` before checking images. - Pi Durable agrees with `status()` right after `prompt()`, answers idle steer with `no_active_turn`, still returns `accepted` when a status read fails after a durable commit, bounds `abort()` at 10 s and reports aborted inbox inputs as `input_dropped`. - **DSH cold profile initialization** (#1080). Concurrent session, model and skill startup on a fresh DSH profile no longer races (3 in 100 shared-profile pairs failed on 0.2.2-rc.5): it now uses the one-opener coordinator Codex already had. This holds within one OAR process; separate processes can still race. ### Tests and docs - Configured-append contract on Antigravity, DSH, Factory, Grok, Pi Durable and Qoder (#1057, #1077); Qoder notification abort (#1059); Windows OpenCode startup diagnostics (#1064, #1078, #1083); tests tell processes apart across PID reuse (#1081, #1087). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Cindy <[email protected]>
Summary
Close OAR's short-lived
claude -pquery children (claudeAccountUsage,claudeListModels, andclaudeSkills/claudeCommands/claudeMcpServers/claudeTools) and idleclaudeSessioninstances ondispose()viastdinEOF instead of immediateSIGTERM(POSIX) ortaskkill /T /F(Windows), while keeping immediate process-tree kill when disposing a session with an active turn. Unify the stdin-EOF close helper (closeLineProcess) inshared/executable/close.tsacross Claude, Qoder, and Qwen, and updatedocs/runtimes/claude.mdwith verified Claude Code2.1.328evidence forclaude-code#102265.Single stdin-EOF close path (
packages/oar/src/shared/executable/close.ts)closeLineProcessinpackages/oar/src/shared/executable/close.tsis the single stdin-EOF close path for line processes across OAR, so follow-up#371extends it rather than adding another copy. It replaces the previous separatecloseQoderandcloseQwencopies (and Claude's session close), callingprepareShutdown()beforemarkNativeStop()andstdin.end()withkillGraceMs()fallback so process-tree cleanup still catches descendants when the root exits on EOF and honorsOAR_KILL_GRACE_MS.Investigation (
[sym]+[env]Claude Code2.1.328and[src]OAR)2.1.328exit wait ([sym]+[env]):ShutdownManager.waitForHeldOAuthRefresh(exitCode)waits up toyls()on normal exit (exitCode === 0), whereyls() = untilDeadline ? Math.max(2000, 8500 - uptimeMs) : 2000, and caps signal/non-zero exits (SIGTERM->shutdown(143)) at2000 ms(A6e = 2000,Ykl = 8500).claude auth status) enableuntilDeadline; plainclaude -pdoes not, soclaude -pexits after2000 ms(OAuth refresh still in flight after 2000ms; exiting without waiting further), leaving the retired refresh token in.credentials.jsonif the OAuth exchange takes longer.claude 2.1.328with a local delayed OAuth server confirmed:1200 msrefresh delay onlist_models: rotated refresh token saved (exitafter ~920 to 950 ms).2800 msrefresh delay onlist_models: hit the2000 msexit wait timeout on bothSIGTERMandstdinEOF (savedRotated: false, old retired token left on disk).get_usage(accountUsage) awaits the OAuth refresh before answeringcontrol_response, so the rotated token is already written before shutdown begins.[src]+[env]):claudeAccountUsage,claudeListModels,claudeinventory queries, andclaudeSessiondispose()all spawnedclaude -pwith{ killTree: true }and noshutdown: "stdin"/ customclose.processShutdown.close()immediately rantaskkill /pid <pid> /T /Fat0 ms, hard-terminatingclaude.exebeforewaitForHeldOAuthRefreshcould run at all.2.1.328already givesSIGTERMthe same2000 msrefresh wait bound as a normalclaude -pexit (shortenOAuthRefreshWait()caps it there), so ending viastdinEOF mainly removes the EOF-vs-SIGTERMrace and avoids truncating any longer normal-exit wait if upstream raises it.stdinEOF probes onclaude 2.1.292and2.1.328confirmed clean code-0 exits onstdinEOF across all three query paths (71to127 ms) and idle sessions (282to328 ms).Call-site audit (
packages/oar/src/runtimes/claude/)Every
spawnLineProcess,runExecutable,spawnLoginProcess, and.kill()call site inpackages/oar/src/runtimes/claude/was checked:account-usage.ts(spawnLineProcess): addedshutdown: "stdin".list-models.ts(spawnLineProcess): addedshutdown: "stdin".inventory.ts(spawnLineProcess): addedshutdown: "stdin".session.ts(forlaunch.tsspawnLineProcess): idledispose()uses sharedcloseLineProcess(child); active-turndispose()still callschild.kill()immediately.account-usage.ts(runExecutable --help): waits for Claude's own exit; no auth involved.auth-status.ts(runExecutable auth status --json): waits for Claude's own exit (and Claude enables the 8.5 suntilDeadlineonauth status).login.ts(spawnLoginProcess auth login): waits for Claude's own exit on normal login; kills only on caller cancel/timeout.launch.ts(child?.kill()in spawncatch): only runs if startup fails before the session opens.open-settings.ts(child.kill()on open refusal/timeout): failed-open refusal/timeout abort path.limit-reset/driver.ts(terminal.kill()): interactive PTY TUI session, not stream-jsonstdinEOF.Changes
packages/oar/src/shared/executable/close.ts(exported fromindex.ts): SinglecloseLineProcesshelper (stopping()guards +prepareShutdown()+markNativeStop()+stdin.end()+killGraceMs()fallback).packages/oar/src/runtimes/claude/,qoder/,qwen/: UsecloseLineProcessacross Claude (session.ts), Qoder (session.ts,list-models.ts), and Qwen (session.ts,list-models.ts), removingcloseQoderandqwen/close.ts(plus updating sea-trial, experiment, and unit test callers). Passshutdown: "stdin"on Claude's three short-lived-pqueries (account-usage.ts,list-models.ts,inventory.ts).tests/claude/claude-shutdown.test.ts&tests/adapter-eof-cleanup.test.ts: Cross-platform tests covering Claude queries + idle/active sessiondispose()and pre-EOF capture cleanup throughcloseLineProcess+qoderDaemonSession.tests/fixtures/fake-line-process.ts: LetScriptedLineProcessexit 0 onstdinEOF by default (and endstdinonkill(), matching realprocessShutdown.close()), with{ ignoreEof: true }for tests exercising unresponsive or slow-to-exit processes.docs/runtimes/claude.md: Update the#402/claude-code#102265note with2.1.328evidence covering both queries and sessions, split into plain sentences, distinguishing Windows 0 mstaskkill /T /Floss from POSIX's shared 2000 ms bound.Verification
2.1.292and2.1.328confirmed cleanstdinEOF exits across queries (71to127 ms) and idle sessions (282to328 ms), and reproduced the2.1.3282000 msOAuth refresh exit timeout with a local HTTPS OAuth stand-in.CI=1 pnpm run checkpassed locally (579 test files / 5,502 tests + 19 mock sea-trial cases).