Repository navigation
fix: release completed terminal spawn inputs - #21139
Conversation
📝 WalkthroughWalkthroughThe change refactors terminal session callbacks to avoid retaining completed spawn inputs. It adds lifecycle tests and Node/Electron reproduction fixtures that inspect garbage-collected request, environment, history, and signal inputs. It also adds source-hash validation, baseline configurations, runtime audit reports, and documentation for retention and lifecycle results. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to The documented audit commands can report success by exiting before their timeout when lifecycle work stalls, leaving retention validation incomplete. Keep both timeouts referenced before merging. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, scope, and validation, but it does not follow the required template. It omits the required Linked Issue, Visual Proof or explicit N/A, Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Resolution Update the description to include all required template sections. Add the linked issue after "Fixes #", state "N/A" with a reason for Visual Proof if no UI change exists, document testing platforms and results, complete the required checkboxes, and address AI Disclosure, Review, Agent skill upstream boundary, and Notes. Full details: Docstring CoverageExplanation Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 9 files. (15 skipped: 15 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a23af695-c2ab-4ebd-872b-e847fa1a9a8d
📒 Files selected for processing (24)
docs/audits/terminal-completed-spawn-inputs/README.mddocs/audits/terminal-completed-spawn-inputs/admission-control.cjsdocs/audits/terminal-completed-spawn-inputs/admission-electron.jsondocs/audits/terminal-completed-spawn-inputs/admission-node.jsondocs/audits/terminal-completed-spawn-inputs/baseline.config.mjsdocs/audits/terminal-completed-spawn-inputs/electron-baseline.jsondocs/audits/terminal-completed-spawn-inputs/electron-fixed.jsondocs/audits/terminal-completed-spawn-inputs/fix.patchdocs/audits/terminal-completed-spawn-inputs/mapped-admission-electron.jsondocs/audits/terminal-completed-spawn-inputs/mapped-admission-node.jsondocs/audits/terminal-completed-spawn-inputs/mapped-electron-baseline.jsondocs/audits/terminal-completed-spawn-inputs/mapped-electron-fixed.jsondocs/audits/terminal-completed-spawn-inputs/mapped-node-baseline.jsondocs/audits/terminal-completed-spawn-inputs/mapped-node-fixed.jsondocs/audits/terminal-completed-spawn-inputs/node-baseline.jsondocs/audits/terminal-completed-spawn-inputs/node-fixed.jsondocs/audits/terminal-completed-spawn-inputs/reproduce.cjsdocs/audits/terminal-completed-spawn-inputs/source-versions.jsondocs/audits/terminal-completed-spawn-inputs/spawn-fixture.cjsdocs/audits/terminal-completed-spawn-inputs/spawn-source.cjssrc/main/daemon/session-output-pipeline.tssrc/main/daemon/terminal-host-session-create.tssrc/main/daemon/terminal-host-spawn-input-retention.test.tssrc/main/daemon/terminal-host.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| main().catch((error) => { | ||
| console.error(error) | ||
| process.exitCode = 1 | ||
| }) | ||
| setTimeout(() => { | ||
| console.error('fixture timeout') | ||
| process.exit(2) | ||
| }, 15000).unref() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,205p' docs/audits/terminal-completed-spawn-inputs/admission-control.cjsRepository: stablyai/orca
Length of output: 5540
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- audit references and runner definitions ---'
rg -n --glob '!node_modules' --glob '!dist' 'admission-control|admission-node|mapped-admission|reproduce\.cjs|fixture timeout|setTimeout\(.*15000|\.unref\(\)' package.json package-lock.json docs scripts src 2>/dev/null | head -200
printf '%s\n' '--- directly bound fixture source ---'
wc -l docs/audits/terminal-completed-spawn-inputs/spawn-fixture.cjs docs/audits/terminal-completed-spawn-inputs/spawn-source.cjs
sed -n '1,240p' docs/audits/terminal-completed-spawn-inputs/spawn-fixture.cjs
printf '%s\n' '--- relevant admission audit helper definitions ---'
rg -n 'async function|await |createOrAttach|dispose|subprocess|setTimeout|unref|main\(' docs/audits/terminal-completed-spawn-inputs/admission-control.cjs docs/audits/terminal-completed-spawn-inputs/spawn-fixture.cjsRepository: stablyai/orca
Length of output: 16647
Keep the admission-control failure timeout referenced. README.md runs admission-control.cjs as a separate process, so reproduce.cjs cannot keep it alive. If an awaited lifecycle promise stalls after other handles drain, .unref() allows Node to exit with status 0 before fixture timeout runs and before the audit writes its report.
setTimeout(() => {
console.error('fixture timeout')
process.exit(2)
-}, 15000).unref()
+}, 15000)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| main().catch((error) => { | |
| console.error(error) | |
| process.exitCode = 1 | |
| }) | |
| setTimeout(() => { | |
| console.error('fixture timeout') | |
| process.exit(2) | |
| }, 15000).unref() | |
| main().catch((error) => { | |
| console.error(error) | |
| process.exitCode = 1 | |
| }) | |
| setTimeout(() => { | |
| console.error('fixture timeout') | |
| process.exit(2) | |
| }, 15000) |
| setTimeout(() => { | ||
| console.error('fixture timeout') | ||
| process.exit(2) | ||
| }, 15000).unref() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,230p' docs/audits/terminal-completed-spawn-inputs/reproduce.cjs
sed -n '1,100p' docs/audits/terminal-completed-spawn-inputs/spawn-fixture.cjsRepository: stablyai/orca
Length of output: 8383
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- spawn-source outline ---'
ast-grep outline docs/audits/terminal-completed-spawn-inputs/spawn-source.cjs
printf '%s\n' '--- spawn-source relevant bindings ---'
rg -n -C 12 'function load|async function load|createOrAttach|spawnSubprocess|sourceMode|evaluatedSourceHashes' docs/audits/terminal-completed-spawn-inputs/spawn-source.cjs
printf '%s\n' '--- related source files ---'
rg -n -C 8 'createOrAttach|spawnSubprocess' docs/audits/terminal-completed-spawn-inputs -g '*.cjs' -g '*.js' -g '*.mjs'Repository: stablyai/orca
Length of output: 20859
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- bundled source inputs ---'
sed -n '52,100p' docs/audits/terminal-completed-spawn-inputs/spawn-source.cjs
cat docs/audits/terminal-completed-spawn-inputs/source-versions.json
printf '%s\n' '--- terminal host outline ---'
ast-grep outline src/main/daemon/terminal-host.ts
printf '%s\n' '--- terminal host lifecycle ---'
rg -n -C 14 'class TerminalHost|constructor|createOrAttach|spawnSubprocess|dispose|await' src/main/daemon/terminal-host.tsRepository: stablyai/orca
Length of output: 17858
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- session creation implementation ---'
rg -n -C 20 'spawnSubprocess|await .*spawn|createOrAttachTerminalSession|setTimeout|setImmediate|setInterval' src/main/daemon/terminal-host-session-create.tsRepository: stablyai/orca
Length of output: 5432
Keep the failure timeout referenced.
pendingInputs() awaits created.creation, while its spawnSubprocess callback awaits the unresolved gate.promise. This leaves only unresolved Promises and the unreferenced timer. Node can exit with status 0 before the timeout runs, so main() may produce no report.
Remove .unref() so the audit fails after 15 seconds.
Proposed fix
setTimeout(() => {
console.error('fixture timeout')
process.exit(2)
-}, 15000).unref()
+}, 15000)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| setTimeout(() => { | |
| console.error('fixture timeout') | |
| process.exit(2) | |
| }, 15000).unref() | |
| setTimeout(() => { | |
| console.error('fixture timeout') | |
| process.exit(2) | |
| }, 15000) |
There was a problem hiding this comment.
️ No critical issues — the production fix is sound and the regression test is genuine. One reproducibility nit inline.
Reviewed changes
- Exit callback no longer captures the request —
terminal-host-session-create.tsbuildsonExitfrom a newcreateSessionExitHandler(deps.onSessionExit, sessionId, generation)instead of an inline arrow closing over the wholeoptsrequest, soenv,historySeedChunks,cancelSignal, and the request object are no longer pinned for the session's lifetime. - Exit/reap body moved to a bound method —
TerminalHost.createOrAttachnow passesthis.handleSessionExit.bind(this), taking the long-lived callback out of thecreateOrAttachlexical scope whose shared context other closures captureoptionswith. Body is byte-for-byte the same;maxTombstonesis dropped as a field but still honored as an option. - Pipeline captures the subprocess, not its options —
session-output-pipeline.tsdestructuressubprocess/isAlivesoconfirmShellForegroundno longer retains the pipeline options (including the consumedhistorySeedChunks).subprocessremains the call receiver, as the new test pins. - New retention regression test —
terminal-host-spawn-input-retention.test.tsusesWeakRefplus forced GC to assert request/env/history/signal collection for live sessions, with lifecycle controls for exit/reap/incarnation replacement and shell recovery. - Audit evidence —
docs/audits/terminal-completed-spawn-inputs/(README, reproduction scripts, pinned JSON reports,fix.patch), whose worktree hashes match the recorded publication-main "fixed" pair for all three modules.
Verification I ran against head 66d12af6a5: the new suite passes 4/4; reverting the three production files to baseline makes exactly the two retention tests fail (so the test can fail); terminal-host.test.ts 38/38; oxlint clean on the four changed files; and reproduce.cjs/admission-control.cjs both run clean on this checkout.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| const path = require('node:path') | ||
| const Module = require('node:module') | ||
| const esbuild = require('esbuild') | ||
| const { applyPatch, parsePatch, reversePatch } = require('diff') |
There was a problem hiding this comment.
require('diff') is not a declared dependency of the root package — it only resolves through shadcn → ts-morph plus shamefullyHoist: true. Since the README tells readers to run this script from a clean worktree, a dependency-graph change (or shadcn dropping diff) would break it with MODULE_NOT_FOUND. Worth either declaring diff in package.json or using a parser the repo already depends on.
Technical details
# Undeclared `diff` dependency in committed audit script
## Affected sites
- `docs/audits/terminal-completed-spawn-inputs/spawn-source.cjs:7` — `require('diff')`
- `package.json` — no `diff` entry; the only root reference is `devDependencies.shadcn`
## Evidence
- `node_modules/diff` is a symlink into `.pnpm/[email protected]`, pulled in transitively by `shadcn`/`ts-morph`; `pnpm-workspace.yaml` sets `shamefullyHoist: true`, which is the only reason it is reachable.
- No other source or config file in the repo requires `diff` directly, so nothing else keeps it in the graph.
## Required outcome
- The script's `require('diff')` must resolve under a plain `pnpm install --frozen-lockfile` for the currently supported dependency graph.
## Suggested approach (optional)
- Add `diff` (v8) to `devDependencies`, or drop the dependency by reconstructing the baseline without `applyPatch`/`reversePatch`.Co-authored-by: m4air <[email protected]>

Completed terminal creation leaves long-lived callbacks holding the original request, environment and already-consumed history chunks. Those inputs remain reachable for the live session even though the emulator has finished consuming its seed.
Capture only session identity in the exit callback, move its unchanged host exit/reap body into a bound method, and capture the subprocess directly in foreground confirmation. Cancellation, admission, process ownership, history content and wire behavior follow their existing paths.
Validation
docs/audits/terminal-completed-spawn-inputs/checks exact baseline/fixed hashes for the audit and independent main projection. Mapped-main proofs use current worktree dependencies; they are not a full historical build.The proof uses an inert subprocess and tiny history seeds. The native PTY wrapper has a separate merged-environment capture, outside this patch. This establishes avoidable retention per live terminal; it does not attribute #19831 or establish an incident-scale byte count.