Repository navigation
fix(runtime-rpc): answer over-limit local connections with runtime_busy instead of dropping them - #22351
fix(runtime-rpc): answer over-limit local connections with runtime_busy instead of dropping them#22351Jinwoo-H wants to merge 1 commit into
Conversation
…sy instead of dropping them
The local socket closed connections past its 32-slot limit unread, so the CLI
reported a dead runtime ("Restart Orca") for requests that never ran. Over-limit
sockets now get a runtime_busy reply marked dispatched:false, the CLI resends
those with short backoff, and orca status reports a busy runtime as reachable.
The limit rises to 128, matching the WS cap.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe runtime connection limit now defaults to 128 and can be configured. When the limit is reached, the Unix-socket transport can return a structured Priority: ➖ Normal Merge Risk: 🔵 Low · up to A delayed retry can send a request after its timeout. This narrow timing issue should be fixed by rechecking the deadline. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
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: ffa8008e-d03e-43b7-af14-8205feb17c35
📒 Files selected for processing (9)
src/cli/runtime/connection-limit-retry.test.tssrc/cli/runtime/status.tssrc/cli/runtime/transport.tssrc/main/runtime/rpc/unix-socket-busy-reply.tssrc/main/runtime/rpc/unix-socket-connection-limit.test.tssrc/main/runtime/rpc/unix-socket-transport.tssrc/main/runtime/runtime-rpc/runtime-rpc-long-poll.tssrc/shared/runtime-rpc-connection-limit.tssrc/shared/runtime-session-contracts.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| return response | ||
| } | ||
| const delayMs = Math.round(baseDelayMs * (0.5 + Math.random())) | ||
| attemptTimeoutMs = deadline - Date.now() - delayMs |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,185p' src/cli/runtime/transport.ts
sed -n '90,138p' src/cli/runtime/connection-limit-retry.test.tsRepository: stablyai/orca
Length of output: 8627
🏁 Script executed:
sed -n '135,285p' src/cli/runtime/transport.ts
rg -n -C 3 "timeoutMs|sendRequest\\(" src/cli/runtime -g '*.ts' | head -180
sed -n '1,115p' src/cli/runtime/connection-limit-retry.test.tsRepository: stablyai/orca
Length of output: 20317
Recheck the deadline after each backoff.
If the backoff timer fires after the deadline, attemptTimeoutMs still holds its pre-wait value. sendRequestOnce can then connect and send a state-changing request after the caller’s timeout. Recalculate the remaining budget after the wait and return the busy response if no time remains.
🐛 Suggested fix
await new Promise<void>((resolve) => setTimeout(resolve, delayMs))
+ attemptTimeoutMs = deadline - Date.now()
+ if (attemptTimeoutMs <= 0) {
+ return response
+ }There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Over-limit connections now get a typed reply.
UnixSocketTransportcounts admitted connections itself and routes excess sockets toreplyConnectionLimitBusy, which reads only the requestid(one line, or the leading"id"within 64 KB) and answers with the same failure envelope every CLI decoder accepts — never dispatching. This removes the silent close that made the CLI blame a healthy runtime. - The limit moves 32 → 128 with Node's
server.maxConnectionskept at2×as a hard ceiling, bounding rejected-socket memory and lifetime (128 × 64 KB, ≤ 4 s). - CLI resend is provably safe.
sendRequestresends only aruntime_busywhosedata.dispatched === false, with three jittered backoffs inside the caller's timeout; long-poll admissionruntime_busyhas no such flag and is sent once. orca statusreports a busy runtime as alive (state: 'busy',reachable: true,graph.state: 'unknown'), andCliRuntimeState/graph unions gain the new members.- Tests cover both sides of the wire with exact-frame assertions (burst past limit → 32 ok + 3 busy, none dispatched; over-long line named by its leading id; ceiling drop; CLI resend/bound/timeout/long-poll cases).
I traced the load-bearing safety claim end to end and independently confirmed it: the connection-limit reject is the only producer of runtime_busy with data.dispatched === false across src/main, src/shared, and src/cli; long-poll admission and the WebSocket path build their runtime_busy via errorResponse with no data, and mapRuntimeError flattens any handler-thrown runtime_busy to runtime_error. So an automatic resend cannot double-apply a mutation. I also checked the new activeSockets/busySockets accounting, the reply deadline timer, and stop() teardown; no leak, miscount, or unreplied reachable branch beyond the two documented cases (the 2× Node ceiling, and a frame whose id cannot be extracted). The new tests, the existing transport/status suites, and the wrapping recovery path all behave as described.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Orca's local command socket accepted at most 32 connections at once. When agents fired more
orcacommands than that in parallel, Orca hung up on the extras without saying anything. Theorcacommand read that as "Orca is dead" and printed "Restart Orca… Orca is not running", even though Orca was running and those commands had never run. Now Orca answers the extras with "busy, try again". The command retries on its own, and if Orca is still busy it says so instead of telling you to restart.What Changed
Before (35 parallel commands, each held for 2 s by the runtime):
runtime_unavailable:The Orca runtime closed the connection before responding. Restart Orca and try again./Orca is not running. Run 'orca open' first.The runtime never saw those 3 requests.orca statuswhile the socket is full:runtime.state: "starting",reachable: false,connectionState: "disconnected".After:
runtime_busy:orca statuswhile the socket is full:runtime.state: "busy",reachable: true,connectionState: "connected",graph.state: "unknown", exit 0.Mechanism.
unix-socket-transport.ts, newunix-socket-busy-reply.ts). The transport now counts admitted connections itself instead of relying on Node'sserver.maxConnections, which closes excess sockets without sending anything. A connection over the limit goes to a reject path. That path reads only far enough to learn the request id: a full line, or the first 64 KB, where the CLI always writesidfirst. It answers with an ordinary failure frame,{id, ok:false, error:{code:'runtime_busy', message, data:{retryable:true, reason:'connection_limit', dispatched:false, nextSteps}}}, then half-closes the socket and keeps discarding input so a client still sending doesn't get EPIPE before it reads the reply. The reject path never calls the message handler. If no id arrives within 2 s the socket is closed, and a replied socket is closed 2 s after the reply at the latest.server.maxConnectionsstays as a hard ceiling at twice the limit. Past that ceiling Node still drops sockets unread, so a flood can't make the runtime hold unbounded busy sockets. The worst case is 128 sockets × 64 KB, held for at most 4 s.MAX_WS_CONNECTIONS = 128). File descriptors aren't the constraint. Measured on macOS with Electron 43.7.0 launched from a shell with softulimit -n 256(the launchd default), the main process runs with soft RLIMIT_NOFILE 1048575 because Chromium raises it at startup, and it opened 3000 socket pairs without EMFILE. Windows named pipes are created with unlimited instances, so the 256 hard ceiling is the binding bound there.LONG_POLL_CAP = 16, only the comment changed). The cap exists so long-polls can't starve short calls. At 16 of 128 that holds more strongly than before. Raising it would also change the ask, browser-host and per-device sub-caps, which are sized for paired-desktop overlap, and long-poll overflow already gets a cleanruntime_busy.transport.ts).sendRequestresends only when the failure isruntime_busyanddata.dispatched === false. It makes up to 3 resends with jittered 250/600/1200 ms backoff, all inside the caller's own timeout. A long-poll admissionruntime_busyhas nodispatchedflag, so it is not retried: that request did reach the handler.status.tstreats aruntime_busyreply as proof the runtime is alive.CliRuntimeStategains'busy', andgraph.stategains'unknown', because a busy reply says nothing about the graph.Why
The runtime must not answer overload with silence. The client can't tell a silent close from a crash, so it gave crash advice for a runtime that was healthy. A typed reply tells the client the truth, and the
dispatched:falseflag makes retrying provably safe even for mutations. Alternatives considered:runtime_unavailableon the client. An EPIPE or clean close can also mean the runtime crashed mid-request, and resending a mutation then could apply it twice.invalid_runtime_responseon old and new CLIs alike.Mixed versions. Old CLI + new runtime: the frame is a normal failure envelope with an optional
_metaomitted, whichRuntimeRpcEnvelopeSchema(unchanged since before this PR) accepts. Running origin/main'stransport.ts+cli-error.tsagainst the new server givesruntime_busyand prints the message plusNext step: Retry the command in a few seconds., with no restart text and no retry. New CLI + old runtime: overflow is still a silent drop, as before. Nothing new is required from either side.Linked Issue
Fixes #
Visual Proof
N/A. This changes CLI and socket behavior, not UI. The test output below shows the before and after.
Testing
Two test files, one per side of the wire:
Server,
src/main/runtime/rpc/unix-socket-connection-limit.test.ts. This drives the realUnixSocketTransportwith a small in-test client that writes one request line and reads frames.RuntimeRpcEnvelopeSchema. That is 32 real replies and 3runtime_busyframes withdispatched:false. The handler ran exactly 32 times, and none of the busy ids reached it. On origin/main's transport this fails:request req-32got nothing back, which is the silent close.CLI,
src/cli/runtime/connection-limit-retry.test.ts. A fake socket server emits the busy frame.runtime_busywithoutdispatched:false(long-poll admission) is sent once.orca statusagainst a runtime that stays busy reportsbusy, reachable, connected.RuntimeRpcEnvelopeSchema, andformatCliErrorprints the busy message and next step with no restart text.transport.tsandstatus.ts, the resend, bounded-resend and status tests fail. The schema and formatting tests pass on origin/main as well, so an old CLI already handles the frame.A scratch run of origin/main's
transport.tsagainst the new server also returnedruntime_busyand printed the retry step, with no restart text. That run was not committed.macOS only. The socket tests are skipped on Windows, like the existing transport tests.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
JSON.parseof at most one line, or a regex over at most 64 KB.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)