Skip to content

feat(ssh): deploy and pair an empty managed orcad server over SSH (#16741 T6-5) - #24453

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/node-rt-p3-t6-5
Oct 1, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/node-rt-p3-t6-5

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2472 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2438
Prod 37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2135 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2119

ELI5

Orca can already install orcad, its headless server, on a remote machine and activate it safely (T6-1 to T6-3). Nothing could yet turn an SSH host into a server you can open from the app. This PR adds that plumbing for empty hosts:

  • install orcad on the host;
  • pair this app with it through an SSH tunnel;
  • remember it as a server;
  • report its status.

It also lets an already-paired server be reached through SSH. Moving an existing SSH host's projects onto the new server (catalog migration) is not included.

Nothing in the UI calls this yet. The settings screens arrive in T6-6, so users see no change.

What Changed

Before: an orcad slot could be installed and activated over SSH, but nothing paired with it, tunneled to it, or saved it as a server.

After (main process only, reachable only through new IPC channels that no UI calls yet):

  • Deploy and pair (orcad-runtime-deployment.ts, through orcad-runtime-lifecycle.ts). The steps, in order:

    1. Claim the SSH target and flush the claim to disk before contacting the host.
    2. Reconcile any interrupted activation (T6-2).
    3. Run deployOrcad with the pinned-Node slot for the host's server target.
    4. Probe the active slot's readiness against the build hash this client holds.
    5. Open a loopback tunnel.
    6. Register the environment, using the server's pairing offer rewritten to ws://127.0.0.1:<tunnel port>.
    • An interrupted deploy resumes under the same environment id, because the target claim records it.
    • When a version is already active, the terminal census is passed as unknown, never zero, so deployOrcad defers instead of restarting over live terminals.
  • Status (orcad-runtime-status.ts). A read-only view of the host's activation record and any interrupted activate or rollback transaction. It repairs nothing.

  • Target claims (ssh-target-orcad-claims.ts, exposed as SshConnectionStore.getOrcadRuntimeClaims()):

    • A claim is refused while the target has any of these:
      • another owner;
      • repositories;
      • folder workspaces;
      • saved port forwards;
      • client state that still references it (ssh-target-orcad-dependents.ts):
        • a workspace session (the host's session partition, including sleeping or saved terminal tabs, or a local session whose active workspace is on that host);
        • an automation that runs on it;
        • worktree metadata recorded for it;
        • a saved PTY lease of any status.
    • The refusal names what blocked it, with a count and up to five names, so the user can clean it up.
    • If any of those stores can't be read, the claim is refused as unverifiable and the message names the store.
    • This is a conservative stand-in for T6-8's full census.
    • A claimed target is hidden from SSH settings and skipped by ~/.ssh/config sync.
    • ssh:updateTarget and ssh:removeTarget refuse a claimed target. The renderer can no longer write orcadProvisioning.
  • Owner marker (managed-orcad-ssh-owner.ts). The owner is {type: 'on-demand-runtime', runtimeId: 'managed-orcad:<id>'}, so shipped builds already keep the target hidden.

    • isEphemeralRuntimeSshOwner now feeds the host-key verifier. A managed host's key is pinned like any real host's; it is not treated as a throwaway VM.
  • Managed tunnel (orcad-managed-tunnel.ts, orcad-managed-tunnel-resume.ts, runtime-environment-managed-tunnel.ts):

    • Runtime calls, subscriptions and status probes for a server that depends on an SSH tunnel now ensure the tunnel first. A tunnel lost on reconnect is rebuilt on the next request, on the same local port.
    • On wake from sleep, each tunnel is probed (2 × 5s, the same policy as relay sessions). If the probe fails, the connection is reconnected and the forward rebuilt.
    • Every step is fenced on target generation, owner, pairing revision and transport generation.
  • SSH provisioning (orcad-ssh-provisioning.ts):

    • It creates a hidden target that carries a {requestId, name} intent and flushes it before deploying. It can then be resumed or listed as pending.
    • The intent is kept after success, so a retry after a lost response returns already-current.
    • If adding the host re-adopts old Orca projects, the host is no longer empty. It is restored as a visible direct-SSH host and nothing is deployed.
  • SSH access for a paired server (runtime-ssh-access.ts, runtime-ssh-access-verification.ts). These are the coordinator and IPC over feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2) #24420's sidecar store:

    1. Durable intent.
    2. Claim.
    3. Tunnel.
    4. Identity proof (verifyRuntimeEnvironmentIdentity).
    5. Link.

    Unlink goes in reverse.

  • Persistence:

    • orcadDeployment is a new field on KnownRuntimeEnvironmentSchema, stored only in orca-environment-sidecar.json.
    • addManagedOrcadEnvironment writes the sidecar first, then orca-environments.json. A crash between the two writes leaves an entry the next write prunes, never a server that has lost its link.
    • A managed server cannot be removed or re-paired through the generic environment calls.
  • IPC (registered in runtime-environments.ts):

    • deployOrcad, getOrcadStatus;
    • createOrcadSshHost, resumeOrcadSshHost, listPendingOrcadSshProvisioning;
    • linkSshAccess, unlinkSshAccess.

Why

  • Empty hosts only. Claiming a host that still has projects would hide them, and moving them is the catalog migration, which may become a follow-on. The claim preflight therefore refuses anything non-empty, folder workspaces included.
  • Sidecar, not orca-environments.json. Shipped builds (v1.4.217/218) parse that file with a key-stripping schema and rewrite it routinely, so a deployment link stored there would vanish after a downgrade. Tests simulate that rewrite.
  • The claim is the journal. In feat(orcad): consolidate Bun runtime and SSH/Remote migration #16741 the migration cutover journal recorded the resume point. Without catalog migration, the target's owner names the environment being created, so no extra journal is needed.
  • Cut from feat(orcad): consolidate Bun runtime and SSH/Remote migration #16741:
    • T8 cutover: the cutover coordinator, source cutover and manifest export imports. Deploy-and-pair is all that is left.
    • For a follow-up after T6-4: orcad-runtime-decommission and orcad-runtime-maintenance (update, rollback, recovery, stop, cancel-stop).
    • Other modules:
      • orcad-managed-migration-status (T6-8/T6-10);
      • orcad-outgoing-recovery-handlers (T8);
      • runtime-identity, whose consumers are T6-3's profile daemon startup and T7 PTY ownership, so it would be dead code here;
      • the draft orcad-runtime owner variant, which never shipped.
    • Re-derived for the pinned-Node slot:
      • The legacy host-Node fallback is an empty path, so a slot without its runtime marker fails to launch instead of borrowing the host's Node.
      • Readiness for a fresh activation is probed rather than read from the deploy result.

Wire compatibility

This PR adds no runtime RPC methods. Everything sent to the remote host runs as SSH commands against T6-1/T6-2's on-disk contracts. The only RPC calls are:

  • the tunnel liveness probe, status.get;
  • the existing T5 identity verification.

Both are methods every paired server already answers. An unanswered census is null, which makes deployOrcad defer; it is never read as zero.

Linked Issue

Part of #16741.

Visual Proof

N/A: no UI change. The new IPC channels have no renderer caller until T6-6.

Testing

  • New and ported vitest: deployment and status (13), target claims (12), dependent-state census (8), managed store and downgrade (6), managed tunnel (ported), runtime SSH access (24), provisioning, the IPC handlers, the CRUD guard, config-sync skip, and host-resume recovery.

  • Regression run over the SSH store, the connection, the runtime-environment IPC, the sidecar and the store tests: 94 files, 1042 passed, 1 skipped.

  • A scoped tsc over the changed files and their main-process importers (133 files) is clean. oxlint and the changed-code quality gate are clean.

  • POSIX hosts only: resolveOrcadRemoteContext refuses Windows hosts before any lifecycle step.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

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

  • SSH:
    • The execution host owns lifecycle state, and every remote verdict keeps live / unverifiable / exited.
    • SSH being unavailable on the client is reported as unverifiable.
  • Secrets: pairing tokens never appear in logs or errors. Results are redacted, and a test asserts the device token is absent from deploy results and tunnel calls.
  • Folder workspaces: a host with only folder workspaces is non-empty and refused, and so is a host that any saved session, automation, worktree metadata or terminal lease still references.

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)

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 2/5

[High risk] Adds SSH-based deployment and tunneling for managed runtime servers.

The PR does not appear safe to merge because upgrading a stopped native-chat queue can send a held message, and two previously reported deployment and provisioning defects remain.

Findings

  1. P1 Recorded version mistaken for readiness ▶
  2. P1 Folder workspaces remain hidden ▶
  3. P2 Tunnel setup silently succeeds ▶

Summary

This PR adds managed Orcad deployment and pairing over SSH. Changes since the previous review also add managed-stop and decommission recovery, Codex Interrupt hooks, and journal-derived native-chat queue pauses.

  • Existing persisted queue pauses need an upgrade path before the old pause table is ignored.
  • The three previous Greptile findings remain outstanding.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Previously saved queued card] --> B[Pause in queued_message_pauses]
  B --> C[Upgrade opens journal]
  C --> D[Derive pause from journal marks and card fields]
  D -->|Legacy pause absent| E[Card eligible for automatic send]
Loading

Reviews (2) · Last reviewed commit: "fix(ssh): keep electron out of the resum..."

Comment on lines +90 to +100
if (registered) {
environmentRegistered = true
await ensureOrcadManagedTunnel(userDataPath, registered.id)
const activeVersion = context.activationRecord.active
if (!activeVersion) {
throw new Error('The managed Orca server has no active runtime version.')
}
return {
outcome: 'already-current',
environment: redactRuntimeEnvironment(registered),
activeVersion

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recorded version mistaken for readiness

When deployment is retried for an already-registered server, this branch reports already-current if the activation record names a version. The service may have exited without leaving an interrupted activation transaction, and ensureOrcadManagedTunnel only opens a forward; it does not check whether Orcad is serving. The caller can therefore receive a successful result for an unreachable server. Check the active slot’s readiness before reporting it current.

Knowledge Base Used: Remote connectivity and execution

Comment on lines +71 to +80
const repoReadoptions = [...targetStore.lastRepoReadoptions]
targetStore.lastRepoReadoptions = []
for (const targetId of new Set(
repoReadoptions.flatMap(({ oldTargetId, newTargetId }) => [oldTargetId, newTargetId])
)) {
rotateSshProviderAuthority(targetId)
}
if (repoReadoptions.length > 0) {
// Why visible: re-adopted projects make the host non-empty; hiding it would hide them too.
targetStore.updateTarget(target.id, { orcadProvisioning: undefined })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Folder workspaces remain hidden

When a removed SSH host had a folder workspace but no repository row, re-adding it reassigns the workspace without adding anything to lastRepoReadoptions. This code then keeps the provisioning intent and attempts managed deployment. The folder workspace blocks the claim, but the host is not restored as a visible direct-SSH host, leaving its workspace hidden. Check for non-repository re-adoptions before choosing the managed path.

Knowledge Base Used: Remote connectivity and execution

Comment on lines +229 to +232
if (!stillOwned() || connection.getTransportGeneration() !== transportGeneration) {
await this.forwards.removeForwardAndWait(forward.id)
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tunnel setup silently succeeds

If SSH reconnects while the saved forward is being bound, this branch removes the new forward but lets ensure resolve successfully. A status probe or runtime call waiting on ensure then proceeds without an active tunnel and fails. Retry the binding on the new transport or report that setup was superseded, so callers do not mistake the tunnel for ready.

Knowledge Base Used: Remote runtime transport

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

Caution

The managed tunnel is created on an OS-assigned (ephemeral) local port, but the port recorded back is always 0. Both the deploy-and-pair flow and the link-SSH-access flow validate that recorded port and reject their own tunnel, so the feature cannot complete a pairing as written. Details inline.

Reviewed changes

  • Deploy and pair — new orcad-runtime-deployment.ts, orcad-runtime-status.ts, orcad-runtime-lifecycle.ts, orcad-managed-runtime-context.ts, orcad-tunneled-pairing.ts: claim the SSH target durably, reconcile, deploy the pinned-Node orcad slot, probe readiness, open a loopback tunnel, register the environment.
  • Target claims — ssh-target-orcad-claims.ts, ssh-target-orcad-dependents.ts, managed-orcad-ssh-owner.ts: exclusive ownership; claimed/provisioning targets hidden from SSH settings and refused by ssh:updateTarget/ssh:removeTarget; isRuntimeOwnedSshTarget widened to include orcadProvisioning.
  • Managed tunnel — orcad-managed-tunnel.ts + orcad-managed-tunnel-resume.ts: ensure/rebuild a forward fenced on manager, ownership and transport generations, target generation, owner and pairing revision; recovered on host resume.
  • SSH access for a paired server — runtime-ssh-access.ts, runtime-ssh-access-verification.ts: intent → claim → tunnel → identity proof → publish, and the reverse for unlink.
  • Provisioning — orcad-ssh-provisioning.ts: durable {requestId,name} intent on a hidden target, resumable and listable.
  • Persistence & IPC — orcadDeployment stored only in the sidecar; addManagedOrcadEnvironment writes sidecar before orca-environments.json; new runtimeEnvironments:* channels registered.
Technical details
# Managed tunnel records local port 0 for its ephemeral bind

## Affected sites
- `src/main/ssh/orcad-managed-tunnel.ts:97-104` — `addForward(target.id, connection, 0, ..., remotePort, ...)`, then `:112` stores `forward.localPort`.
- `src/main/ssh/ssh2-port-forward-provider.ts:57` — `entry.localPort: options.localPort` (the `net.Server.listen(0)` result is never read).
- `src/main/ssh/system-ssh-port-forward-provider.ts:45` — same echo.

## Required outcome
`start` must return the actual bound port. Either the providers report `server.address().port` when `options.localPort === 0`, or the manager pre-selects a free loopback port and passes it explicitly (as `assertLocalForwardPortAvailable` already does for the system-ssh path).

## Suggested approach (optional)
Resolve the ephemeral port inside the providers and build the entry from it, then have the existing `forward.localPort !== deployment.localPort` fences in `ensureManagedTunnel`/`reconnectAndRebuild` compare the real value. A regression test should assert the value `start` returns for a `0` request, not just that a forward was opened.

## Open questions for the human (optional)
Is `0` intended to mean "any free port" on the system-ssh provider? OpenSSH only supports `-L 0:...` on recent versions, and `waitForSystemSshForwardStartup` probes `connect(..., port: 0)`, which never succeeds — so that transport likely needs an explicit chosen port too.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

const forward = await this.forwards.addForward(
target.id,
connection,
0,

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.

start requests an ephemeral port by passing 0 here, then returns forward.localPort (:112/:118). But both port-forward providers copy the requested options.localPort into the entry (ssh2-port-forward-provider.ts:57, system-ssh-port-forward-provider.ts:45) rather than the port net.Server.listen(0) actually bound, so start returns 0.

Downstream that is fatal: tunneledOrcadPairingCode produces an endpoint ending in :0, and addManagedOrcadEnvironment rejects it because getPreferredLoopbackRuntimePort requires port >= 1; the link flow rejects earlier still at verifyRuntimeEnvironmentSshTunnel (localPort < 1). The unit tests mask it because addForward is mocked to echo/return 46768. Every deploy and link therefore fails at the pairing step.

Technical details
# Managed tunnel records local port 0 for its ephemeral bind

## Affected sites
- `src/main/ssh/orcad-managed-tunnel.ts:97-104` — `addForward(..., 0, ...)`, then `:112` stores `forward.localPort`.
- `src/main/ssh/ssh2-port-forward-provider.ts:57` — `entry.localPort: options.localPort` (the `listen(0)` result is never read).
- `src/main/ssh/system-ssh-port-forward-provider.ts:45` — same echo.

## Required outcome
`start` must return the actual bound port. Either the providers report `server.address().port` when `options.localPort === 0`, or the manager pre-selects a free loopback port and passes it explicitly (as `assertLocalForwardPortAvailable` already does for system ssh).

## Suggested approach (optional)
Build the provider entry from the resolved port, then let the existing `forward.localPort !== deployment.localPort` fences in `ensureManagedTunnel`/`reconnectAndRebuild` compare the real value. Add a test asserting the value `start` returns for a `0` request, not merely that a forward was opened.

Comment on lines +148 to +156
const prepared = prepareRuntimeEnvironmentSshAccessLink(userDataPath, {
expectedEnvironment: environment,
requestId: args.requestId,
remotePort: args.remotePort,
...fence
})
await claims.flush()
requireAccessOnlyTarget(claims, target.id, environmentId)
requireFence(claims, environmentId, fence, true)

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.

The durable link intent (with targetFingerprint) is written at :148-153, before the await claims.flush() at :154 and claims.claim at :157. During that window the target is still unowned, and ssh:updateTarget is not serialized or blocked for it (only runtime-owned targets are refused), so a concurrent edit (or a passive ~/.ssh/config re-import of a config-sourced target) changes the fingerprint. The requireFence at :156 then throws, leaving the intent on disk.

Once the fingerprint has moved there is no escape hatch: a link retry fails requireMatchingIntent ("Another SSH access operation is pending."), a unlink retry fails requireFence on the stale fingerprint (:222/:235/:240), and environment removal/re-pair is blocked by assertNoIndependentSshAccess — the server is stuck until the target config is reverted to the exact old fingerprint. The unlink path has the same shape after release clears ownership and await claims.flush() at :239 yields.

Technical details
# A target-fingerprint change strands the pending SSH-access intent

## Affected sites
- `src/main/ssh/runtime-ssh-access.ts:148-156` — link intent persisted before claim; a post-persist fence throw leaves it behind.
- `src/main/ssh/runtime-ssh-access.ts:235-240` — unlink releases ownership, then flushes; a concurrent edit strands the pending `unlink` with the owner already cleared.
- `src/main/ssh/ssh-target-crud-handlers.ts:51-55` / `ssh-connection-store.ts:262-264` — target stays editable while unowned.
- `src/shared/runtime-environment-store.ts:231-238` — removal/re-pair refused while `pendingSshAccessOperation` exists.

## Required outcome
A fingerprint change (or any failure before remote contact) must not leave an intent that no operation can clear. Either validate the fingerprint immediately before persisting, roll the pending intent back when a fence fails before `claims.claim`/any tunnel work, or make unlink-cancellation validate the intent's identity without requiring the stale fingerprint to still match.

## Open questions for the human (optional)
Is the link target expected to already be runtime-owned by the time `linkRuntimeSshAccess` runs? Requiring ownership up front, or serializing `ssh:updateTarget` through `runTargetLifecycle(targetId)`, would close the window more simply than a rollback path.

@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 new issues in this delta.

Reviewed changes

  • Dependent-state census — new src/main/ssh/ssh-target-orcad-dependents.ts (collectDependentStateBlockers): a claim is now refused when any saved client state still references the host — its workspace-session partition (or a local session whose active workspace is on it), an automation targeting it, worktree metadata, or a saved PTY lease of any status (terminated/expired included). An unreadable store downgrades to orcad_migration_dependency_unverifiable and names the store. SshTargetOrcadClaims drops its previous live-only lease filter and delegates to this census; OrcadMigrationDependency.names (bounded to 5) and the new blocker variant are added to orcad-migration-preflight.ts.
  • Tests — new ssh-target-orcad-dependents.test.ts and updated claim/deploy/ownership fixtures; the deploy test asserting a leased host is refused before connect/claim.

The census logic holds up: readers are isolated per store with fail-closed error handling, workspaceSessionReferences compares against the default session so an untouched partition reads empty, and names are capped without dropping the count. This commit does not touch the two findings from the prior review, which remain outstanding.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

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: c4dc383c-19ca-4aa1-9400-071439688c19

📥 Commits

Reviewing files that changed from the base of the PR and between 2f8467a and fd65dc8.

📒 Files selected for processing (6)
  • src/main/ipc/ssh-host-sleep-reconnect.test.ts
  • src/main/ipc/ssh-host-sleep-reconnect.ts
  • src/main/ipc/ssh.ts
  • src/main/ssh/orcad-runtime-deployment.test.ts
  • src/main/ssh/orcad-runtime-status.ts
  • src/shared/orcad-managed-runtime.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change adds managed Orcad SSH provisioning, deployment, and status operations. It adds SSH target ownership claims, runtime SSH access linking and verification, and managed tunnel setup and host-resume recovery. Environment schemas and sidecar persistence now support Orcad deployment links. IPC handlers expose these operations and validate their inputs.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to fd65d

Resolve or explicitly accept the remaining retry and main-thread I/O concerns before merging: retries after host re-adoption can fail, and repeated synchronous store reads on runtime calls can affect responsiveness. The resume callback concern does not require a change.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to fd65d

The deployment flow includes strong ownership checks, durable recovery state, and loopback-only tunneling. The remaining material uncertainty is whether interrupted deployments stay isolated from ordinary SSH operations throughout retries and concurrent activity. No exploitable security vulnerability was established, and the new deployment operations are not exposed by the inspected renderer bridge.

Retained concerns

  • Medium · reliability · inferred: Exclusive ownership remains incompletely established across interrupted deployment retries. Same-owner preflight skips current dependency blockers, and ordinary SSH connection admission still resolves the target by ID. If a stale or concurrent direct caller can complete after the claim, retry could register the managed server while unmigrated direct dependencies remain. Target hiding and edit/removal restrictions are countercontrols, but downstream rejection of such writers was not verified. This is an inferred ownership and failure-containment concern, not a verified exploit.
Security review details

Security Blast Radius

  • inferred — A deployment operation acts on its selected SSH registration and remote account, while persisting ownership and pairing state in the client profile. A caller able to invoke the new privileged handlers can select other registered targets, subject to claim and dependency checks. Evidence does not establish broader tenant, fleet, IAM, or cloud-secret authority.

Trust Boundaries and Controls

  • observed — Remote readiness supplies the initial pairing offer. The client checks readiness against the local build, rejects non-loopback pairing endpoints, and verifies that persisted pairing points at its tunnel. These controls bind deployment and transport configuration; they are not independent proof against a compromised SSH host.
  • observed — The new IPC handlers validate arguments but do not inspect sender identity. Effective untrusted-renderer reachability remains unestablished: the inspected preload bridge omits these methods, and the main window enables sandboxing. No sender-authorization vulnerability is asserted from handler-local absence alone.

Resilience and Maintainability Implications

  • observed — Tunnel establishment rechecks ownership, pairing revision, target generation, and transport generation around asynchronous work. Superseded or incorrectly bound forwards are removed. Resume recovery similarly fences target ownership and removes a newly opened forward when its state has become stale.

Hardening Proposals

  • proposed — Make exclusive ownership explicit at ordinary SSH connection and dependency-write admission. For an interrupted claim whose environment is not yet registered, consider revalidating direct dependencies before deployment resumes, while retaining idempotent ownership identity.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.66% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 79 functions across 50 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 identifies the primary change: deploying and pairing an empty managed Orcad server over SSH.
Description check ✅ Passed The description is detailed and covers the required sections, including the user impact, changes, rationale, linked issue, visual proof, testing, scope, security, and compatibility notes. Manual testi…
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
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c1a4edee-fbb7-4f9c-a497-115409263f89

📥 Commits

Reviewing files that changed from the base of the PR and between 477e699 and 2f8467a.

📒 Files selected for processing (55)
  • src/main/ipc/orcad-runtime-lifecycle-handlers.test.ts
  • src/main/ipc/orcad-runtime-lifecycle-handlers.ts
  • src/main/ipc/orcad-ssh-provisioning-handlers.test.ts
  • src/main/ipc/orcad-ssh-provisioning-handlers.ts
  • src/main/ipc/runtime-environment-handler-channels.ts
  • src/main/ipc/runtime-environment-managed-tunnel.ts
  • src/main/ipc/runtime-environment-status-owner.ts
  • src/main/ipc/runtime-environment-transport-routing.ts
  • src/main/ipc/runtime-environments-pairing.test.ts
  • src/main/ipc/runtime-environments.ts
  • src/main/ipc/runtime-ssh-access-handlers.test.ts
  • src/main/ipc/runtime-ssh-access-handlers.ts
  • src/main/ipc/ssh-host-sleep-reconnect.test.ts
  • src/main/ipc/ssh-host-sleep-reconnect.ts
  • src/main/ipc/ssh-target-crud-handlers-ownership.test.ts
  • src/main/ipc/ssh-target-crud-handlers.ts
  • src/main/ipc/ssh.ts
  • src/main/ssh/orcad-managed-runtime-context.ts
  • src/main/ssh/orcad-managed-tunnel-resume.ts
  • src/main/ssh/orcad-managed-tunnel.test.ts
  • src/main/ssh/orcad-managed-tunnel.ts
  • src/main/ssh/orcad-runtime-deployment.test.ts
  • src/main/ssh/orcad-runtime-deployment.ts
  • src/main/ssh/orcad-runtime-lifecycle.ts
  • src/main/ssh/orcad-runtime-status.ts
  • src/main/ssh/orcad-ssh-provisioning.test.ts
  • src/main/ssh/orcad-ssh-provisioning.ts
  • src/main/ssh/orcad-tunneled-pairing.test.ts
  • src/main/ssh/orcad-tunneled-pairing.ts
  • src/main/ssh/runtime-ssh-access-verification.test.ts
  • src/main/ssh/runtime-ssh-access-verification.ts
  • src/main/ssh/runtime-ssh-access.test.ts
  • src/main/ssh/runtime-ssh-access.ts
  • src/main/ssh/ssh-connection-store-orcad-ownership.test.ts
  • src/main/ssh/ssh-connection-store.ts
  • src/main/ssh/ssh-connection.ts
  • src/main/ssh/ssh-target-orcad-claims.test.ts
  • src/main/ssh/ssh-target-orcad-claims.ts
  • src/main/ssh/ssh-target-orcad-dependents-fixture.ts
  • src/main/ssh/ssh-target-orcad-dependents.test.ts
  • src/main/ssh/ssh-target-orcad-dependents.ts
  • src/shared/managed-orcad-ssh-owner.test.ts
  • src/shared/managed-orcad-ssh-owner.ts
  • src/shared/orcad-managed-runtime.ts
  • src/shared/orcad-migration-preflight.ts
  • src/shared/orcad-ssh-provisioning.ts
  • src/shared/runtime-environment-managed-orcad-store.test.ts
  • src/shared/runtime-environment-managed-orcad-store.ts
  • src/shared/runtime-environment-shipped-store-fixture.ts
  • src/shared/runtime-environment-sidecar.test.ts
  • src/shared/runtime-environment-sidecar.ts
  • src/shared/runtime-environment-store.ts
  • src/shared/runtime-environments.ts
  • src/shared/runtime-ssh-access.ts
  • src/shared/ssh-types.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment on lines +4 to +11
export async function resolveManagedRuntimeEnvironment(
userDataPath: string,
selector: string
): Promise<ReturnType<typeof resolveEnvironment>> {
const environment = resolveEnvironment(userDataPath, selector)
await ensureOrcadManagedTunnel(userDataPath, environment.id)
return resolveEnvironment(userDataPath, environment.id)
}

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.

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Return early for environments without SSH access. This removes extra store reads from every RPC.

callRuntimeEnvironment now calls resolveManagedRuntimeEnvironment for every queued call. That includes terminal.send and terminal.updateViewport, which run on each keystroke or resize. For every environment, this helper now does three synchronous reads of the environment store and sidecar:

  • Line 8.
  • The read inside ensureOrcadManagedTunnel.
  • Line 10.

Before this change, the call path did one read. For an environment with no orcadDeployment or sshAccess, managedTunnels.ensure returns immediately. The second and third reads therefore do no useful work. These reads run on the Electron main process thread.

Fix: check getRuntimeSshAccess on the first resolved environment and return it when no tunnel is needed. Tunneled environments still pay for the connect() and stillOwned() reads on each call. A later change could add a cached fast path that matches the active tunnel.

⚡ Proposed fix
+import { getRuntimeSshAccess } from '../../shared/runtime-environments'
 import { resolveEnvironment } from '../../shared/runtime-environment-store'
 import { ensureOrcadManagedTunnel } from '../ssh/orcad-managed-tunnel'
 
 export async function resolveManagedRuntimeEnvironment(
   userDataPath: string,
   selector: string
 ): Promise<ReturnType<typeof resolveEnvironment>> {
   const environment = resolveEnvironment(userDataPath, selector)
+  if (!getRuntimeSshAccess(environment)) {
+    return environment
+  }
   await ensureOrcadManagedTunnel(userDataPath, environment.id)
   return resolveEnvironment(userDataPath, environment.id)
 }

if (existing.orcadProvisioning?.name !== name || !matchesRequest(existing, targetInput)) {
throw new Error('This provisioning request already belongs to another host or server name.')
}
return provision(userDataPath, existing, [])

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

An exact retry fails after the first attempt finished.

When a request already exists, createOrcadSshHost calls provision again. Line 61 does this even after the server is registered. provision then runs createManagedOrcadEnvironment again. That call takes the registered branch, which ensures the tunnel and returns already-current. This path works.

resumeOrcadSshHost has a different problem. A request can lose its orcadProvisioning intent through the updateTarget(..., { orcadProvisioning: undefined }) path on line 80, which runs for re-adopted repositories. After that, a retry with the same requestId cannot find the target. createOrcadSshHost then reaches sameEndpoint and throws 'already registered' instead of returning the earlier pending result. As a result, an exact retry after a re-adoption outcome is not idempotent.

The doc comment on line 27 says that a completed request "keeps its intent for idempotent retries". The re-adoption branch breaks this contract. Choose one of these fixes:

  • Keep the intent and mark it as not deployable.
  • Document that a retry after re-adoption is expected to fail.

m4air and others added 3 commits October 1, 2026 13:41
…6741 T6-5)

Adds deploy + pair + status for a managed orcad environment on an empty SSH
host, the loopback tunnel it is reached through (rebuilt on reconnect and
after host resume), SSH provisioning of a new host, and SSH access for an
already paired server. The deployment link lives in the environment sidecar
so a downgraded build cannot strip it. Inert until the T6-6 settings UI.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…he host

Until the T6-8 census exists, a target is claimable only when no workspace
session, automation, worktree metadata or saved PTY lease (any status) points
at it. An unreadable store refuses as unverifiable. Refusals name what
blocked them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… journal in status

The caller now passes the profile path for managed-tunnel recovery after host
resume, so ssh-host-sleep-reconnect no longer reads electron's app. Status maps
T6-4's decommission transaction.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@OrcaWin
OrcaWin force-pushed the OrcaWin/node-rt-p3-t6-5 branch from 2f8467a to fd65dc8 Compare October 1, 2026 20:44

@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 new issues in this delta.

Reviewed changes

  • Managed-tunnel recovery no longer reads Electron directly — registerPowerMonitorReconnect now takes an optional getUserDataPath thunk, and ssh.ts supplies getAppEnvironment().getPath('userData'). ElectronAppEnvironment forwards getPath to app.getPath (src/main/host/electron-app-environment.ts:10), so the path the resume handler uses is unchanged; only the injection seam is new.
  • Decommission journal surfaced in status — getManagedOrcadRuntimeStatus now maps an interrupted decommission transaction (prepared / stop-dispatched / process-exited) into recovery, alongside activate and rollback, with the matching OrcadManagedRuntimeStatus.recovery variant. The read remains non-repairing; readOrcadActivationTransaction still throws on an unreadable journal rather than reporting it.

Both changes carry tests (a resume case for the injected path and a status case for the decommission journal), and neither touches the two findings still open from the previous review — the ephemeral-local-port-0 tunnel bind and the stranded pending SSH-access intent remain outstanding.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit 8b76683 into main Oct 1, 2026
61 checks passed
OrcaWin added a commit that referenced this pull request Oct 2, 2026
* 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]>
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.

1 participant