Skip to content

fix(remote): stop keepalives from refreshing stuck short-RPC deadlines - #8060

Closed
Jinwoo-H wants to merge 1 commit into
mainfrom
fix/shared-control-short-rpc-deadline
Closed

Jinwoo-H wants to merge 1 commit into
mainfrom
fix/shared-control-short-rpc-deadline

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A remote-runtime server keepalive frame refreshed the timeout of every pending request on the shared-control socket. Those pending requests are ordinary short RPCs (git / repo / session-tabs — nearly all control-plane calls except status.get), while the keepalive is armed server-side only while a long-poll subscription is in flight on the same socket (runtime-rpc.ts arms it for terminal.wait / orchestration.check --wait).

Consequence: while any long-poll kept keepalives flowing, a genuinely-stuck short RPC never reached its deadline. The caller hung forever with no error, the timeout-driven teardown → reconnect → subscription-replay never fired, and 8 such hangs exhausted the per-environment call queue (concurrency 8, runtime-rpc-call-queue.ts), wedging all further control-plane calls for that environment.

Fix

Distinguish request kinds. Each pending request is now tagged with refreshTimeoutOnKeepalive (default false):

  • Ordinary short RPCs keep an absolute deadline — a stuck server call now times out, marks the socket suspect, tears it down, and reconnects/replays subscriptions exactly as onTimeout was designed to do ([Bug]: Remote Orca Server issues #7718).
  • Long-polls routed through the short-RPC path can opt in (refreshTimeoutOnKeepalive: true) to keep the old keepalive-extends-deadline behavior.

No current caller sets the opt-in: today's long-polls (terminal.wait, orchestration.check --wait) run on the subscription map (.subscribe()), which has no per-request timeout and whose longevity is driven by replay/response — not by pendingRequests. So the refresh over pendingRequests never had a legitimate use; the flag is a preserved escape hatch, and subscription behavior is unchanged.

Only the refresh semantics change — every timeout value is left exactly as it was.

Screenshots

No visual change.

Testing

  • pnpm typecheck
  • pnpm test — full remote-runtime-shared-control suite (28) + runtime-rpc, runtime-rpc-call-queue, runtime-environment-request-connections, runtime-environment-transport-routing (66) all pass
  • oxlint (changed files) + pnpm check:max-lines-ratchet
  • Added a deterministic fake-timer repro (remote-runtime-shared-control-keepalive-refresh.test.ts):
    • stuck short RPC + periodic keepalives → still times out (this test hangs to the 30s vitest cap on unpatched main; passes with the fix)
    • long-poll opted into refresh + same keepalives → never times out, resolves normally
    • short RPC, no keepalives → deadline fires
    • Updated the real-socket connection test that previously asserted the buggy "keepalive extends a short RPC" contract to assert the corrected absolute-deadline behavior.

AI Review Report

Reviewed the timeout registration/refresh/teardown path across remote-runtime-shared-control-{requests,state,frame-dispatch,connection,send,subscription-start}.ts. Confirmed subscriptions never enter pendingRequests, so tightening pendingRequests deadlines cannot shorten subscription longevity; the onTimeout → teardown/reconnect/replay wiring is preserved and still covered by the existing "tears down the socket when a request times out" test. Change is pure TypeScript control-plane logic with no platform-specific code (no shortcuts, labels, paths, shell, or Electron surfaces) — identical on macOS, Linux, and Windows.

Security Audit

No new input handling, command execution, path handling, auth, secrets, dependency, or IPC surface. The change only makes a client-side request deadline stricter (absolute vs refreshable), which strictly reduces the window a wedged/half-open connection can hold resources. No follow-up needed.

Notes

Core SSH / remote-server territory: this shared-control connection backs both the SSH remote-runtime and remote Orca Server topologies (both route control-plane RPCs through RemoteRuntimeSharedControlConnection), so both benefit from the queue-wedge fix. Risk for legitimately long-running short RPCs: they already had a bounded caller-supplied timeout before this change (keepalive refresh only ever masked hangs, it did not grant well-behaved long RPCs a larger budget), so none regress; if a genuinely long short-RPC surfaces later, bump its timeoutMs at the call site or opt it into refresh.

Made with Orca 🐋

A shared-control keepalive frame refreshed the timeout of every pending
request on the shared socket. Those pending requests are ordinary short
RPCs (git/repo/session-tabs), while the keepalive is armed server-side
only for an unrelated long-poll on the same socket. So while any long-poll
kept keepalives flowing, a genuinely-stuck short RPC never hit its
deadline: the caller hung forever, the timeout-driven teardown/reconnect/
replay never fired, and eight such hangs exhausted the per-environment
call queue (concurrency 8), wedging all further control-plane calls.

Tag each pending request with `refreshTimeoutOnKeepalive` (default false).
Short RPCs now keep an absolute deadline so a stuck server call times out,
tears the socket down, and reconnects/replays as designed. Only requests
that explicitly opt in (long-polls routed through the short-RPC path) may
have their deadline extended by keepalives — preserving that escape hatch
without changing any current caller, since today's long-polls run on the
subscription map, not pendingRequests.

Applies to both SSH remote-runtime and remote Orca Server topologies,
which share this control connection.
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2c8ad755-8d88-410f-b5ae-0216f5c4dc89

📥 Commits

Reviewing files that changed from the base of the PR and between 3f9dbba and bea9273.

📒 Files selected for processing (5)
  • src/shared/remote-runtime-shared-control-connection.test.ts
  • src/shared/remote-runtime-shared-control-keepalive-refresh.test.ts
  • src/shared/remote-runtime-shared-control-requests.ts
  • src/shared/remote-runtime-shared-control-state.ts
  • src/shared/remote-runtime-shared-control-types.ts

📝 Walkthrough

Walkthrough

Shared control requests now carry an opt-in refreshTimeoutOnKeepalive flag, defaulting to false. Timeout refresh processing skips requests without that flag. New tests verify short RPC deadlines, long-poll refresh behavior, timeout cleanup, and repeated keepalive handling. The test server now emits recurring keepalive frames when configured with a delay and sends one immediate frame when no delay is provided.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: keepalives no longer refresh deadlines for stuck short RPCs.
Description check ✅ Passed The description matches the template and covers summary, screenshots, testing, AI review, security audit, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Superseded by #8141, which combines all ten remote-reliability audit fixes, incorporates the valid CodeRabbit follow-ups, and has full CI plus live Electron/SSH validation. Closing this standalone PR so #8141 is the single review target; this fix remains included there.

@Jinwoo-H Jinwoo-H closed this Jul 10, 2026
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants