Skip to content

fix(runtime): keep a CLI socket open while its request is still running - #29262

Merged
nwparker merged 1 commit into
mainfrom
nwparker/rpc-idle-timer-inflight
Oct 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/rpc-idle-timer-inflight

Conversation

@nwparker

@nwparker nwparker commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​70 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

ELI5

When an orca command took more than 30 seconds to answer (for example orca worktree create on a big repo), Orca hung up on the command halfway through. The command then said "the runtime closed the connection, restart Orca", even though Orca kept going and finished the job. Agents that saw the failure retried, which left orphaned worktrees or two agents working the same task. Now Orca stays on the line while it is still working on the request.

What Changed

Before: UnixSocketTransport (Unix sockets on macOS/Linux, named pipes on Windows) armed socket.setTimeout(30_000, destroy) once per connection. Node's idle timer counts byte silence, and a slow request writes nothing while it works. Only long-poll methods send keepalive frames, so worktree.create, worktree.rm, browser.snapshot and other merely-slow requests were reaped at 30 s. The handler kept running and wrote its reply to a closed socket.

After: while any request on a connection is still being handled, the idle timer is suspended (socket.setTimeout(0)). When the last one replies (or the socket closes), the 30 s timer is armed again. A connection with nothing in flight is still reaped after exactly 30 s, as before.

Why

  • Why not keepalives for every request: keepalive frames also refresh the CLI's own 60 s request timer, so a hung handler would never time out on the client. Suspending only the server reap keeps the CLI's ceiling meaningful.
  • Why not add worktree.create to the long-poll list: that list was already being patched one method at a time, and long-poll requests use admission slots. This fixes every slow request in one place.
  • Is anything lost by pausing the reap? No. This is a local socket or pipe: if the CLI process dies, the kernel closes the connection and the existing close handler aborts the in-flight work. The idle reap was only meant for clients that connect and go quiet.

This takes over #25889 by @ggbdpq (their commit, rebased on current main). #22347 is the same approach and is superseded by this PR.

Follow-ups not in this PR (from the issue): a distinct CLI error for "connection lost after the request was sent", and idempotent retries.

Linked Issue

Fixes #25830

Visual Proof

N/A. No UI change; this only changes when the CLI socket is closed.

Testing

  • Automated tests added/updated, or explained why not below

pnpm test src/main/runtime/rpc/unix-socket-transport.test.ts:

  • New: a non-long-poll request that takes 45 s keeps its socket past the 30 s timer and gets its reply, then the connection is reaped 30 s after going quiet. Fails on main (socket destroyed at 30 s).
  • New: a connection with nothing in flight is still reaped after 30 s.

pnpm tc:node and pnpm run check:code-quality:changed pass.

Notes

Cross-platform: the same transport serves Unix sockets and Windows named pipes; setTimeout(0) behaves the same on both. No wire change, so mixed CLI and app versions are unaffected. SSH/remote runtimes use a different transport and are not touched.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visual proof with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2a7bf320-ebb9-4e91-9beb-84d6aea010fd
📥 Commits

Reviewing files that changed from the base of the PR and between 9c863a6 and f70c435.

📒 Files selected for processing: 2
  • src/main/runtime/rpc/unix-socket-transport.test.ts
  • src/main/runtime/rpc/unix-socket-transport.ts
  • 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.

@nwparker
nwparker force-pushed the nwparker/rpc-idle-timer-inflight branch from f1cd3c1 to 4657280 Compare October 16, 2026 03:43
…flight

The runtime socket transport reaped connections after 30s of raw byte
silence, and Node's idle timer counts bytes — so a slow dispatch like
worktree.create on a large repo, which is not a long-poll and sends no
keepalives, read as a dead peer: the server destroyed the socket mid-
request, the handler kept running (the worktree got created), and the
CLI reported runtime_unavailable and told the user to restart. Callers
then retried, leaving orphaned worktrees or two agents on one task
(#25830, the root behind #15663/#23911/#20108 symptoms).

The reap timer now suspends while dispatches are pending and rearms
when the last one cleans up. Quiet connections with nothing in flight
still reap after exactly the same 30s, and a dead peer on a local
socket is delivered by the kernel as close/error, which the existing
cleanup already handles — so the reaping duty is unchanged where it
mattered.

Fixes #25830

Generated-by: GLM-5.3-Flash (ZCode)
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.

Local RPC idle timer (30 s) drops slow requests like worktree create; CLI reports runtime_unavailable after the request succeeded

2 participants