Skip to content

fix(runtime-rpc): don't reap a socket while its request is still running - #22347

Closed
Jinwoo-H wants to merge 1 commit into
mainfrom
jinwoo/rpc-idle-timer
Closed

Jinwoo-H wants to merge 1 commit into
mainfrom
jinwoo/rpc-idle-timer

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​148 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​143
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11

ELI5

When you run an orca command that takes more than 30 seconds (for example, creating a worktree while setup runs), Orca hung up on the command halfway through. The command then said Orca wasn't running, even though Orca kept going and finished the job. Now Orca stays on the line until it has answered.

What Changed

Before: Any CLI request that ran longer than 30 seconds, and was not one of the few "wait" commands, failed at exactly 30 seconds with "The Orca runtime closed the connection before responding. Restart Orca and try again.", followed by "Orca is not running". The work kept running in the app and usually finished, which left worktrees nobody asked for and actions that were reported as failed but had actually happened.

After: The request gets its real result, whether it succeeded or failed, however long it takes. The CLI's own timeout (60 seconds by default, or whatever the caller passes) is still what limits a request that never finishes.

Mechanism: The local runtime socket (src/main/runtime/rpc/unix-socket-transport.ts, used for Unix sockets on macOS/Linux and named pipes on Windows) closed any connection that went quiet for 30 seconds. That rule is meant to clean up clients that connect and then go silent, but it also applied while the server was still working on a request, because nothing is written to the socket during that time. The idle timer now pauses while a request is running on the connection and starts again when the last running request replies. The transport already tracked running requests per connection for its abort handling, so the pause and restart hook into that existing tracking.

Unchanged:

  • A connection that never sends a request, or stays open after its reply, is still closed after 30 seconds.
  • If the client disconnects mid-request (for example, because the CLI's own timeout fired), the existing close handling still aborts the request and releases its connection slot and state.
  • Nothing about the wire protocol changes. Messages, keepalive frames, and the CLI are the same, so old CLIs and new apps work with each other in both directions.

Why

The 30-second timer was closing the connection on the server side, so the fix goes there.

  • Keepalive frames for every request (not chosen for now): these would also keep the connection open, but they send extra frames on every slow request. Old CLIs only handle keepalives on the path built for long waits. That makes it a wire-level change, and it would need its own compatibility review. Pausing the timer fixes the bug without changing anything on the wire. Keepalives are still used where they already are (long-poll commands like check --wait).
  • Raising the 30-second limit: this only moves the cutoff, so a 31-second job would still fail at the new limit.

One side effect: a connection with a request that never finishes is no longer closed after 30 seconds. The CLI times out and disconnects on its own, which frees the connection. Only same-user local clients can reach this socket (it is mode 0600 on Unix).

This also stops the 30-second socket cutoff from racing the daemon client's 30-second request timeout (src/main/daemon/client.ts). A daemon timeout error now reaches the CLI as a real error instead of a dropped connection.

Linked Issue

STA-4989, STA-7258, STA-1346

Fixes #

Visual Proof

N/A. No UI changes. What changes is the CLI's result for requests longer than 30 seconds, and the tests below cover it.

Testing

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

New tests in src/main/runtime/rpc/unix-socket-transport.test.ts:

  • A request that runs 35 seconds still gets its reply written (fake timers, named-pipe transport kind).
  • The idle timer restarts after the last running request replies, and closes the connection 30 seconds later.
  • A connection that sends nothing is still closed at 30 seconds.
  • A client that disconnects mid-request triggers the request's abort, nothing is written afterward, and no timers are left running.
  • Real Unix socket: a 400 ms request against a 100 ms idle limit returns its real reply, and a silent connection is still closed.

Fails before, passes after: on origin/main, the 35-second and re-arm tests fail, because the socket is destroyed at 30 seconds. With only the timeout made injectable on main, the real-socket test fails with "closed before responding". With this change, all 11 tests pass. runtime-rpc-long-poll-transport.test.ts and all 18 src/main/runtime/runtime-rpc* test files pass (139 tests), and pnpm tc:node, oxlint, oxfmt and check:code-quality:changed are clean.

Platforms: tested on macOS. The Windows named-pipe path uses the same class and code path, and the fake-socket tests use the named-pipe kind. The real-socket tests skip on Windows.

Review

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

Security: the socket is local and restricted to the same user. Cross-platform: Unix sockets and named pipes share one implementation. SSH/remote: remote clients use the WebSocket/relay transports, which this change does not touch. Mobile: not affected. Backwards compatibility: no wire change. Performance: one extra setTimeout call per request.

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)

The 30s idle timeout destroyed CLI sockets whose request took longer than
30s, so the CLI reported 'Orca is not running' while the work still landed.
Pause the idle timer while any request is in flight on the connection and
re-arm it when the last one replies.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 723d4277-c5c6-486a-be88-d896528c5f4a

📥 Commits

Reviewing files that changed from the base of the PR and between 7240368 and 840c86e.

📒 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: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

This change updates UnixSocketTransport idle-timeout handling for UNIX socket RPC. The transport now accepts an optional idleTimeoutMs value, uses that value when it arms socket timeouts, and pauses the idle timer while a request is in flight. When the last in-flight request finishes, the transport restores the idle timer. The tests now simulate net.Socket timeout behavior in FakeSocket and add cases for idle reaping, delayed replies, timer re-arming, disconnect aborts, and real UNIX socket behavior.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 840c8

Long-running runtime RPC requests retain their socket until they reply, while idle connections continue to be reaped. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: the runtime RPC socket is not reaped while a request is running.
Description check ✅ Passed The description explains the problem, change, rationale, compatibility, and testing in detail. It includes linked issue IDs, but the “Fixes #” field is blank, and the full lint, typecheck, test, and b…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

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

ℹ️ No blocking issues — one stale-comment cleanup for the follow-up queue.

Reviewed changes

  • Pauses the per-connection idle reap during a request. dispatchMessage now calls socket.setTimeout(0) while a dispatch is registered in inflight, and cleanupDispatch re-arms socket.setTimeout(this.idleTimeoutMs) once the last in-flight dispatch settles, so a handler that runs past 30 s no longer has its reply written to a destroyed socket.
  • Adds an injectable idleTimeoutMs option. Defaults to the existing 30 s constant; the tests use 100 ms to exercise the reap on a real Unix socket without waiting 30 s.
  • Expands test coverage. FakeSocket now models Node's setTimeout semantics (0 disables, activity restarts), and there are five fake-timer tests (never-sends reap, slow reply surviving the timeout, re-arm after the last in-flight reply, abort + timer-free on client disconnect) plus two real-socket tests. Ran the file locally: 11/11 pass.

ℹ️ Stale comments still describe the removed 30 s server-side backstop

The change removes the only unconditional 30 s reap on the server side, but three "Why" comments still justify their design against it. They should be refreshed so a future debugger does not chase a safety net that no longer exists.

Technical details
# Stale 30 s idle-backstop references

## Affected sites
- `src/main/runtime/runtime-rpc/runtime-rpc-long-poll-transport.test.ts:797-799` — "Without the `.catch` on handleMessage's promise, a throw would leave the client hanging until the 30s idle timer and leak the dispatch's AbortController in the transport's in-flight set." With the timer paused during dispatch, the client hangs until its own timeout, not 30 s.
- `src/main/runtime/runtime-rpc/runtime-rpc-long-poll.ts:45-49` — "...it needs the same keepalive as check --wait or the 30 s socket idle timer tears it down." Keepalive is still required, but now to refresh the *client* 60 s timer (`src/cli/runtime/transport.ts:98`/`:137`), not the server's.
- `src/main/runtime/runtime-rpc/runtime-rpc-pairing-types.ts:128` — "keepalive frames count as socket activity, resetting both idle timers so long-polls outlive the 30s/60s idle caps." The server idle timer is disabled while a dispatch is in flight, so there is nothing to reset on that side.

## Required outcome
- The comments should state the current mechanism: keepalive still refreshes the client-side ceiling; the server no longer reaps during an in-flight request (nor during a never-settling one).

## Notes
- Sites are outside this PR's diff, so they cannot be anchored inline. Non-blocking.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor

Thanks, @Jinwoo-H! 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.

2 participants