Repository navigation
fix(runtime): let waiting agents read mail and start actions - #26549
brennanb2025 wants to merge 14 commits into
Conversation
…or agent start Prompted terminal sends, prompted agent launches, worker starts and task injection into a chat were counted in the same 16-slot budget as passive terminal/orchestration waits, so a fleet of waiting agents made a fresh prompt fail with "long-poll capacity reached". Those actions keep their keepalive and cancellation but no longer consume or check the observer budget; observer limits are unchanged. Co-Authored-By: OpenAI Codex gpt-6.1-sol <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Slow user actions (terminal send with an agent prompt, prompted agent launch, worker start, chat inject) no longer take one of the 16 waiting slots, so 16 waits plus 16 such actions could fill all 32 local socket connections. Past that limit Node drops every new connection and the CLI tells the user to restart Orca, even for quick calls like a status check. Raise the local socket / named pipe connection limit to 128, matching the WebSocket transport's client budget, so waits stay capped well below it and actions plus short calls still get through. Comments now state that invariant, and a test holds 16 waits and 16 slow actions open and checks a short call still answers (it fails at the old limit of 32).
…room test The waiting-request counter comment and the socket transport header no longer describe the old 32-connection behavior. The headroom test now allows up to 10 seconds for its 32 connections to open, so a busy machine doesn't make it fail. No behavior change.
|
When many agents wait for mail, a shared 16-request quota could refuse a request before it read pending mail or started work. This PR removes that shared quota for held waits, adds a 512-held-request backstop per physical connection (never per device), raises the paired-server connection limit from 128 to 512, and shares terminal screen and process readings among idle waiters in each sweep. Update: main merged in (head Review loop finished on Real QA, current main vs this head.
Not exercised: the 512 and 640 limits themselves, and saturating a paired connection. The automated tests cover those. A first prompt typed while Codex's startup warning panel was open got no reply; after the panel was dismissed, a new prompt under load was answered. This doesn't appear related to this PR. Test copies used throwaway homes, every process was stopped by its recorded PID, and ports were verified free afterward. 20 waits held on the branch (the CLI shows each one's keepalives): A real worker completing while the waits are held: A prompt answered while the waits are held: 32 idle waits pending on one agent terminal: The agent finishing and the final prompt answered, after which the idle waits settled: Main reproducing the refusal (saved output replayed in the terminal): |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
|
I tested the neighbouring PR #26751 on a Linux box tonight. Its env cap can't get past the local socket's 32-connection limit. With For context, I'm on Orca 1.4.218 on macOS with about 43 concurrent This PR looks like the piece that actually fixes it for us: worker-start and the other slow actions stop counting as waits, and the socket limit goes to 128. Happy to test a build that combines this with #26751's check sub-cap if that's useful. |
…ions-poll-admission # Conflicts: # src/main/runtime/rpc/unix-socket-transport.ts # src/main/runtime/runtime-rpc-long-poll-transport.test.ts
…pending mail or refuse actions The runtime admitted at most 16 long-polls (check --wait, ask, terminal wait, browser-host attach), counted by method name before the handler ran. With 16 held, every other wait was refused unread, so a coordinator's check --wait reported no mail while mail was pending, and the count also refused worker starts and asks. The count only stood in for the local socket's 32-connection budget; a held wait costs one socket, an unref'd keepalive timer and an in-memory waiter. Long-polls now only get keepalive frames and an abort signal. The cap, its ask and browser-host sub-caps and their counters are gone from both the local socket and paired WebSocket paths. The local socket gets a 512-connection budget in place of Node's silent maxConnections drop: a long-poll arriving past it gets a retryable runtime_busy, short calls are still served, and an accept failure no longer crashes the runtime. Tracked in STA-11193.
…d close over-budget sockets after their reply
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:
c01206f0-22eb-4719-870c-665d9783e9ea
📒 Files selected for processing: 15
config/scripts/vitest-sqlite-database-runtime-files.mjssrc/main/runtime/rpc/methods/orchestration/messaging/check-direct.tssrc/main/runtime/rpc/transport.tssrc/main/runtime/rpc/unix-socket-transport.tssrc/main/runtime/runtime-rpc-browser-host-admission.test.tssrc/main/runtime/runtime-rpc-dispatch-inject-long-poll.test.tssrc/main/runtime/runtime-rpc-held-request-admission.test.tssrc/main/runtime/runtime-rpc-long-poll-transport.test.tssrc/main/runtime/runtime-rpc-websocket-long-poll-caps.test.tssrc/main/runtime/runtime-rpc/runtime-rpc-lifecycle.tssrc/main/runtime/runtime-rpc/runtime-rpc-long-poll.tssrc/main/runtime/runtime-rpc/runtime-rpc-pairing-types.tssrc/main/runtime/runtime-rpc/runtime-rpc-request-admission.tssrc/main/runtime/runtime-rpc/runtime-rpc-state.tssrc/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
💤 Files with no reviewable changes: 3
- src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.ts
- config/scripts/vitest-sqlite-database-runtime-files.mjs
- src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
… its waiters With the long-poll cap gone, any number of terminal wait --for tui-idle calls can be held. Each sweep evaluated every waiter separately: a tail scan, blocked-prompt detection and possibly a screen read and process query per waiter. Waiters on one terminal read the same evidence at the same instant, so the sweep now evaluates each terminal once (per launch-readiness mode) and shares the verdict, screen read and process query. 200 waiters on 4 terminals: 169 ms -> 2.4 ms of main-thread time per sweep.
… connection limit With the shared cap gone, one connection could hold any number of long-polls: a paired WebSocket multiplexes requests, and a local socket can pipeline them. Each physical connection now holds at most 512; the next long-poll on that connection gets runtime_busy while the connection and other clients carry on. The count is never per device, because every CLI call from one machine shares its device token but opens its own connection. Each remote CLI call opens its own WebSocket, so the 128-connection WebSocket limit became the next point where held waits refuse another client's call; it rises to 512 (TCP 1024), matching the local socket budget.
…ions-poll-admission
…ions-poll-admission
…ions-poll-admission # Conflicts: # config/scripts/vitest-sqlite-database-runtime-files.mjs






ELI5
When many agents were waiting on Orca at once, Orca started refusing everyone else. On 2026-10-19 about 40 coordinator agents on one Mac were each waiting for orchestration mail. A coordinator's wait said "no mail" for an hour while two questions sat in its mailbox, so a worker waited 50 minutes for an answer, and
worker-startkept failing with "long-poll capacity reached; retry with backoff". At normal fleet sizes, waits no longer compete for a shared quota: a wait whose mail is already there gets it, and fresh actions can run. The separate connection backstop still applies under overload.What Changed
Before: Orca's runtime (the server the
orcaCLI, paired desktops and phones talk to) allowed at most 16 requests that stay open while they wait ("long-polls"):orchestration check --wait,orchestration ask,terminal wait, a paired desktop's browser-host attach, and slow actions likeworker-start,agent launchwith a prompt,terminal send --enterand injecting a task into a chat. Inside the 16 there were smaller shares for asks and browser hosts. The count was checked by request type before the request ran. So once 16 were open, every further one was refused unread: acheck --waitwhose mail was already pending never looked at it, anasknever sent its question, and a worker never started. The CLI does not retryruntime_busy, so each refusal was a failed command.After: long-polls no longer take a slot. They still get what they actually need (keepalive frames so the 30-second idle timer doesn't cut them off, and cancellation when the client goes away), on the local socket (macOS/Linux), the Windows named pipe and paired WebSocket connections. The 16 cap, the ask and browser-host shares, and their counters are deleted.
The local socket keeps a safety limit on connections, not on request types. Every held wait keeps one socket open, and Orca used to cap the socket at 32 connections (raised to 128 in this PR's first version).
runtime_busy("Orca has too many open connections right now; retry in a few seconds") instead of a silently dropped connection, which the CLI reported as "Restart Orca". Quick calls likeorca statusare still answered, and an over-limit connection closes right after its one reply.runtime_busy; the connection stays open, quick calls still go through, and no other connection is affected. The limit is per connection, never per device: every CLI call from one machine shares its device sign-in but opens its own connection, so a per-device limit would let one CLI's waits refuse another's action.terminal wait --for tui-idleused to re-check every waiter separately every 2 seconds (a scan of the terminal's recent output, plus possibly a screen read and a process lookup). Waiters on the same terminal now share one check per sweep. With 200 idle waiters on 4 terminals, a sweep went from 169 ms to 2.4 ms of main-thread time.Why
The 16 was a stand-in for the local socket's old 32-connection budget, not for anything a wait costs. A held
check --waitis an in-memory waiter woken when mail is routed (no polling, one per Run). Anaskuses the same waiter. Each held request costs one socket, one 10-second keepalive timer, and whatever its own handler keeps (a terminal wait's per-terminal waiter, for example). Because the count was applied by request type before the request ran, it hid state that was already there and let passive waits refuse actions. Earlier fixes kept carving it up: an ask share when asks starved waits, browser-host shares, then this PR's first version moving actions out. Each fixed the latest group to starve and left the next one exposed. That is how tonight's waits starved other waits.The common pattern for local RPC servers is to put no admission count on long-lived requests: read state first and manage the wait's lifetime separately from transport resources. We considered:
Linked Issue
Tracked in STA-11193 (Linear).
Visual Proof
Native Windows comparison on pinned main
77195a1266d2and branch9bace0f58ed4, using isolated Electron copies and a dedicated Codex driver. Main held 16 of 20 waits and refused pending-mail reads and actions. The branch held all 20 and returned the exact mail in 440 ms; real prompt execution and worker completion were verified. Screenshots below show the actual app and CLI output. The mail screenshot reprints saved real CLI stdout in an owned terminal. The fresh final integrated-head comparison is recorded below.Testing
Automated:
runtime-rpc-held-request-admission.test.ts, the whole flow on a real local socket and on a paired connection: with 40 waits held open, a mail wait (check --wait),ask,worker-start,agent launchwith a prompt,terminal send --enterandstatus.getare all answered. A third case with a 2-connection budget: a third wait gets the retryableruntime_busyand never reaches its handler, andstatus.getis still answered.runtime-rpc-websocket-long-poll-caps.test.ts, the cap cases in the transport and browser-host tests).Live QA on the final head
8dea4989343(macOS test copy, real Codex), compared with fresh main: main held 16 of 20 mail waits, refused the rest, and left pending mail unread and a worker start and prompt refused. The branch held all 20; with them held, pending mail returned in 105 ms, a real worker started and finished, a prompt was answered and status answered. Cancelling 4 waits left the other 16 delivering. 32 idle waits on one agent terminal settled correctly (8 cancelled, 24 settled, then a fresh wait). Normal mail send/check/ack/reply worked. The 512/640 limits and paired-connection saturation are covered by automated tests, not live. Screenshots are in the review status comment.Review
The plan and code were checked by two independent reviewers. Both chose the uncapped design. Their fixes are folded in: the accept-error handler, the clear error past the connection limit, a hard connection limit with over-limit connections closed after their reply, and the labelling below. Review loop and QA status will be in the review comment.
Agent skill upstream boundary
Notes
runtime_busystays a valid reply. Clients keep handling it (the browser-host attach retry and remote-runtime error handling are unchanged) because older paired servers still produce it. An older CLI against a newer runtime simply stops seeing it for waits. A newer CLI against an older runtime sees it exactly as before, until that runtime updates. SSH and WSL hosts run the same server and get the fix when they update.legacy-relay-cli-call-limits.ts), unchanged by this PR. It bounds a flood from an older remote host onto this desktop, a multi-host case the common pattern doesn't have, and it goes away with that whole compatibility path, which the code marks for retirement on 2027-01-15.orca orchestration check --ack <id>(no--wait) acknowledges the batch and then leases and returns the next one. That is the documented contract (--ack"acknowledge the prior whole batch before checking/waiting"). A leased batch the caller ignores is replayed on its next check, so nothing is lost. To only acknowledge, use--ack <id> --peek. Noted on STA-11193.orca-wait-mailworkaround: once this release is installed, coordinators can go back to one blockingcheck --waitper Run (handlingwaiter_exists). Until then, polling withcheck --peekstays correct.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author: @BrennanKB5
Fresh final integrated-head QA
On the admitted Windows high spec machine, isolated Electron main 2b60778 again held 16 of 20 waits and refused pending mail and actions. Integrated head 18f1bd7 held all 20, delivered the exact pending message in 220 ms, accepted a real prompt that produced its reply, and automatically started a real worker that reported success and was released. Status, normal messaging, acknowledgment, reply and cancellation passed. All recorded test processes stopped and assigned ports were clear.
Both fresh copies showed baseline hook failures and a shell alias startup error; the actual prompt reply and durable worker completion were verified despite those errors. The earlier pre-integration QA startup recoveries were not needed in this run. Exact integrated-head CI passed.
An unattributed configuration change on the shared QA machine is recorded in the private audit; the lane owner accepted the functional evidence after reviewing the isolation receipts.
Fresh main held-wait app/CLI output:
Main prompt refusal, captured before the driver input-policy incident:
Integrated branch saved actual CLI stdout (label and mail portion are above the viewport):
Integrated branch actual agent reply and worker completion: