Skip to content

fix(runtime): long-polls take no admission slot, so waits return pending mail and never refuse actions - #30878

Open
Jinwoo-H wants to merge 1 commit into
mainfrom
sta-11193-orchestration-wait-busy
Open

Jinwoo-H wants to merge 1 commit into
mainfrom
sta-11193-orchestration-wait-busy

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​237 $\color{#cf222e}{\Huge{\mathbf{−}}}$​796 $\color{#cf222e}{\Huge{\mathbf{−}}}$​559
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​161 $\color{#cf222e}{\Huge{\mathbf{−}}}$​118

ELI5

When many agents were waiting on Orca at once, Orca refused everyone after the 16th. A coordinator's orchestration check --wait reported "no mail" for an hour while two questions sat in its mailbox, and worker-start kept failing with "long-poll capacity reached; retry with backoff". Now a wait whose mail is already there gets it, and starting a worker or asking a question works no matter how many other agents are waiting.

This is a slimmer version of #26549 by @brennanb2025, built from the same pieces (credited as co-author).

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: check --wait, ask, terminal wait, worker-start, agent launch with a prompt, prompt submission via terminal send, chat inject, and a paired desktop's browser-host attach. Smaller shares inside the 16 were reserved for asks and browser hosts. The count was checked by request type before the request ran, so the 17th was refused without being read. The CLI doesn't retry runtime_busy, so each refusal was a failed command.

After:

  • Waiting requests no longer count against any cap. They still get keepalive frames and are cancelled when the client disconnects, as before.
  • The 16 cap, the ask and browser-host shares, and their counters are deleted from both the local socket and the paired WebSocket path.
  • The local socket's connection limit goes from 32 to 512. An accept failure (out of file handles) is logged instead of crashing the runtime.

Why

The 16 existed only to keep the local socket's 32-connection limit from filling up (#1403, May). It measured nothing about what a wait costs: a held check --wait is an in-memory waiter woken when mail arrives. Because it was checked before the request ran, it hid mail that was already waiting and let idle waits block real work. Earlier fixes carved it into shares (#10529 for ask, #15448 for browser hosts), and each one moved the wall to the next group of requests.

Alternatives considered:

  • Separate pools per request type (fix: reserve long-poll capacity for worker startup #26751): moves the wall again.
  • A bigger cap: at 32+ held requests the socket's own limit silently drops connections first.
  • Read waiting mail before counting: fixes mail, but idle waits still refuse worker-start and ask.

Differences from #26549: it adds a 512 "budget" plus a 640 hard limit, a per-connection flag passed from the transport into request handling, and closes the socket after an over-budget reply. Every local client opens one socket per request (src/cli/runtime/transport.ts, the sidecar client), so a single connection limit does the same job. Electron raises its file-handle limit at startup (checked: launched with a limit of 256, it reports about 1M), so 512 sockets is safe. Past 512 the CLI shows the same message as today's past-32 behaviour, which a 40-agent fleet (about 80 sockets) won't reach.

Browser-host attach keeps its real limits: assertBrowserHostLeaseAdmission already caps leases per connection and per paired device, so the deleted admission shares were a second copy of that limit.

Linked Issue

Linear STA-11193. Also fixes #19342.

Visual Proof

N/A: no UI change. The before/after is the CLI/RPC result, covered by the tests below. #26549 has native Windows app screenshots of the same behaviour change.

Testing

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

New runtime-rpc-held-request-admission.test.ts, all three cases fail on main with runtime_busy and pass here:

  • With 40 waits held on a real local socket, check --wait, ask, worker-start, a prompted agent.launch, prompt submission via terminal send and status.get are all answered.
  • The same with 40 waits held on a paired WebSocket connection.
  • With 40 real orchestration.check --wait calls held, a 41st check --wait whose mail is already waiting returns that message immediately (real mail handler, no mock).

Keepalive and cancel-on-disconnect transport tests are kept; cap-only tests are deleted. Locally: pnpm tc:node, oxlint, oxfmt, check:code-quality:changed, and the affected runtime test files (43 tests) pass. No live app run; macOS only for the unit tests.

Review

Reviewed against #26549; the connection-budget wiring was removed as unnecessary.

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, and clients keep handling it because older servers still send it. An older CLI against a newer runtime stops seeing it for waits; a newer CLI against an older runtime sees it as before.
  • SSH, WSL and headless Linux servers run the same runtime server and get the fix when they update. Windows named pipes use the same transport code.
  • Tradeoff: there is no longer a cap on how much waiting work the runtime holds at once. Each held request costs one socket, one keepalive timer and its handler's own waiter, and per-kind limits (one mail waiter per mailbox, browser-host lease limits) stay.

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)

…ing mail and never refuse actions

The runtime refused the 17th open long-poll (check --wait, ask, worker-start,
terminal wait, prompted agent launch, agent-prompt send, browser-host attach)
with runtime_busy before its handler ran. A coordinator's check --wait then
reported no mail while mail sat in its mailbox, and idle waits refused
worker-start and ask.

Long-polls keep keepalive and the abort signal but no longer count against a
cap. The 16 cap existed only to protect the local socket's 32-connection
limit, so that limit is now 512; clients open one socket per request. An
accept failure no longer crashes the runtime. Browser-host attach keeps its
per-connection and per-device limits in the lease registry.

Co-authored-by: Brennan Benson <[email protected]>
Co-authored-by: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Runtime RPC no longer limits long-poll requests by category, device, or total capacity, and it no longer rejects requests with runtime_busy when those limits are reached. The request classifier now returns a boolean. Keepalive and abort-signal handling remain. The Unix socket connection limit increases from 32 to 512, and server errors are logged. Tests now cover request aborts and successful calls while many waits remain held.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 83c55

Long-running waits no longer use up a limited pool of request slots. Held mail checks and terminal waits therefore no longer cause other runtime actions to be refused as busy. The only remaining note is a small cleanup in a test list. Nothing found blocks merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue #19342 requests a separate sub-cap for continuously held check polls and a configurable longPollCap. It also requests active-count and capacity visibility and a diagnostic capacity error. Th… Implement the coding requirements from #19342: retain a separate configurable limit for continuously held check polls, expose active counts and capacity, and provide a diagnostic capacity error. Alternatively, update the linked issue to r…
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 4 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: long-poll requests no longer consume admission slots, so waits can return pending mail and actions are not refused.
Description check Passed The description follows the required template and clearly explains the user impact, mechanism, rationale, alternatives, linked issues, testing, compatibility, and risks. It explicitly documents that m…
Out of Scope Changes check Passed The changes remain connected to the linked starvation problem. The local socket limit increase and accept-error logging support the removal of request admission caps. The WebSocket changes, keepalive …
Full details: Description check

Explanation

The description follows the required template and clearly explains the user impact, mechanism, rationale, alternatives, linked issues, testing, compatibility, and risks. It explicitly documents that manual testing and a live app run were not performed.

Full details: Out of Scope Changes check

Explanation

The changes remain connected to the linked starvation problem. The local socket limit increase and accept-error logging support the removal of request admission caps. The WebSocket changes, keepalive and disconnect cancellation coverage, classifier refactor, and test updates cover the same runtime request behavior. No unrelated change is established.

Full details: Linked Issues check

Explanation

Issue #19342 requests a separate sub-cap for continuously held check polls and a configurable longPollCap. It also requests active-count and capacity visibility and a diagnostic capacity error. The PR removes longPollCap, the admission counters, and the runtime_busy admission path. RuntimeRpcRequestAdmission now dispatches long polls without admission. This removes the reported starvation, but it does not implement the issue's requested sub-cap, configuration, observability, or diagnostic error behavior.

Resolution

Implement the coding requirements from #19342: retain a separate configurable limit for continuously held check polls, expose active counts and capacity, and provide a diagnostic capacity error. Alternatively, update the linked issue to replace those requirements with the no-admission design before treating this PR as compliant.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · 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.

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

🧹 Nitpick comments: 1
config/scripts/vitest-sqlite-database-runtime-files.mjs: 1

179-182: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the second duplicate entry.

The include list contains runtime-orchestration-sender-names.test.ts twice. Keep the existing first entry and remove the later one.

Suggested fix
   'src/main/runtime/runtime-rpc-held-request-admission.test.ts',
   'src/main/runtime/runtime-rpc-long-poll-transport.test.ts',
-  'src/main/runtime/runtime-orchestration-sender-names.test.ts',
   'src/main/runtime/runtime-rpc-orchestration-db-migration.test.ts',

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4101efe-53aa-4402-9cbc-0c7fd66c7dc3
📥 Commits

Reviewing files that changed from the base of the PR and between a0d9457 and 83c5550.

📒 Files selected for processing: 13
  • config/scripts/vitest-sqlite-database-runtime-files.mjs
  • src/main/runtime/rpc/methods/orchestration/messaging/check-direct.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-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: 2
  • src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
  • src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.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.

@brennanb2025

Copy link
Copy Markdown
Contributor

Two things from #26549 that aren't in this version, both costs that only appear once the 16 cap is gone:

  1. Waits for an idle terminal are checked one by one. terminal-idle-polls.ts sweep() checks every terminal wait --for tui-idle separately every 2 s. Each check rebuilds up to about 256 KB of the terminal's output and checks it for a blocked prompt. fix(runtime): let waiting agents read mail and start actions #26549 does that once per terminal per round and shares the answer: with 200 waits on 4 terminals, a round dropped from 169 ms to 2.4 ms on the main thread.
  2. One paired device can hold any number of waits. With the WebSocket admission removed, a single paired desktop or phone connection can hold unlimited waits. fix(runtime): let waiting agents read mail and start actions #26549 limited each connection to 512 waiting requests and answered runtime_busy past that.

This branch has not been deployed

No deployments
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.

longPollCap: continuously-held check polls starve worker-start; cap is 16 and not configurable

2 participants