Skip to content

fix: release completed terminal spawn inputs - #21139

Merged
OrcaWin merged 1 commit into
mainfrom
np-oom-scan-completed-spawn-inputs
Sep 18, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
np-oom-scan-completed-spawn-inputs

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​214 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​214
Prod 23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1801 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1781

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

  • Actual TerminalHost, Session and output pipeline: three live sessions retain three sets of spawn inputs before and zero after, on Node 26 and Electron 43.7 / Node 24. Pending spawns still retain their required inputs; exit/reap, generation replacement and foreground receiver controls pass.
  • Actual daemon admission confirms original request environment/history become collectible while attached. Preparation/signal metadata remains owned by an attached stream and becomes collectible after detach.
  • 67 tests across nine suites, full desktop typechecks, focused lint and changed-code quality pass. Independent admission review and root proofs pass.
  • Portable evidence in 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.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The 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 66d12

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 che… 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 checkbo…
Docstring Coverage ⚠️ Warning 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: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: releasing completed terminal spawn inputs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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 Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a23af695-c2ab-4ebd-872b-e847fa1a9a8d

📥 Commits

Reviewing files that changed from the base of the PR and between f36a7ce and 66d12af.

📒 Files selected for processing (24)
  • docs/audits/terminal-completed-spawn-inputs/README.md
  • docs/audits/terminal-completed-spawn-inputs/admission-control.cjs
  • docs/audits/terminal-completed-spawn-inputs/admission-electron.json
  • docs/audits/terminal-completed-spawn-inputs/admission-node.json
  • docs/audits/terminal-completed-spawn-inputs/baseline.config.mjs
  • docs/audits/terminal-completed-spawn-inputs/electron-baseline.json
  • docs/audits/terminal-completed-spawn-inputs/electron-fixed.json
  • docs/audits/terminal-completed-spawn-inputs/fix.patch
  • docs/audits/terminal-completed-spawn-inputs/mapped-admission-electron.json
  • docs/audits/terminal-completed-spawn-inputs/mapped-admission-node.json
  • docs/audits/terminal-completed-spawn-inputs/mapped-electron-baseline.json
  • docs/audits/terminal-completed-spawn-inputs/mapped-electron-fixed.json
  • docs/audits/terminal-completed-spawn-inputs/mapped-node-baseline.json
  • docs/audits/terminal-completed-spawn-inputs/mapped-node-fixed.json
  • docs/audits/terminal-completed-spawn-inputs/node-baseline.json
  • docs/audits/terminal-completed-spawn-inputs/node-fixed.json
  • docs/audits/terminal-completed-spawn-inputs/reproduce.cjs
  • docs/audits/terminal-completed-spawn-inputs/source-versions.json
  • docs/audits/terminal-completed-spawn-inputs/spawn-fixture.cjs
  • docs/audits/terminal-completed-spawn-inputs/spawn-source.cjs
  • src/main/daemon/session-output-pipeline.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host-spawn-input-retention.test.ts
  • src/main/daemon/terminal-host.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

Comment on lines +165 to +172
main().catch((error) => {
console.error(error)
process.exitCode = 1
})
setTimeout(() => {
console.error('fixture timeout')
process.exit(2)
}, 15000).unref()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,205p' docs/audits/terminal-completed-spawn-inputs/admission-control.cjs

Repository: 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.cjs

Repository: 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.

Suggested change
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)

Comment on lines +205 to +208
setTimeout(() => {
console.error('fixture timeout')
process.exit(2)
}, 15000).unref()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.cjs

Repository: 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.ts

Repository: 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.ts

Repository: 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.

Suggested change
setTimeout(() => {
console.error('fixture timeout')
process.exit(2)
}, 15000).unref()
setTimeout(() => {
console.error('fixture timeout')
process.exit(2)
}, 15000)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

️ 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.ts builds onExit from a new createSessionExitHandler(deps.onSessionExit, sessionId, generation) instead of an inline arrow closing over the whole opts request, so env, historySeedChunks, cancelSignal, and the request object are no longer pinned for the session's lifetime.
  • Exit/reap body moved to a bound method — TerminalHost.createOrAttach now passes this.handleSessionExit.bind(this), taking the long-lived callback out of the createOrAttach lexical scope whose shared context other closures capture options with. Body is byte-for-byte the same; maxTombstones is dropped as a field but still honored as an option.
  • Pipeline captures the subprocess, not its options — session-output-pipeline.ts destructures subprocess/isAlive so confirmShellForeground no longer retains the pipeline options (including the consumed historySeedChunks). subprocess remains the call receiver, as the new test pins.
  • New retention regression test — terminal-host-spawn-input-retention.test.ts uses WeakRef plus 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

@OrcaWin
OrcaWin merged commit 79800e6 into main Sep 18, 2026
34 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 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