Repository navigation
feat(ssh): add pty.resumeClient and split SSH PTY process listing (#16741 T2 P5+P6) - #24414
Conversation
…6741 T2 P5+P6) P6: a relay now answers pty.resumeClient, which admits only an exact resume of the existing session owner (it never mints a fresh claim when that owner is gone). resumeSshPtyConsumerSession calls it with cancellation and authority checks; an old relay's method-not-found becomes a pty_consumer_resume_unsupported refusal that leaves the channel usable for pty.openClient. Owner grant publication now rolls back if the response-settlement hook cannot be armed, and the adapter exposes read-only owner and publication-settled queries. P5: SshPtyProvider.listProcesses moves to ssh-pty-process-list unchanged, and the notification-routing tests split into a shared fixture plus recovery and recovery-activation files. Nothing calls pty.resumeClient yet (T6). Ported by hunk from #16741 (a68b6f3) without ownership-transfer (T7) or Bun runtime hunks.
|
| } | ||
|
|
||
| describe('SSH PTY notification recovery routing', () => { | ||
| it('rejects a stale activation without disturbing current continuity', () => { |
There was a problem hiding this comment.
Duplicated recovery tests The new recovery suite repeats four activation tests in
ssh-pty-notification-recovery-activation.test.ts and two routing tests already in ssh-pty-notification-routing.test.ts. It also recreates the shared subscription fixture. These duplicates make the tests take longer and create copies that can drift apart; keep each case in one suite and use the shared fixture.
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!
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Warning Review limit reachedYou'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 38 seconds. View limit detailsLimit details: You’ve used all 10 included reviews currently available. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes add a dedicated SSH PTY consumer-session resume path across shared, client, and relay code. They add resume validation and track ownership admissions until response publication settles. SSH PTY notification tests now use a shared fixture and cover activation recovery and rollback. Process listing moves from the provider into a configured helper. A spawn-environment test checks PATH and relay bridge values. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/providers/ssh-pty-notification-routing-recovery.test.ts (1)
1-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the shared fixture and remove the duplicated tests.
This file redefines
MockMux,createSubscription, andsourceActivationin Lines 5-69. The same helpers already exist inssh-pty-notification-routing-test-fixture.ts. The PR adds that fixture so the test files can share these helpers.Four tests here also duplicate tests in
ssh-pty-notification-recovery-activation.test.tsexactly:
- "rejects a stale activation without disturbing current continuity" (Lines 72-102 here, Lines 172-202 there).
- "drops provisional frames and settles cancellation before rollback completes" (Lines 104-134 here, Lines 204-234 there).
- "restores the exact prior cursor when a replacement rolls back after frames" (Lines 136-185 here, Lines 236-285 there).
- "does not let an older lease rollback replace a newer activation" (Lines 187-225 here, Lines 287-325 there).
If someone later changes the fixture or the routing contract, the two copies can drift apart, and only one copy will show the behavior that is actually used. To fix this:
- Import
createSubscriptionfrom the shared fixture.- Delete the local helpers.
- Keep each of the four tests in only one file.
Only the missing-id and control-method tests (Lines 227-280) are unique to this file.
♻️ Proposed change
-import { describe, expect, it, vi } from 'vitest' -import { subscribeSshPtyNotifications } from './ssh-pty-notification-routing' -import type { PtySourceReceivingActivation } from '../../shared/pty-source-receiving-activation' - -type MockMux = { ... } -function createSubscription() { ... } -function sourceActivation(...) { ... } +import { describe, expect, it, vi } from 'vitest' +import { createSubscription } from './ssh-pty-notification-routing-test-fixture'Then delete the four duplicated
it(...)blocks from this file.Also applies to: 72-225
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 3b7a12c3-ecbb-4963-8490-183f8bfc2bf9
📒 Files selected for processing (15)
src/main/providers/ssh-pty-notification-recovery-activation.test.tssrc/main/providers/ssh-pty-notification-routing-recovery.test.tssrc/main/providers/ssh-pty-notification-routing-test-fixture.tssrc/main/providers/ssh-pty-notification-routing.test.tssrc/main/providers/ssh-pty-process-list.tssrc/main/providers/ssh-pty-provider.tssrc/main/providers/ssh-pty-spawn-env.test.tssrc/main/ssh/ssh-pty-consumer-resume-session.test.tssrc/main/ssh/ssh-pty-consumer-session.tssrc/relay/ssh-pty-consumer-resume-client.test.tssrc/relay/ssh-pty-consumer-session-adapter.test.tssrc/relay/ssh-pty-consumer-session-adapter.tssrc/shared/pty-consumer-session-contract.tssrc/shared/pty-consumer-session-resume-only.test.tssrc/shared/pty-consumer-session.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
There was a problem hiding this comment.
ℹ️ Minor suggestions only.
Reviewed changes
pty.resumeClientRPC — new dedicated relay method registered besidepty.openClient; routes throughPtyConsumerSession.admitResumed, which refuses a missing/expired owner withpty_consumer_resume_owner_missingand never mints a replacement claim.- Resume client —
resumeSshPtyConsumerSessionsends onlypty.resumeClient, validates authority/abort/disposal around the request, maps old-relay-32601topty_consumer_resume_unsupported, and requires an exact-resume grant. - Publication rollback fix — a throwing
onResponseSettledregistration now rolls the admission back instead of leaking a half-admitted owner. - P5 extraction —
SshPtyProvider.listProcessesmoved tossh-pty-process-list.ts; notification-routing tests split into a shared fixture plus routing/recovery/recovery-activation files.
The wire-compatibility reasoning checks out: the mux preserves the JSON-RPC code on rejection, an older relay answers unknown requests with -32601 and keeps the channel open, and the client classifies that explicitly without falling back to pty.openClient. The extraction is behaviorally identical.
ℹ️ Duplicated recovery tests and fixture in a new file
ssh-pty-notification-routing-recovery.test.ts looks like it contributes no unique coverage — its four recovery tests are byte-for-byte identical to tests in the sibling ssh-pty-notification-recovery-activation.test.ts, and its two remaining tests already live in ssh-pty-notification-routing.test.ts. It also re-declares the createSubscription/sourceActivation fixture that this PR just extracted into ssh-pty-notification-routing-test-fixture.ts.
Technical details
# Duplicate recovery tests and fixture
## Affected sites
- `src/main/providers/ssh-pty-notification-routing-recovery.test.ts:10` — local `createSubscription`/`sourceActivation`, duplicating `ssh-pty-notification-routing-test-fixture.ts`.
- `src/main/providers/ssh-pty-notification-routing-recovery.test.ts:72,104,136,187` — identical to `ssh-pty-notification-recovery-activation.test.ts:172,204,236,287`.
- `src/main/providers/ssh-pty-notification-routing-recovery.test.ts:227,237` — identical to the tests kept in `ssh-pty-notification-routing.test.ts`.
## Required outcome
- Each recovery test runs once, and the newly shared fixture is the single source for `createSubscription`/`sourceActivation`.
- The split still keeps every test from main's original file.
## Suggested approach
- Import from `./ssh-pty-notification-routing-test-fixture` and drop the local fixture copy.
- Remove the four tests that already exist in `recovery-activation` from the routing-recovery file (or vice versa — keep the file whose name matches the concern and delete the other if nothing unique remains).
## Open questions for the human
- Was `ssh-pty-notification-routing-recovery.test.ts` intended to hold recovery *routing* cases (data frames during recovery) that were never added, or is it a copy-paste artifact?Nitpicks
ssh-pty-process-list.ts:36-38inlinesMath.max(1, deadlineMs - Date.now()), duplicatingrelayTimeoutOptionsinssh-pty-provider.ts:31. Consider lifting that helper so the deadline semantics stay in one place.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| request: ReturnType<typeof vi.fn> | ||
| } | ||
|
|
||
| function createSubscription() { |
There was a problem hiding this comment.
These four recovery tests (lines 72, 104, 136, 187) are byte-for-byte identical to ssh-pty-notification-recovery-activation.test.ts:172,204,236,287, and the two tests at lines 227/237 already live in ssh-pty-notification-routing.test.ts. This file also re-declares the createSubscription/sourceActivation fixture that this PR extracted into ssh-pty-notification-routing-test-fixture.ts, so it looks like it adds no unique coverage. Could this file be dropped, or did it mean to hold recovery routing cases that weren't added?
…journal (#16741 T3 R1) The relay gains an owner-reset surface that no current client calls. A session-owner client will be able to ask its relay to prepare a shutdown (`relay.reset`), have that preparation journaled durably beside the relay endpoint, and later recover it (`relay.recoverPreparedReset`, or the read-only `--read-reset-preparation` exec mode if the daemon is gone). Relay status advertises `relay.ownerReset.v1` and, when a journal is configured, `relay.durableResetPreparation.v1`. Why ahead of its caller: relays and clients update independently, so the host side has to be deployed before any client can rely on it. Old relays answer method-not-found and advertise neither capability, which a client reads as "unavailable", never as "reset". - relay-grace-lifecycle: shutdown is split into prepareShutdown and finishShutdown so a reset can settle its response before the process exits. Idle and signal shutdown keep today's behavior, including the deferred retry when disposal fails, and still do not wait on admitted requests; only a reset initiator drains work around owned-process disposal. - relay-work-drain-contract: both reset requests are admitted during a drain. - relay.ts / relay-daemon.ts: register the reset, its journal under `<endpointDir>/owner-reset-preparations`, the status capabilities, and the reader argv (checked after the self-test and Windows breakaway launch). Porting note (source: #16741 a68b6f3, merge-base 277c289): - Based on #24414, which already adds the adapter's activeSessionOwner and assertOwnerPublicationSettled with code identical to #16741's. - Dropped: network-tunnel fencing (T4), the PTY ownership-transfer fence and its refusal test case (T7), the Bun arm of the reader integration test, the Bun runtimeVersion status field, and #16741's lazy entry imports. - Adapted: wire parsers use a record guard instead of casts; the idle path no longer gains an unbounded work drain. - Added: relay-grace-lifecycle tests (idle exit, deferred retry, attached client, reset preparation, joining and retry) and a wire-contract test pinning the capability, method and flag names.
…journal (#16741 T3 R1) (#24418) The relay gains an owner-reset surface that no current client calls. A session-owner client will be able to ask its relay to prepare a shutdown (`relay.reset`), have that preparation journaled durably beside the relay endpoint, and later recover it (`relay.recoverPreparedReset`, or the read-only `--read-reset-preparation` exec mode if the daemon is gone). Relay status advertises `relay.ownerReset.v1` and, when a journal is configured, `relay.durableResetPreparation.v1`. Why ahead of its caller: relays and clients update independently, so the host side has to be deployed before any client can rely on it. Old relays answer method-not-found and advertise neither capability, which a client reads as "unavailable", never as "reset". - relay-grace-lifecycle: shutdown is split into prepareShutdown and finishShutdown so a reset can settle its response before the process exits. Idle and signal shutdown keep today's behavior, including the deferred retry when disposal fails, and still do not wait on admitted requests; only a reset initiator drains work around owned-process disposal. - relay-work-drain-contract: both reset requests are admitted during a drain. - relay.ts / relay-daemon.ts: register the reset, its journal under `<endpointDir>/owner-reset-preparations`, the status capabilities, and the reader argv (checked after the self-test and Windows breakaway launch). Porting note (source: #16741 a68b6f3, merge-base 277c289): - Based on #24414, which already adds the adapter's activeSessionOwner and assertOwnerPublicationSettled with code identical to #16741's. - Dropped: network-tunnel fencing (T4), the PTY ownership-transfer fence and its refusal test case (T7), the Bun arm of the reader integration test, the Bun runtimeVersion status field, and #16741's lazy entry imports. - Adapted: wire parsers use a record guard instead of casts; the idle path no longer gains an unbounded work drain. - Added: relay-grace-lifecycle tests (idle exit, deferred retry, attached client, reset preparation, joining and retry) and a wire-contract test pinning the capability, method and flag names. Co-authored-by: m4air <[email protected]>
* Revert "feat(orcad): source-side dormant export of a relay-hosted SSH target (#16741 T6-8) (#24519)" This reverts commit 783101b. * Revert "feat(ssh): update, roll back, recover and stop a managed orcad server (#16741 T6-5 follow-up) (#24463)" This reverts commit 38c2d1d. * Revert "feat(ssh): deploy and pair an empty managed orcad server over SSH (#16741 T6-5) (#24453)" This reverts commit 8b76683. * Revert "fix(ssh): orcad GC honors the activation journal; readiness requires proven daemon coverage (#16741 T6 follow-up) (#24451)" This reverts commit d3f8c50. * Revert "feat(ssh): remote orcad stop by request file and journaled decommission (#16741 T6-4) (#24449)" This reverts commit 43d9b43. * Revert "feat(orcad): supervisable server: stop requests, managed stop receipts and a lifetime that keeps its lock on failed teardown (#16741 T6-3) (#24433)" This reverts commit b093d3a. * Revert "feat(ssh): crash-safe orcad activation, rollback and recovery (#16741 T6-2) (#24423)" This reverts commit 1a9ac0e. * Revert "feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2) (#24420)" This reverts commit 99db2bf. * Revert "feat(relay): capability-gated owner reset with a durable preparation journal (#16741 T3 R1) (#24418)" This reverts commit 34a582b. * Revert "feat(ssh): track connection-manager drains, test probes and provider continuations (#16741 T2 P3+P8a) (#24407)" This reverts commit d53063d. * Revert "feat(daemon): idle retirement, session census and recovery-only provider (#16741 T2 P4b) (#24409)" This reverts commit ff212db. * Revert "feat(ssh): add pty.resumeClient and split SSH PTY process listing (#16741 T2 P5+P6) (#24414)" This reverts commit 92cb717. * Revert "feat(relay): await owned watcher and agent children on shutdown (#16741 T2 P1) (#24400)" This reverts commit 6b36e4f. * Revert "feat(session): retry failed renderer session writes and verify local folder PTYs (#16741 T2 P9) (#24406)" This reverts commit d23ecef. * Revert "feat(ssh): remote orcad primitives on the pinned Node runtime (#16741 T6-1) (#24419)" This reverts commit dd87ae5. * Revert "fix(runtime): fence runtime-environment subscriptions and status probes by identity (#16741 T5-3) (#24421)" This reverts commit ece9e4d. * Revert "feat(orcad): migration manifest and dormant-state contracts (#16741 T6-7) (#24422)" This reverts commit 3fbdaba. * Revert "feat(ssh): wire SshConnection through the work and transport close ledgers (#16741 T2 P2) (#24401)" This reverts commit 4e8edc8. * Revert "feat(profiles): carry markdown frontmatter visibility in project transfers (#16741 T2 P7) (#24405)" This reverts commit 60c9326. * Revert "fix(runtime): project the PTY incarnation onto mobile session tabs (#24413)" This reverts commit 99e0303. * Revert "feat(daemon): tag daemon stream data with the PTY incarnation id (#16741 T2 P4a) (#24402)" This reverts commit 817af76. * Revert "feat(ssh): port the SSH connection work ledger and transport close ledger (#16741 T2) (#24210)" This reverts commit c991893. * Revert "feat(relay): fence and drain file and git response streams on shutdown (#24185)" This reverts commit dc08ffe. * Revert "refactor(runtime-rpc): extract the Node WebSocket lifecycle; opt-in pinned port (#24186)" This reverts commit a789233. * Revert "feat(relay): route relay handlers through work admission; producer publication drain (#24181)" This reverts commit 0b812bd. * Revert "feat(relay): land the #16741 T1 seam (work drain, publication drain, release gate) (#24156)" This reverts commit 3aa2d3a. --------- Co-authored-by: m4air <[email protected]>

ELI5
When an SSH connection drops and reconnects, Orca has to prove it is the same client that owned the remote terminals before. This PR adds a dedicated "resume" request to the remote relay. The request only ever reclaims the exact previous owner and never quietly creates a new one. Nothing calls it yet; a later slice (T6) will. It also tidies the SSH terminal provider and its tests. Today's behavior is unchanged.
This is the T2 P5+P6 slice of porting #16741 (SSH PTY provider extraction, notification-routing recovery tests, and the PTY consumer-session resume RPC).
What Changed
Resume RPC (P6):
pty.resumeClientnext topty.openClient. It uses the same handler with a resume-only admission (PtyConsumerSession.admitResumed).resumeproof and the session-owner role. It is refused withpty_consumer_resume_owner_missingwhen no owner is held. A refused resume doesn't shorten the current owner's disconnect grace.resumeSshPtyConsumerSession(main) sends onlypty.resumeClient, honours an abort signal and an authority check before and after the request, and validates that the grant is an exact resume (same lease, newer generation).-32601). The client turns that into apty_consumer_resume_unsupportedrefusal, with the original error ascause. It never falls back topty.openClientinside the resume call, and the channel stays open, so the caller can stillpty.openClienton the same connection (covered by a test).activeSessionOwnerandassertOwnerPublicationSettled, which the resume tests use.Provider extraction (P5):
SshPtyProvider.listProcessesmoved unchanged intossh-pty-process-list.ts.Why
Wire compatibility (
docs/reference/remote-wire-compatibility.md):pty.openClientmatters because an old relay ignores unknown fields. A resume flag would be silently treated as a fresh claim, which is exactly what resume must never do.Plain SSH mode (#24147) has no relay and therefore no multiplexer, so
pty.resumeClientcan't be attempted there.Relay changes are plain synchronous and async code with no Node 20+ APIs, keeping the relay bundle's Node 18 floor.
Adapted from #16741 (a68b6f3), by hunk:
ssh-pty-provider.ts;onOwnershipTransferOutputandresolveCommittedActivationinssh-pty-notification-routing.ts;ssh-pty-session-reattach.ts;ssh-pty-provider-rpc.ts, whose only consumer is the T7 controls;ssh-pty-provider.test,ssh-pty-live-source-restore-respawn.test, and two ownership-envelope routing tests).ssh-pty-retirement-cancellation.testis not ported, because it needs the T7 delegation fixture.runtimePath/runtimeKindbridge fields inssh-pty-spawn-env.tsexist only to label a Bun relay. The newssh-pty-spawn-env.test.tscovers the Node bridge environment as it is on main.resumeSshPtyConsumerSessionreject with the raw-32601error. Here it is a typed refusal, and the branch test was updated to match.Linked Issue
Part of the Node runtime plan (Phase 3), porting #16741.
Visual Proof
N/A. This is a new relay RPC with no caller yet, plus test-only and internal refactors.
Testing
Ported:
pty-consumer-session-resume-only;ssh-pty-consumer-resume-client(relay dispatcher end to end);ssh-pty-consumer-session-adapter(including the registration-throw rollback);ssh-pty-consumer-resume-session, plus a new old-relay method-not-found test;New:
ssh-pty-spawn-env.test.ts.Regression:
src/main/providers/ssh-pty-*.test.ts,src/relay/*pty*.test.ts,src/main/ssh/ssh-pty-*.test.tsandsrc/shared/pty-consumer-session*.test.ts: 70 files, 740 passed;Lint: both CI lint configs (native-plugins and type-aware,
--deny-warnings) are clean.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.