Skip to content

fix(runtime): let waiting agents read mail and start actions - #26549

Closed
brennanb2025 wants to merge 14 commits into
mainfrom
brennanb2025/user-actions-poll-admission
Closed

brennanb2025 wants to merge 14 commits into
mainfrom
brennanb2025/user-actions-poll-admission

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​379 $\color{#cf222e}{\Huge{\mathbf{−}}}$​798 $\color{#cf222e}{\Huge{\mathbf{−}}}$​419
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201 $\color{#cf222e}{\Huge{\mathbf{−}}}$​186 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15

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-start kept 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 orca CLI, 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 like worker-start, agent launch with a prompt, terminal send --enter and 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: a check --wait whose mail was already pending never looked at it, an ask never sent its question, and a worker never started. The CLI does not retry runtime_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).

  • Up to 512 open connections everything is served.
  • Past 512, a new long-poll gets a clear, retryable 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 like orca status are still answered, and an over-limit connection closes right after its one reply.
  • 640 connections is the hard limit on accepted local sockets. It bounds this listener, rather than guaranteeing file-descriptor headroom for the whole process.
  • One connection can hold at most 512 waiting requests at once (a paired desktop or phone sends many requests over one connection, and a local client can send several over one socket). The next one on that connection gets the same retryable 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.
  • The paired-server connection limit rises from 128 to 512 (raw network connections from 256 to 1024). Each remote CLI call opens its own connection, so with waits no longer capped, 128 held remote waits would otherwise make the next client's call fail at connect.
  • terminal wait --for tui-idle used 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.
  • A failed accept (the process out of file handles) no longer crashes the runtime; it drops that one connection.

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 --wait is an in-memory waiter woken when mail is routed (no polling, one per Run). An ask uses 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:

  • separate pools per request type (mail waits get their own), which only moves the wall again;
  • a bigger number, or a number in Settings, which leaves the wall in place and needs tuning. Brennan suggested a setting; with no wait limit left there is nothing meaningful to tune, so it was ruled out.

Linked Issue

Tracked in STA-11193 (Linear).

Visual Proof

Native Windows comparison on pinned main 77195a1266d2 and branch 9bace0f58ed4, 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

  • Tested in isolated Electron copies on the admitted Windows QA machine
  • Automated tests added/updated, or explained why not below

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 launch with a prompt, terminal send --enter and status.get are all answered. A third case with a 2-connection budget: a third wait gets the retryable runtime_busy and never reaches its handler, and status.get is still answered.
  • The keepalive and cancel-on-disconnect transport tests are kept; the cap-only tests are deleted (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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • No wire change. runtime_busy stays 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.
  • Performance: removing the shared cap also removed an incidental limit on how much waiting work Orca holds. What bounds it now: at most 512 waiting requests per connection, the local socket's 512/640 connection limits, the paired server's 512 connections, one mail wait per Run, per-terminal waiters with one shared idle check per terminal per sweep, the terminal wait limit for multiplexed panes, 1 MB frames and reply-size limits. On Linux, Orca's runtime raises its open-file limit at startup (measured on a Linux host: 1,048,576 for the running server versus 1024 for a plain shell), so the 640-socket limit stays far below it.
  • Intended / temporary differences from the common pattern:
    • Intended: the per-connection limit of 512 waiting requests. The common pattern doesn't count requests per connection; Orca keeps this as a backstop so one runaway client can't grow the host's waiting work without bound, set far above what any normal client holds.
    • Intended: the local socket's connection limit (512 for long-polls, 640 hard). The common pattern has no connection limit at all. Orca already had one (32), and dropping all file-handle protection is a separate safety decision from fixing wait starvation, so this PR keeps a limit, raises it far above any real fleet, and makes it answer clearly.
    • Intended: the legacy relay path for older SSH terminals keeps its own limit of 16 calls per host (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.
  • Out of scope, separate mechanism: a bare 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.
  • The orca-wait-mail workaround: once this release is installed, coordinators can go back to one blocking check --wait per Run (handling waiter_exists). Until then, polling with check --peek stays correct.
  • Nothing persisted. No assumptions about Git, workspace kind or platform.

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)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author: @BrennanKB5

main-prompt-refused

branch-mail-cli

branch-held-cli

branch-agent

branch-worker-recovered

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:

Final main held waits

Main prompt refusal, captured before the driver input-policy incident:

Final main prompt refusal

Integrated branch saved actual CLI stdout (label and mail portion are above the viewport):

Final branch accepted actions

Integrated branch actual agent reply and worker completion:

Final branch real prompt

Final branch real worker

brennanb2025 and others added 3 commits October 8, 2026 03:34
…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.
@brennanb2025

brennanb2025 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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 2e75d091b73). Main's changes since the reviewed head touch neither request admission, mail waits nor terminal waits (they add live-terminal placement on client attach and mobile agent session methods), so the review and QA below carry over. The only conflict was a test-list script main deleted; this PR's diff against main is unchanged. The six affected test files pass (72 tests) and the full PR workflow passed on this head.

Review loop finished on 8dea4989343ad69fb71b27b48ab0fc262f6bf0d8. Seven review rounds in total. Round 7 covered the new per-connection limit and the shared idle readings, and found no new problems. The design of the per-connection limit was settled by an independent design panel. The full PR workflow passed on this head.

Real QA, current main vs this head.

  • Fresh main (bfdf16b, Windows) reproduced the bug. With 20 mail waits open, 16 were held and 4 were refused. Mail that was already waiting stayed unread, and a worker start and an agent prompt were refused.
  • This head (8dea498, macOS test copy, real Codex) passed every required flow:
    • All 20 waits held, none refused.
    • With all 20 held: pending mail came back in 105 ms; a real worker started in about 2 s, ran its task, and reported done (received, released and acknowledged); a prompt to the real agent got its reply; orca status answered.
    • Cancelling 4 waits left the other 16 alive, and each still returned its own message.
    • 32 idle waits on one agent terminal: 8 were cancelled and the other 24 settled when the agent finished; a fresh wait after a new prompt and reply also settled.
    • Normal mail worked: send, check, acknowledge, reply, check, acknowledge.

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

branch-held-cli.png

A real worker completing while the waits are held:

branch-worker-completed.png

A prompt answered while the waits are held:

branch-clean-prompt-under-load.png

32 idle waits pending on one agent terminal:

branch-idle-32-pending.png

The agent finishing and the final prompt answered, after which the idle waits settled:

branch-idle-final.png

Main reproducing the refusal (saved output replayed in the terminal):

main-refusal-replay.png

@brennanb2025
brennanb2025 marked this pull request as ready for review October 8, 2026 12:50
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 4ecc3712-6c73-4957-a15b-a8d1b9b14236
📥 Commits

Reviewing files that changed from the base of the PR and between 8dea498 and 2e75d09.

📒 Files selected for processing: 1
  • src/main/runtime/runtime-rpc/runtime-rpc-lifecycle.ts

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

📝 Walkthrough

Runtime RPC admission now uses a configurable connection budget and per-connection long-poll limits. Unix socket transport rejects long-poll admission when a connection is over budget or at its per-connection limit. WebSocket dispatch also tracks long-polls per connection. Tests cover admission, cancellation, and connection capacity. Terminal idle polling now reuses cached verdicts, screen reads, and foreground-process reads during each sweep.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 2e75d

Over-budget Unix connections can still lose replies for concurrent requests, creating a material runtime reliability risk that should be resolved before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary runtime fix: allowing waiting agents to read mail and start actions.
Description check Passed The description is detailed and covers the required change summary, rationale, testing, visual proof, compatibility notes, review status, and checklist. The linked issue is identified as STA-11193 but…
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 is detailed and covers the required change summary, rationale, testing, visual proof, compatibility notes, review status, and checklist. The linked issue is identified as STA-11193 but is not provided as an actual issue link or Fixes reference, and the standard validation commands remain unchecked.

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

@webdevtodayjason

Copy link
Copy Markdown
Contributor

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 ORCA_RPC_LONG_POLL_CAP=64 and 40 separate check sockets, 32 waits stayed open and new worker-start, mutation and plain check connections were closed. So on a host like mine, raising the cap alone doesn't help.

For context, I'm on Orca 1.4.218 on macOS with about 43 concurrent check --wait calls across 30+ agent sessions on one host. Worker-start and check re-arms get refused with runtime_busy.

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.
@brennanb2025
brennanb2025 marked this pull request as draft October 19, 2026 08:43
@brennanb2025 brennanb2025 changed the title fix(runtime): don't let passive waits refuse a user's terminal input or agent start fix(runtime): waiting agents never hide pending mail or refuse actions Oct 19, 2026
@brennanb2025
brennanb2025 marked this pull request as ready for review October 19, 2026 08:51
@brennanb2025 brennanb2025 changed the title fix(runtime): waiting agents never hide pending mail or refuse actions fix(runtime): let waiting agents read mail and start actions Oct 19, 2026

@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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c01206f0-22eb-4719-870c-665d9783e9ea
📥 Commits

Reviewing files that changed from the base of the PR and between 211d04e and 9bace0f.

📒 Files selected for processing: 15
  • config/scripts/vitest-sqlite-database-runtime-files.mjs
  • src/main/runtime/rpc/methods/orchestration/messaging/check-direct.ts
  • src/main/runtime/rpc/transport.ts
  • src/main/runtime/rpc/unix-socket-transport.ts
  • src/main/runtime/runtime-rpc-browser-host-admission.test.ts
  • src/main/runtime/runtime-rpc-dispatch-inject-long-poll.test.ts
  • src/main/runtime/runtime-rpc-held-request-admission.test.ts
  • src/main/runtime/runtime-rpc-long-poll-transport.test.ts
  • src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-lifecycle.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-long-poll.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-pairing-types.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-state.ts
  • src/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.
@brennanb2025
brennanb2025 marked this pull request as draft October 20, 2026 01:57
@brennanb2025
brennanb2025 marked this pull request as ready for review October 20, 2026 01:57
…ions-poll-admission

# Conflicts:
#	config/scripts/vitest-sqlite-database-runtime-files.mjs
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing in favor of #30878 (@Jinwoo-H), a slimmer version of the same change.

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.

2 participants