Repository navigation
[mem] Backpressure worker subprocess output without dropping bytes - #30698
Conversation
3b15771 to
57dcebb
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
57dcebb to
2413433
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2b642abc-8fcf-473b-8c94-23b600bf08e3
📒 Files selected for processing: 8
config/scripts/vitest-node-runtime-files.mjssrc/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.tssrc/main/rate-limits/codex-rpc-worker-backpressure.test.tssrc/main/worker-thread-child-process/worker-thread-child-output-flow.test.tssrc/main/worker-thread-child-process/worker-thread-child-process-worker.test-fixtures.tssrc/main/worker-thread-child-process/worker-thread-child-process.test.tssrc/main/wsl/wsl-orcad-connection.tssrc/main/wsl/wsl-orcad-pairing-identity.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
ELI5
A disk-space scan or Codex usage probe can produce output while Orca's main process is busy. Pause its output when too much is waiting, so the worker cannot queue the entire response in memory. Output-heavy commands may take longer while their reader catches up.
What Changed
The main process acknowledges each stdout or stderr chunk after its synchronous listeners return. The worker counts outstanding bytes per child, pauses both pipes at 256 KiB, and resumes as acknowledgements arrive. Each chunk owns its transferred backing buffer, avoiding a second payload copy.
Real-worker tests exercise the actual Codex usage reader with noisy stderr, initialization and RPC deadlines, aborts, and graceful stdin-EOF shutdown after output listeners detach. Sub-window replies are checked to continue without pausing.
Why
Acknowledgement-based flow control preserves complete output and its order. Dropping bytes can corrupt RPC messages; terminating commands changes their results; disk spooling would add storage and cleanup machinery. The existing caller limits run downstream and cannot prevent transport queues growing while the main process is stalled.
Linked Issue
Follow-up to the OOM audit in #30650. This PR protects worker subprocess transport; it does not establish the cause of a production OOM.
Visual Proof
N/A — internal subprocess transport and tests; no visual or interaction change.
Testing
pnpm tc:node, changed-code quality, full formatting check, and commit hooks passed for the updated branch.bdfda9ca10a7514bba948590c7bc8b5a7617586b, including all five test shards, relay integration, static analysis/typechecking, Linux and Windows packaging, and the required aggregate gate: https://github.com/stablyai/orca/actions/runs/39723529707.Review
The 256 KiB value is a pause threshold, not a strict memory cap: chunks and closing pipes can overshoot it. The window is per child and bounds transport payload only; callers can still retain output, and producers that ignore backpressure can buffer in their own process. Draft #31408 evaluates a separate 16 MiB pending-line budget. Its producer investigation reproduced complete HTTP response bodies being copied into oversized usage errors. That receiver guard is defensive hardening, not a producer or production-OOM root-cause fix; its response-size policy remains under review.
Existing deadlines remain unchanged. Waiting for output can make a child or caller miss a deadline it previously met; a synthetic child with its own deadline reproduced that tradeoff. A noisy stderr stream can pause stdout because both pipes share the window. The real caller tests cover recovery, deadline expiry, and shutdown without extending deadlines or silently discarding output.
The acknowledgement protocol is internal to a worker and its owning process. Paired SSH, relay, and mobile protocols are unchanged. No changes to interactive terminal output are included.
Agent skill upstream boundary
Notes
This change uses Node pipe pause/resume and worker buffer transfer. It adds no output-size cap or new timeout to the bridge.
Checklist