Repository navigation
feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2) - #24420
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe changes add schemas for SSH access, pending operations, and reconciliation records. They add sidecar storage for environment state and update store operations to read, write, and guard that state. New SSH link and unlink operations validate requests and runtime identity. Tests cover schema constraints, persistence behavior, retries, and conflicting changes. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Nothing calls the new SSH link store yet, so there is no user-visible change. Once it is wired up, a linked environment's first successful response could fail when the runtime id is recorded, and a downgrade rewrite could leave link state hidden from normal reads. Fix both before the store gets a caller. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Durable SSH access introduces a security-sensitive lifecycle with useful identity checks and staged cleanup. However, rollback recovery can hide cleanup state, and a separate credential-deletion change needs further validation. No currently exposed remote exploit was established. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 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 |
|
| if (runtimeIdChanged || pairedDeviceIdChanged) { | ||
| const current = resolveEnvironmentFromStore(readEnvironmentStore(userDataPath), environment.id) | ||
| if (current.sshAccess || current.pendingSshAccessOperation) { |
There was a problem hiding this comment.
Linked requests can fail. When a server is linked before its runtime ID is saved in
orca-environments.json, the sidecar supplies the verified ID. After a successful request, markEnvironmentUsed compares that same ID with the persisted null, treats it as a change, and throws because SSH access is active. An ordinary request can therefore report failure even though the remote operation succeeded. Compare against the overlaid identity and allow the matching ID to be recorded.
Knowledge Base Used: Remote connectivity and execution
| function assertNoIndependentSshAccess(environment: KnownRuntimeEnvironment): void { | ||
| if (environment.sshAccess || environment.pendingSshAccessOperation) { |
There was a problem hiding this comment.
Reconciliation does not block removal. A server can have a durable reconciliation record without SSH access or a pending SSH operation, but this lifecycle guard checks only those SSH fields. Removing that server deletes the record; re-pairing makes it stale, and a runtime ID change is also allowed. Call
assertRuntimeEnvironmentNotReconciling before these mutations so an in-progress reconciliation keeps its authority record.
Knowledge Base Used: Remote connectivity and execution
There was a problem hiding this comment.
Important
Two runtime-identity issues undermine the link lifecycle this PR adds: markEnvironmentUsed rejects the identity a link already verified, which breaks ordinary RPCs after linking, and the overlay and isCurrentEntry disagree on runtimeId, which lets a downgrade hide a durable link from the lifecycle guards. Details inline.
Reviewed changes
Reviewed the single commit 79045b34d4 (11 files) that adds durable SSH access links for paired servers in a sidecar store. Nothing calls the new store yet.
- Two-phase SSH access store —
runtime-environment-ssh-access-store.tsprepares/completes link and unlink, turns a failed verification into a durable unlink intent, and makes a lost completion response return the existing link instead of a second one. - Downgrade-safe sidecar —
runtime-environment-sidecar.tskeeps link state inorca-environment-sidecar.json, bound to{createdAt, pairingRevision, preferredEndpointId}, so a v1.4.217/218 rewrite oforca-environments.jsoncannot strip it. - Schema split —
PersistedRuntimeEnvironmentSchemais the shipped shape;KnownRuntimeEnvironmentSchemaoverlayssshAccess/pendingSshAccessOperation/reconciliation;RuntimeEnvironmentStoreSchemanow persists only the shipped fields. - Lifecycle guards —
removeEnvironment/updateEnvironmentFromPairingCoderefuse while linked or pending, andmarkEnvironmentUsedrefuses a runtime-id/device-id change while linked or pending. - T6 helpers —
verifyRuntimeEnvironmentIdentityandassertRuntimeEnvironmentNotReconciling(provided for T6; not wired into the store). - Tests — 38 new tests across the link store, schema refinements/redaction, and the downgrade rewrite.
ℹ️ Nitpicks
- The downgrade test models shipped endpoints as
z.object({}).passthrough()(runtime-environment-sidecar.test.ts:46) rather than the real key-strippingRuntimeAccessEndpointSchema. It does not change the current assertions, but it means the test does not actually reproduce a shipped build's parse, so it cannot be cited as proof thatPersistedRuntimeEnvironmentSchemaequals the released v1.4.217/218 shape. (The released sources are not reachable in this shallow clone — no tags — so the premise rests on a hand-written schema.) - The test comment "every write (lastUsedAt included) rewrites the whole file" overstates frequency:
lastUsedAtwrites are throttled to one per 60s byLAST_USED_PERSIST_INTERVAL_MS. runtime-environment-sidecar.test.ts:153is titled as though a reconciliation record makes lifecycle changes refuse, but it only asserts thatassertRuntimeEnvironmentNotReconcilingthrows; no store lifecycle function calls it (expected if that wiring is T6's).
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| if (runtimeIdChanged || pairedDeviceIdChanged) { | ||
| const current = resolveEnvironmentFromStore(readEnvironmentStore(userDataPath), environment.id) | ||
| if (current.sshAccess || current.pendingSshAccessOperation) { | ||
| throw new RuntimeEnvironmentStoreError( | ||
| 'invalid_argument', | ||
| 'SSH access operation cannot change the paired runtime identity.' | ||
| ) | ||
| } |
There was a problem hiding this comment.
After a link, the verified runtime id lives only in the sidecar while the persisted environment still has runtimeId: null. linkVerifiedRuntimeEnvironmentSshAccess deliberately allows that (existing.runtimeId === null, runtime-environment-ssh-access-store.ts:95), but this guard compares args.runtimeId against the persisted value at line 176 and throws once the overlay shows sshAccess. So the first post-link markEnvironmentUsed({ runtimeId }) rejects the very identity the link already verified — and on the request path that throw is observable, because markEnvironmentUsedFromResponse (runtime-environment-transport-routing.ts:257) runs before every RPC returns.
Technical details
# markEnvironmentUsed rejects learning the runtime id a linked environment already carries
## Affected sites
- `src/shared/runtime-environment-store.ts:176` — `runtimeIdChanged` compares to the persisted `environment.runtimeId` (still `null` after a link)
- `src/shared/runtime-environment-store.ts:186-193` — throws when the overlaid view has `sshAccess`/`pendingSshAccessOperation`
- `src/shared/runtime-environment-ssh-access-store.ts:94-130` — `linkVerifiedRuntimeEnvironmentSshAccess` allows `existing.runtimeId === null` and records `runtimeId` only in the sidecar
- `src/main/ipc/runtime-environment-transport-routing.ts:257` and `src/main/ipc/runtime-environment-support-routing.ts:106` — call `markEnvironmentUsed({ runtimeId })` on successful responses, unguarded
## Required outcome
- Learning a runtime id that the link already verified must not be treated as an identity change. The comparison needs to use the effective (overlaid) runtime id, or the link path must persist `runtimeId` before any response can trigger `markEnvironmentUsed`.
## Open questions for the human (optional)
- Is the persisted environment expected to already carry the runtime id before a link is created? The link path explicitly permits `null`, and `SidecarEntrySchema.runtimeId` is documented as outliving the link "like a learned runtimeId would", which suggests not.| if ( | ||
| entry.runtimeId !== undefined && | ||
| environment.runtimeId !== null && | ||
| environment.runtimeId !== entry.runtimeId | ||
| ) { | ||
| return base | ||
| } |
There was a problem hiding this comment.
overlayRuntimeEnvironmentSidecar treats a runtimeId disagreement as stale and returns base, but isCurrentEntry — used by readCurrentRuntimeEnvironmentSidecarEntry and the preservation loop in writeRuntimeEnvironmentSidecarEntry — does not consider runtimeId. A shipped build that writes a different runtimeId (a downgrade edit that leaves createdAt/pairingRevision/preferredEndpointId untouched) therefore hides the link from listEnvironments/resolveEnvironment while the sidecar still holds it, so the lifecycle guards miss it and a later link attempt throws.
Technical details
# overlay and isCurrentEntry disagree on runtimeId
## Affected sites
- `src/shared/runtime-environment-sidecar.ts:113-119` — overlay returns `base` on a `runtimeId` mismatch
- `src/shared/runtime-environment-sidecar.ts:87-97` — `isCurrentEntry` ignores `runtimeId` (and `endpoints`)
- `src/shared/runtime-environment-sidecar.ts:186-192` — `readCurrentRuntimeEnvironmentSidecarEntry` returns the raw entry, so `readAccessContext` (`runtime-environment-ssh-access-store.ts:248-250`) hands `commit` an entry the overlay already rejected
- `src/shared/runtime-environment-store.ts:76-85,100-102` — `assertNoIndependentSshAccess` reads the overlaid view, so removal/re-pair prune a link the overlay hid
- `src/shared/runtime-environment-ssh-access-store.ts:263-269` — a subsequent `prepare…Link` fails the presence check and throws `The SSH access state is inconsistent with this paired server.`
## Required outcome
- The fields that make an entry "current" must agree between the overlay and `isCurrentEntry`/`readCurrentRuntimeEnvironmentSidecarEntry`: either a rejected link is also rejected by every reader and pruned on the next write, or it stays visible to the lifecycle guards. Linking must not dead-end in the `commit` inconsistency throw.
## Suggested approach (optional)
- Fold `runtimeId` (and the endpoint preconditions the second refine relies on) into the staleness predicate, or route `readAccessContext`/`assertNoIndependentSshAccess` through the same overlay decision.…e sidecar (#16741 T5-1+T5-2) Paired runtime environments gain a durable two-phase SSH access link (prepare link, verified link, prepare unlink, complete unlink, cancel), plus the reconciliation record type and the runtime identity verification helper that T6 needs. Nothing calls the link store yet; T6's managed tunnel and runtime SSH access are its first writers. Why a sidecar: v1.4.217 and v1.4.218 parse orca-environments.json with plain z.object schemas, which strip unknown keys, and rewrite the whole file on routine use (markEnvironmentUsed). Storing the link there, as #16741 did, would let a downgraded build keep the tunnel endpoint but drop sshAccess, stranding the server unlinkable and losing its pinned host-key fingerprint. #16741's own answer (bumping the store version) makes those builds reject the whole file. So orca-environments.json keeps exactly its shipped shape (version 1, persisted fields only), and all T5 state lives in orca-environment-sidecar.json beside it: the link and its tunnel endpoint, the pending operation, the reconciliation record, the verified runtime id and a monotonic pairing-revision floor. Reads overlay the sidecar; each entry is bound to the environment's createdAt, pairing revision and preferred endpoint, so a re-pair, removal or edit by an older build makes it stale (ignored, pruned on the next sidecar write). An unreadable sidecar fails closed, like the main file. Porting note (source: #16741 a68b6f3): - Taken: the link-store behavior and messages, the access-link schemas and refinements, the reconciliation record, identity verification, and the store/schema tests. - Adapted: link state moved from orca-environments.json to the sidecar; existing mutators write persisted fields only; removal, re-pairing and runtime identity changes refuse while SSH access is linked or pending. - Left for later slices: orcadDeployment and restoreManagedOrcadEnvironmentLink (T6), reconciliation store, integrity, catalog and UI (T5-3 to T5-5), the 24 renderer terminal-input files (T7), runtime-identity and the managed-tunnel resolver (T6).
79045b3 to
b5bfbd9
Compare
* 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]>

This is T5 slices 1 and 2 of the #16741 port (runtime-environment reconciliation): durable SSH access links for paired servers, plus the reconciliation record and runtime identity check that T6's managed SSH deployment needs. Nothing calls the new store yet.
ELI5
Orca keeps a list of the servers you've paired with. Soon it will be able to reach a paired server through an SSH tunnel, and it has to remember that link reliably. It can't put the link in the existing list file: older Orca versions quietly drop fields they don't recognize whenever they save that file. So the link goes in a second file that older versions never open. Going back to an older version and then forward again leaves the link intact.
What Changed
Before: a paired server could only be reached directly or through a tunnel the user ran themselves. Nothing recorded a tunnel Orca manages.
After: user-visible behavior is unchanged. Underneath:
New link store:
runtime-environment-ssh-access-storeadds a two-phase link for a paired server:A failed verification becomes a durable unlink intent. Retrying a completion whose response was lost returns the same link instead of creating a second one.
New sidecar file:
orca-environment-sidecar.json, next toorca-environments.json, holds the link with its tunnel endpoint, any pending operation, the verified runtime id, a pairing-revision floor that never goes backwards, and a reconciliation record.Reads:
listEnvironmentsandresolveEnvironmentreturn each environment with its sidecar state merged in.Writes: existing writes to
orca-environments.jsononly ever write the fields shipped builds understand. Removing a server, re-pairing it, or changing its runtime identity is refused while SSH access is linked or pending.New helpers for T6: the reconciliation record type plus
assertRuntimeEnvironmentNotReconciling, andverifyRuntimeEnvironmentIdentity, which checks overstatus.getthat an endpoint is really the paired runtime.Why
The downgrade problem. The two latest stable releases, v1.4.217 and v1.4.218, read
orca-environments.jsonwith zodz.objectschemas, which strip unknown keys. They also rewrite the whole file on routine use, becausemarkEnvironmentUsedrecordslastUsedAt.sshAccess. The server would then point at a tunnel nobody owns, could not be unlinked, and would lose the SSH target and its pinned host-key fingerprint. A half-finished link or unlink would also be lost.How the sidecar handles it:
Compatibility rules. Older builds rewrite
orca-environments.jsonand strip keys they don't know, so all new state lives in a sidecar they never touch. Beyond that:status.get, with the client capabilities the desktop already sends.orca-environments.json, which the uninstaller already leaves in place. It isn't a new on-disk location, so no two-step uninstaller rollout is needed.Left out:
orcadDeployment), which is T6;runtime-identityand the managed-tunnel resolver, which are T6.Linked Issue
Part of the Node runtime plan, Phase 3, T5 slices 1 and 2. Ported from #16741 (a68b6f3). Unblocks T6's managed SSH deployment.
Visual Proof
N/A. Nothing calls the new store yet, so there's no UI or behavior change.
Testing
Link store (15 tests): link, unlink, retries, races with re-pairing, refusal of wrong grants or runtimes, refusal of duplicate runtime registrations, and refusal of removal or re-pairing while linked. A check that
orca-environments.jsonalways matches the shipped shape exactly replaces feat(orcad): consolidate Bun runtime and SSH/Remote migration #16741's version-bump assertions.Schema (17 tests): access-link refinements, redaction, and proof that the persisted envelope never carries sidecar state.
Downgrade (6 tests): a simulated v1.4.217/218 rewrite keeps the link; an older build's re-pair makes the link stale and the next write prunes it; a dangling entry for a removed server is ignored; removal is refused while linked; a corrupt sidecar fails closed; a reconciliation record merges in and blocks lifecycle changes.
Regression: every runtime-environment, pairing-verification, ephemeral-VM, web-preload and runtime-server test: 66 files, 457 passed.
The changed-code quality gate passes.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
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.Notes
orca-environments.jsonis unchanged on disk.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)