Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds encrypted session probes with configurable intervals and timeouts. The probes depend on connection readiness and active subscriptions, reschedule busy requests, and close stale sockets when appropriate. Connection handling now reconciles subscription lifecycle, propagates abort signals, cleans cancellation resources, and uses shared socket and reconnection helpers. Reusable encrypted test-server and zombie-relay helpers support unit and end-to-end recovery tests. Reliability-gate configuration records coverage, evidence, budgets, and promotion criteria. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
|
Rebased onto current main. Both conflicts trace to the overnight revert of #10179 (#10255): the shared-control types file keeps only this PR's |
ba143a8 to
122e73c
Compare
122e73c to
b42173e
Compare
|
Rebased onto current main. The reworked OOM foundation (#10299) brought back |
b42173e to
7aaeaf6
Compare
Greptile SummaryThis PR adds an encrypted session probe to the shared-control connection that fires a
Confidence Score: 4/5Safe to merge; the self-heal path is isolated behind generation fencing and the existing close/reconnect/replay machinery. The probe, abort-signal plumbing, and test server extraction are logically correct and tested across unit, integration, and E2E layers. The only open items are two missing comments: one explaining that schedule() aborts in-flight probes when conditions fail, and one preserving the backoff-bypass rationale in the extracted manual-reconnect helper. Files Needing Attention: remote-runtime-shared-control-session-probe.ts and remote-runtime-shared-control-manual-reconnect.ts both merit a small clarifying comment added before merge.
|
| Filename | Overview |
|---|---|
| src/shared/remote-runtime-shared-control-session-probe.ts | New core probe class; schedule/clear/runProbe logic is sound: non-sliding cadence, generation fencing, abort-aware error path, and admission-saturation reschedule all correctly modelled. |
| src/shared/remote-runtime-shared-control-connection.ts | Probe integrated at all lifecycle touch-points; generation captured correctly at forceClose call time, not at lambda construction time. |
| src/shared/remote-runtime-shared-control-requests.ts | AbortSignal support added correctly with early-abort fast-path, post-add re-check for the signal→listen race, and releaseCancellation cleanup. |
| src/shared/remote-runtime-shared-control-state.ts | releasePendingRequestCancellation called in all three rejection/resolution paths — no listener leaks. |
| src/shared/remote-runtime-shared-control-manual-reconnect.ts | Logically equivalent extraction but the original Why-comment about backoff bypass was not carried over. |
| tests/e2e/helpers/zombie-runtime-relay.ts | preserveUpstream flag correctly prevents client-socket close after server-side termination; zombifyActiveSessions awaits close confirmation before returning. |
Sequence Diagram
sequenceDiagram
participant C as Client
participant R as Relay (zombie)
participant S as Server (restarted)
C->>R: WS connect
R->>S: WS connect
Note over C,S: Normal session established
C->>R: subscribe(runtime.clientEvents)
R->>S: subscribe(runtime.clientEvents)
S-->>R: "{type:ready}"
R-->>C: "{type:ready}"
Note over R,S: Server restarts — relay socket stays open
R-xS: downstream severed (zombifyActiveSessions)
Note over C,R: Relay still auto-answers RFC 6455 pings
loop Every 15s probe interval
C->>R: status.get (encrypted)
R-xS: forwarded — S has no session
Note over C: probe times out 10s → force-close
end
C->>R: WS close (generation fenced)
R->>S: new WS connect
Note over C,S: Fresh E2EE session + subscription replay
C->>R: subscribe(runtime.clientEvents) replayed
R->>S: subscribe(runtime.clientEvents)
S-->>R: "{type:ready} + new worktree events"
R-->>C: new worktree events
Note over C: Sidebar updated
Reviews (1): Last reviewed commit: "fix(remote-runtime): bound session probe..." | Re-trigger Greptile
| export function reconnectSharedControlNow( | ||
| unavailable: boolean, | ||
| closeSocket: (error: RemoteRuntimeClientError) => void, | ||
| open: () => void | ||
| ): void { | ||
| if (!unavailable) { | ||
| return | ||
| } | ||
| closeSocket(remoteRuntimeUnavailableError('Refreshing remote runtime control transport.')) | ||
| open() | ||
| } |
There was a problem hiding this comment.
The original
reconnectNow inline code carried a Why comment explaining that the caller should replace even a stuck CONNECTING/awaiting-ready socket rather than wait behind stale backoff when the endpoint is known to be reachable. That rationale is lost here, so the function now reads as a plain guard without signalling its intent to future readers.
| export function reconnectSharedControlNow( | |
| unavailable: boolean, | |
| closeSocket: (error: RemoteRuntimeClientError) => void, | |
| open: () => void | |
| ): void { | |
| if (!unavailable) { | |
| return | |
| } | |
| closeSocket(remoteRuntimeUnavailableError('Refreshing remote runtime control transport.')) | |
| open() | |
| } | |
| export function reconnectSharedControlNow( | |
| unavailable: boolean, | |
| closeSocket: (error: RemoteRuntimeClientError) => void, | |
| open: () => void | |
| ): void { | |
| if (!unavailable) { | |
| return | |
| } | |
| // Why: replace even a stuck CONNECTING/awaiting-ready socket instead of | |
| // waiting behind stale backoff when the caller has proof the endpoint is reachable. | |
| closeSocket(remoteRuntimeUnavailableError('Refreshing remote runtime control transport.')) | |
| open() | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Restored the Why comment on the replace-stuck-socket path in 4c324295a8.
| schedule(): void { | ||
| if ( | ||
| this.hooks.isIntentionallyClosed() || | ||
| !this.hooks.hasSubscriptions() || | ||
| !this.hooks.isReady() | ||
| ) { | ||
| this.clear() | ||
| return | ||
| } |
There was a problem hiding this comment.
schedule() is side-effectful in the negative case: when any of the three guard conditions fails it calls clear(), which cancels the timer and aborts any in-flight probe. This is intentional and tested (the "in-flight probe retirement" case relies on it), but the method name alone implies a purely-additive operation. A Why comment here would help the next reader who calls schedule() expecting it never tears down an existing probe.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Added a Why comment noting that schedule() doubles as teardown when its guards fail (4c324295a8).
8181d68 to
4c32429
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Rebased onto current main (resolved the reliability-gates.jsonc conflict by keeping both gate entries) and addressed both review threads. Also pinned the shared-control test server to 127.0.0.1: on macOS a concurrent process binding the same ephemeral port on loopback shadows a wildcard listener, which intermittently hijacked the test connections on a machine running the Orca app. Focused shared-control tests pass 8/8 consecutive runs; typecheck and lint clean. |
There was a problem hiding this comment.
Actionable comments posted: 7
🧹 Nitpick comments (3)
src/shared/remote-runtime-shared-control-session-probe.test.ts (1)
55-95: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd the positive
forceClosecase.Both tests assert the negative path: the probe must not force a close after the subscription ends. No test asserts that
forceCloseruns when a probe fails while the socket is unchanged and subscriptions remain active. That branch is the core failure behavior ofSharedControlSessionProbe. Add a test that rejects the probe without callingprobe.clear()and assertsforceClosereceives the mapped error.tests/e2e/helpers/zombie-runtime-relay.ts (1)
91-110: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse the destructured connection instead of an index lookup.
Line 104 reaches back into
active[index]to setpreserveUpstreamon the element the callback already receives. Destructure the connection itself. The flag must still be set beforeterminate(), which the rewrite preserves.♻️ Proposed refactor
await Promise.all( active.map( - ({ downstream }, index) => + (connection) => new Promise<void>((resolve) => { - active[index].preserveUpstream = true - downstream.once('close', resolve) - downstream.terminate() + connection.preserveUpstream = true + connection.downstream.once('close', resolve) + connection.downstream.terminate() }) ) )tests/e2e/pr10235-stale-subscription-restart.spec.ts (1)
72-84: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename
readSharedControlGenerationto match the value it reads.The function reads
remoteControl?.lastConnectedAt, which is a timestamp, not a generation counter. The name and thesharedControlGenerationBeforeFaultvariable at line 122 suggest a monotonic generation identifier. Rename both to referencelastConnectedAtso a later reader does not assume generation semantics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c08386da-b0da-4c06-a8f4-08fc057a081a
📥 Commits
Reviewing files that changed from the base of the PR and between bc1e049 and 4c324295a81f57c0625483dd992b2bd15540ad57.
📒 Files selected for processing (16)
config/reliability-gates.jsoncsrc/shared/remote-runtime-shared-control-connection.test.tssrc/shared/remote-runtime-shared-control-connection.tssrc/shared/remote-runtime-shared-control-frame-dispatch.tssrc/shared/remote-runtime-shared-control-frame-handler.tssrc/shared/remote-runtime-shared-control-manual-reconnect.tssrc/shared/remote-runtime-shared-control-ready.tssrc/shared/remote-runtime-shared-control-requests.tssrc/shared/remote-runtime-shared-control-session-probe.test.tssrc/shared/remote-runtime-shared-control-session-probe.tssrc/shared/remote-runtime-shared-control-socket-generation.tssrc/shared/remote-runtime-shared-control-state.tssrc/shared/remote-runtime-shared-control-test-server.tssrc/shared/remote-runtime-shared-control-types.tstests/e2e/helpers/zombie-runtime-relay.tstests/e2e/pr10235-stale-subscription-restart.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/shared/remote-runtime-shared-control-socket-generation.ts
- src/shared/remote-runtime-shared-control-ready.ts
- config/reliability-gates.jsonc
Add an encrypted session probe to the shared control connection: a WS-terminating relay answers protocol pings itself, so a restarted orca serve behind it looks alive while its subscription registry is gone. A failed probe force-closes into the existing reconnect+replay machinery. Split out of stablyai#9614.
…st server to loopback - Restore the "Why" comment on reconnectSharedControlNow's replace-stuck-socket path - Document that schedule() doubles as teardown when its guards fail - Bind the shared-control test server to 127.0.0.1 explicitly: on macOS a concurrent process binding the same ephemeral port on loopback shadows a wildcard listener and hijacks the tests' connections Co-Authored-By: Claude Fable 5 <[email protected]>
4c32429 to
a01f38f
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
…den tests - requireSessionProbeSuccess throws on an ok:false status.get response so lost session authority triggers recovery instead of a reschedule (+ failMethods coverage) - createSharedControlSessionProbe rejects zero/negative/non-finite timing overrides with a RangeError (+ test) - Probe connection tests close their connection in finally - Test server captures a per-connection index for ready-frame suppression and consumes the one-shot close-after-streaming flag when the response is sent, so delayed paths still observe the close - E2E seed commit disables gpgsign; the stale-surface check is a single immediate read instead of a 2s negative poll Co-Authored-By: Claude Fable 5 <[email protected]>
|
Rebased onto current main (kept both new upstream gates plus this branch's session-authority gate in reliability-gates.jsonc) and addressed all seven review findings — both majors (ok:false probe responses now trigger recovery via requireSessionProbeSuccess; probe timing overrides are validated) and the five minors. 40 focused shared-control tests pass 3/3 runs, the headless pr10235 e2e journey passes (32s), and typecheck is clean. Note: pnpm lint currently warns on src/renderer/src/components/WorktreeJumpPalette.tsx (react-hooks exhaustive-deps) — that file is byte-identical to upstream main and untouched by this branch. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/shared/remote-runtime-shared-control-session-probe.test.ts (2)
55-95: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDrain microtasks with a timer advance instead of counting
await Promise.resolve().Lines 90-91 assume
runProbeneeds exactly two microtask turns after the rejection before it can reachforceClose. Line 70 makes the same assumption. If a future change adds anawaitinsiderunProbe, these tests pass even when the guard is removed, becauseforceClosehas not run yet at assertion time.vi.advanceTimersByTimeAsync(0)drains the microtask queue without depending on the turn count.♻️ Proposed change
rejectProbe(new Error('session lost')) - await Promise.resolve() - await Promise.resolve() + await vi.advanceTimersByTimeAsync(0) expect(forceClose).not.toHaveBeenCalled()Apply the same change at line 70:
await pendingProbe - await Promise.resolve() + await vi.advanceTimersByTimeAsync(0)
104-122: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the socket-replacement guard.
state.socketandstate.intentionallyClosedare never mutated by any test in this file. Two guards inrunProbestay uncovered: thegetSocket() === probedSocketcheck that stops a stale probe from force-closing a replacement socket, and theisIntentionallyClosed()check. The socket-replacement guard is the one that protects a recovered session, so a regression there is expensive.Add a test that reassigns
state.socketto a second object while a probe is pending, rejects the probe, and assertsforceCloseis not called.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fbf55052-b353-4768-b63b-ee6d14976eb0
📒 Files selected for processing (16)
config/reliability-gates.jsoncsrc/shared/remote-runtime-shared-control-connection.test.tssrc/shared/remote-runtime-shared-control-connection.tssrc/shared/remote-runtime-shared-control-frame-dispatch.tssrc/shared/remote-runtime-shared-control-frame-handler.tssrc/shared/remote-runtime-shared-control-manual-reconnect.tssrc/shared/remote-runtime-shared-control-ready.tssrc/shared/remote-runtime-shared-control-requests.tssrc/shared/remote-runtime-shared-control-session-probe.test.tssrc/shared/remote-runtime-shared-control-session-probe.tssrc/shared/remote-runtime-shared-control-socket-generation.tssrc/shared/remote-runtime-shared-control-state.tssrc/shared/remote-runtime-shared-control-test-server.tssrc/shared/remote-runtime-shared-control-types.tstests/e2e/helpers/zombie-runtime-relay.tstests/e2e/pr10235-stale-subscription-restart.spec.ts
🚧 Files skipped from review as they are similar to previous changes (12)
- src/shared/remote-runtime-shared-control-frame-dispatch.ts
- src/shared/remote-runtime-shared-control-manual-reconnect.ts
- src/shared/remote-runtime-shared-control-types.ts
- src/shared/remote-runtime-shared-control-ready.ts
- src/shared/remote-runtime-shared-control-socket-generation.ts
- src/shared/remote-runtime-shared-control-frame-handler.ts
- src/shared/remote-runtime-shared-control-state.ts
- src/shared/remote-runtime-shared-control-requests.ts
- tests/e2e/helpers/zombie-runtime-relay.ts
- src/shared/remote-runtime-shared-control-test-server.ts
- src/shared/remote-runtime-shared-control-session-probe.ts
- config/reliability-gates.jsonc
createGitRepo removes its temp directory when a git step throws, repo creation happens inside the oracle's try so the client/relay always dispose, and each teardown step catches its own rejection so cleanup completes and the original test error propagates. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Fixes stale subscriptions after
orca serverestarts behind a WS-terminating relay. The socket-level liveness monitor pings at the RFC 6455 control-frame layer, but such a relay answers those pings itself — so when the server process restarts, the client's E2EE session and the server's in-memory subscription registry are gone while the socket still looks alive, and worktrees created after the restart never reach the sidebar until an app reload. This PR adds an encrypted session probe (status.getevery 15s while subscriptions are active): only the server holding this connection's session keys can answer, so a failed probe proves the session is dead and force-closes into the existing close → reconnect → subscription-replay machinery. Responsive connections stay on their socket; probing stops when no subscriptions are active.Split out of #9614, which bundled this with the unrelated app-version-skew feature; #9614 will be rebased down once the split PRs land.
Tests: new cases in
remote-runtime-shared-control-connection.test.ts, including a zombie-relay repro (server records requests but never answers while ws pings keep succeeding → probe forces reconnect and the subscription is re-established on a fresh connection), plus no-reconnect-while-probes-succeed and no-probes-without-subscriptions.pnpm typecheckand the test file green locally.Review starting point: the header comment in
src/shared/remote-runtime-shared-control-session-probe.ts.cc @OrcaWin
ELI5
After orca serve restarts behind a relay that answers WebSocket pings, the client still looked connected but missed new worktrees. An encrypted session probe self-heals stale subscriptions without a full app reload.