Skip to content

fix(runtime): suspend the socket idle timeout while a dispatch is in flight - #25889

Closed
ggbdpq wants to merge 1 commit into
stablyai:mainfrom
ggbdpq:fix/rpc-idle-timer-slow-requests
Closed

ggbdpq wants to merge 1 commit into
stablyai:mainfrom
ggbdpq:fix/rpc-idle-timer-slow-requests

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

ELI5

If a local CLI request took longer than 30 seconds — orca worktree create on a big repo, for example — Orca's runtime hung up mid-request. The worktree actually got created and the agent actually started, but the CLI was told "the runtime closed the connection, restart Orca". Callers (agents especially) then retried, which is how people ended up with orphaned worktrees or two agents working the same task. The hangup came from an idle timer that counts raw network silence — and a slow request is silent while it thinks. Now the timer pauses while a request is being processed and resumes when the socket is quiet again.

What Changed

  • In UnixSocketTransport (which serves both Unix sockets and Windows named pipes), the 30s reap timer is now suspended while any dispatch is in flight (socket.setTimeout(0)) and rearmed when the last dispatch cleans up. Verified against real net.Socket semantics: setTimeout(0) disables the timeout, and re-arming without a callback keeps the original one-time 'timeout' handler.
  • Quiet connections with nothing in flight still reap after exactly the same 30s — a new guard test locks that in.
  • Nothing else changes: protocol, framing, keepalive policy, the runtime_unavailable/runtime_timeout error surfaces, admission, and lifecycle are all untouched.

Why

The idle timer's job is reaping dead peers, and it judged liveness by byte silence. A long-poll request never trips it because long-polls opt into keepalive frames — but ordinary slow handlers (worktree.create, worktree.rm, browser.snapshot) send nothing while they work, so the timer read a healthy, thinking connection as a corpse. Suspending on in-flight dispatches fixes that at the mechanism itself. The alternative — auto-keepaliving every request — was rejected on evidence: an existing guard test (runtime-rpc-long-poll-transport.test.ts "does not emit keepalive frames for short RPCs") locks keepalive to long-polls as a deliberate invariant, and it would change the wire for every socket client. On a local socket a truly dead peer is delivered by the kernel as close/error, which the existing cleanup path already handles, so byte-silence reaping had no additional duty beyond idle reaping — and that duty is preserved.

Linked Issue

Fixes #25830 (the server-side misreap — the report's root cause). Related symptom reports #15663 and #23911 and the #20108 orphan worktrees should stop occurring from this path; the report also sketches follow-ups (a distinct CLI error code for post-success connection loss, idempotent retries via clientMutationId) that are deliberately not in this PR.

Visual Proof

N/A — no UI change; the before/after is the socket lifetime, pinned by tests: before, a 45s non-long-poll dispatch was destroyed at 30s (expected true to be false on the socket-alive assertion); after, the reply arrives at 45s and the quiet socket reaps 30s later.

Testing

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

Commands actually run locally (macOS): new cases red→green (1 failed / 6 passed before, 7 passed after — the FakeSocket was upgraded to model real idle-timer semantics: ms>0 counts, 0 suspends, re-arm keeps the original handler, traffic refreshes, destroy clears); transport/admission/framing suites including real-socket integration (3 files / 36 tests); pnpm tc exit 0; oxlint/oxfmt --check clean on both touched files. The named-pipe (Windows) branch shares all of this code but was not exercised on Windows; real 30s+ wall-clock behavior is simulated via the upgraded socket-model tests plus the real-socket integration suite, not a literal half-minute wait.

AI Disclosure

Investigation, coding and verification by GLM-5.3-Flash (ZCode agent); orchestrated, reviewed and committed by a main agent with the same model, human overseeing.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Transport-internal change: no protocol or wire change, no new RPC, works identically for Unix sockets and Windows named pipes (same class), SSH unaffected (different transport, no such timer). Behavior after the fix: requests may now legitimately take arbitrarily long without the server hanging up — the CLI's own 60s requestTimeoutMs remains the upper bound and reports runtime_timeout (honest, unlike the previous "restart Orca" advice). Connection-reaping duty for genuinely dead peers is preserved and guard-tested.

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)

…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
(stablyai#25830, the root behind stablyai#15663/stablyai#23911/stablyai#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 stablyai#25830

Generated-by: GLM-5.3-Flash (ZCode)
@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 9716659e-f2fd-4188-977a-7bd4d9f1acdf
📥 Commits

Reviewing files that changed from the base of the PR and between 5cf3585 and e6d9c3f.

📒 Files selected for processing (2)
  • src/main/runtime/rpc/unix-socket-transport.test.ts
  • src/main/runtime/rpc/unix-socket-transport.ts

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


📝 Walkthrough

Walkthrough

The Unix socket transport now suspends its 30-second idle timeout while a dispatch is in flight. It restores the timeout after the last dispatch completes. Tests update FakeSocket to model timeout behavior and cover both a delayed dispatch reply and reaping a connection after 30 seconds of inactivity.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e6d9c

Slow requests can retain their connection while quiet connections remain subject to the idle timeout. No identified issue prevents merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning #25830’s transport objective is implemented: UnixSocketTransport disables the idle timeout while dispatches are in flight, restores it after the last dispatch, and tests cover both a slow non-long-p… Implement the #25830 CLI error handling for connection loss after request transmission, with automated coverage for the distinct error.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: suspending the socket idle timeout while a dispatch is in flight.
Description check ✅ Passed The description covers the required sections, explains the change and rationale, links issue #25830, provides a justified N/A for visual proof, and describes tests and platform coverage.
Out of Scope Changes check ✅ Passed The transport timeout change and the FakeSocket behavior and tests directly support #25830. The reviewed changes do not show unrelated work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check

Explanation

#25830’s transport objective is implemented: UnixSocketTransport disables the idle timeout while dispatches are in flight, restores it after the last dispatch, and tests cover both a slow non-long-poll reply and idle reaping. The issue also requests a distinct CLI error when the connection closes after the request is written. This PR does not change the CLI error handling, so that coding requirement remains unmet. The issue labels clientMutationId idempotency as a follow-up, so this PR is not required to implement it.

  • Fix all pre-merge checks with AI
  • 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.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks, @ggbdpq! This was rebuilt on current main and merged in #29262 (your approach was used). Closing as superseded.

@nwparker nwparker closed this Oct 16, 2026
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