Skip to content

Release completed browser helper drain timers - #26210

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-agent-browser-exit-drain-retirement
Oct 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-agent-browser-exit-drain-retirement

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

After a browser command returns a large result, Orca can briefly keep the finished helper and extra copies of its reply alive. Release the helper's fallback timer when the command completes.

What Changed

Keep the existing 500 ms pipe-drain timer handle and clear it in the execFile completion callback. Results, errors, cancellation, output limits, and the fallback delay stay the same.

Add lifetime regressions using the full browser bridge and real helper subprocesses: completed child collection while the bridge stays usable, timer retirement after error/cancellation, and spawn failure without a drain timer. The existing 5 MiB inherited-pipe regression remains unchanged.

Why

The timer callback captures the child process, which still owns Node's buffered reply and completion context after normal closure. Retiring this finished timer removes that temporary ownership. The fallback itself remains necessary when a Windows daemon inherits the helper's pipes.

Seven alternating before/after trials ran four real helpers returning 5 MiB each, keeping the bridge-method fixture owner live and retaining only output lengths and hashes. At 4.8–8.6 ms after completion and GC, median extra heap was 42,249,944 → 280,024 bytes; completed child references were 4 → 0. Every reply length and SHA-256 matched. After 600 ms, both variants released all children. Four 256 KiB replies measured 2,414,904 → 298,440 bytes; four 1 KiB replies measured 312,880 → 287,624 bytes.

This is transient retention for supported generated large replies, not a permanent leak, captured typical workload, typing-latency result, or CPU speedup. The measurements use the actual bridge method and native execFile with fixture session state; persistent tests also exercise the full bridge constructor. Raw RSS is recorded separately and is not treated as retained heap.

Linked Issue

N/A — maintainer performance audit.

Visual Proof

N/A — process ownership cleanup has no visual or interaction change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

All selected PR CI checks pass, including all five Node 24 test shards, relay tests, static analysis, and macOS/Windows packaging.

macOS, all tests launched with ORCA_BACKGROUND_LAUNCH=1:

  • Persistent regressions: before 3 failed / 2 passed, after 5 passed, including the unchanged real 5 MiB inherited-pipe fallback.
  • Full browser suite: 209 files / 1,905 tests passed, one file / two tests skipped.
  • pnpm tc:node: passed.
  • Integrated with the other published performance fixes: 2,222 browser/ACP tests pass across 247 files (two skipped tests), full pnpm tc passes, and the 85-file changed-code quality gate reports zero new findings.
  • Focused oxlint and oxfmt: passed.
  • Changed-code quality against 4077fb4a8de8: passed, two changed files, zero new findings.
  • Temporary WeakRef controls: candidate 6 passed, covering ordinary completion, error, cancellation, spawn failure, fired fallback ownership, and full inherited output.
  • Windows/Linux/SSH not physically run. The native helper's platform policy, inherited-pipe fallback, command routing, and wire behavior remain unchanged.

Review

The completion callback retires the drain timer before clearing the active process and settling the result. Spawn errors have no exit timer; inherited-pipe callbacks still wait for the same fallback to release the pipes. The lifetime test clears mock call records before GC so those records cannot keep the child alive.

Reproduce the focused regressions with:

ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/browser/agent-browser-bridge-raw-process-retention.test.ts src/main/browser/agent-browser-bridge-raw-process.test.ts

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

The completion callback already owns settlement and helper cleanup. Clearing an undefined or already-fired timer is harmless, so spawn failure and inherited-pipe fallback preserve their existing behavior. No new timeout, polling, cache, or cross-host protocol change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • Local focused lint, Node typecheck, full browser tests, formatting, and changed-code quality passed; broader build and full lint are delegated to CI.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f6587f20-e787-492f-b12f-91cd4f4db139
📥 Commits

Reviewing files that changed from the base of the PR and between 7f8b4a8 and 18480b8.

📒 Files selected for processing (2)
  • src/main/browser/agent-browser-bridge-raw-process-retention.test.ts
  • src/main/browser/agent-browser-bridge-raw-process.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

runAgentBrowserRaw now stores the exit-drain timer and clears it when the execFile callback runs. New tests cover child-process garbage collection and bridge reuse, error and cancellation outcomes, and spawn failure.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 18480

The timer cleanup and its regressions present no identified merge-blocking risk; merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: releasing the completed browser helper’s drain timer.
Description check ✅ Passed The description covers the required sections, explains the change and rationale, and provides detailed testing results. It gives N/A for visual proof and the linked issue, consistent with the stated n…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker
nwparker merged commit efb071b into main Oct 8, 2026
30 checks passed
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