Repository navigation
fix(vm): a recipe VM's SSH root runs on a managed Orca server - #27366
Conversation
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to Removing a recipe-VM project can delete the project from Orca while the VM keeps running. This can happen when the server catalog is stale, or when cleanup finds no matching runtime. Orphaned VMs keep consuming resources, so the removal paths should be fixed before merging. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f3ed9e66-331d-4149-bc6d-dd66a222082b
📥 Commits
Reviewing files that changed from the base of the PR and between cf36928 and 654af0f744a34273842e514d3409484f4e121516.
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (36)
src/main/ephemeral-vm-runtime-environment-release.test.tssrc/main/ephemeral-vm-runtime-environment-release.tssrc/main/ephemeral-vm-runtime-ssh.test.tssrc/main/ephemeral-vm-runtime-ssh.tssrc/main/ipc/ephemeral-vm-managed-ssh.test.tssrc/main/ipc/ephemeral-vm-runtime-handlers.tssrc/main/ipc/ephemeral-vm.tssrc/main/ipc/ssh-host-server-on-connect-wiring.tssrc/main/provisioned-root-checkout.tssrc/main/provisioned-root-ssh-adoption.tssrc/main/runtime/orca-runtime-create-managed-remote-worktree.tssrc/main/runtime/rpc/methods/worktree-provisioned-root-method.tssrc/main/runtime/rpc/methods/worktree.tssrc/main/runtime/runtime-provisioned-root-adoption.test.tssrc/main/runtime/runtime-provisioned-root-adoption.tssrc/main/ssh/ssh-target-orcad-claims.test.tssrc/main/ssh/ssh-target-orcad-claims.tssrc/preload/api/ephemeral-vm-api.tssrc/renderer/src/components/sidebar/RemoveFolderDialog.test.tsxsrc/renderer/src/components/sidebar/RemoveFolderDialog.tsxsrc/renderer/src/lib/ephemeral-vm-workspace-target.test.tssrc/renderer/src/lib/ephemeral-vm-workspace-target.tssrc/renderer/src/lib/recipe-vm-managed-host.test.tssrc/renderer/src/lib/recipe-vm-managed-host.tssrc/renderer/src/store/repos/recipe-vm-project-removal.tssrc/renderer/src/store/repos/repo-removal.tssrc/renderer/src/store/slices/repos-ephemeral-vm-cleanup-retention.test.tssrc/renderer/src/store/slices/worktrees/create/create-worktree.tssrc/renderer/src/store/slices/worktrees/create/runtime-provisioned-root-adoption.test.tssrc/renderer/src/store/slices/worktrees/create/runtime-provisioned-root-adoption.tssrc/renderer/src/store/slices/worktrees/create/worktree-create-payload.tssrc/shared/managed-orcad-ssh-owner.test.tssrc/shared/managed-orcad-ssh-owner.tssrc/shared/protocol-version.tssrc/shared/rpc-contract/worktree-provisioned-root-params.tstests/e2e/ssh-orcad-vm-provisioned-root.spec.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.
| import { z } from 'zod' | ||
| import { OptionalString } from './rpc-param-primitives' | ||
| import { WorktreeCreate } from './worktree-create-params' | ||
|
|
||
| const create = WorktreeCreate.shape | ||
|
|
||
| /** A recipe's provisioned project root, adopted on its host as the main worktree's workspace. */ | ||
| export const WorktreeAdoptProvisionedRoot = z.object({ | ||
| repo: create.repo, | ||
| nameWasGenerated: create.nameWasGenerated, | ||
| displayName: create.displayName, | ||
| displayNameKind: create.displayNameKind, | ||
| baseBranch: create.baseBranch, | ||
| compareBaseRef: create.compareBaseRef, | ||
| branchNameOverride: create.branchNameOverride, | ||
| sparseCheckout: create.sparseCheckout, | ||
| linkedIssue: create.linkedIssue, | ||
| linkedPR: create.linkedPR, | ||
| linkedLinearIssue: create.linkedLinearIssue, | ||
| linkedLinearIssueWorkspaceId: create.linkedLinearIssueWorkspaceId, | ||
| linkedLinearIssueOrganizationUrlKey: create.linkedLinearIssueOrganizationUrlKey, | ||
| linkedGitLabMR: create.linkedGitLabMR, | ||
| linkedGitLabIssue: create.linkedGitLabIssue, | ||
| linkedBitbucketPR: create.linkedBitbucketPR, | ||
| linkedAzureDevOpsPR: create.linkedAzureDevOpsPR, | ||
| linkedGiteaPR: create.linkedGiteaPR, | ||
| linkedWorkItem: create.linkedWorkItem, | ||
| linkedItems: create.linkedItems, | ||
| linkedTaskSourceContext: create.linkedTaskSourceContext, | ||
| workspaceStatus: create.workspaceStatus, | ||
| manualOrder: create.manualOrder, | ||
| pushTarget: create.pushTarget, | ||
| createdWithAgent: create.createdWithAgent, | ||
| name: z.string().min(1, 'Missing workspace name'), | ||
| expectedPath: z.string().min(1, 'Missing provisioned project root'), | ||
| expectedRefHead: OptionalString | ||
| }) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
rg -n 'pendingFirstAgentMessageRename' src/shared/rpc-contract/worktree-create-params.ts src/renderer/src/store/slices/worktrees/create/worktree-create-payload.tsRepository: stablyai/orca
Length of output: 438
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- target schema ---'
nl -ba src/shared/rpc-contract/worktree-provisioned-root-params.ts
printf '%s\n' '--- all relevant references ---'
rg -n -F --glob '*.{ts,tsx}' -- 'pendingFirstAgentMessageRename' src || true
printf '%s\n' '--- provisioned-root symbols ---'
rg -n -F --glob '*.{ts,tsx}' -- 'ProvisionedRootRequest' src || true
rg -n -F --glob '*.{ts,tsx}' -- 'buildProvisionedRootMeta' src || true
rg -n -F --glob '*.{ts,tsx}' -- 'WorktreeAdoptProvisionedRoot' src || true
printf '%s\n' '--- worktree create schema ---'
nl -ba src/shared/rpc-contract/worktree-create-params.ts
printf '%s\n' '--- payload context ---'
nl -ba src/renderer/src/store/slices/worktrees/create/worktree-create-payload.ts | sed -n '45,80p'Repository: stablyai/orca
Length of output: 25231
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- provisioned root checkout ---'
nl -ba src/main/provisioned-root-checkout.ts | sed -n '1,175p'
printf '%s\n' '--- runtime adoption ---'
nl -ba src/main/runtime/runtime-provisioned-root-adoption.ts
printf '%s\n' '--- RPC method ---'
nl -ba src/main/runtime/rpc/methods/worktree-provisioned-root-method.ts
printf '%s\n' '--- callers ---'
nl -ba src/main/runtime/orca-runtime-create-managed-remote-worktree.ts | sed -n '160,215p'
nl -ba src/main/provisioned-root-ssh-adoption.ts | sed -n '70,115p'Repository: stablyai/orca
Length of output: 17479
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- adoption RPC call sites ---'
rg -n -F --glob '*.{ts,tsx}' -- 'worktree.adoptProvisionedRoot' src || true
rg -n -F --glob '*.{ts,tsx}' -- 'adoptProvisionedRoot' src || true
printf '%s\n' '--- provisioned-root create options and request construction ---'
nl -ba src/renderer/src/lib/provisioned-root-create-options.ts 2>/dev/null || true
rg -n -F --glob '*.{ts,tsx}' -- 'pendingFirstAgentMessageRename' src/main/runtime src/main/provisioned-root-checkout.ts src/renderer/src/lib | head -80
printf '%s\n' '--- first-agent rename consumer ---'
nl -ba src/main/agent-hooks/first-work-rename-runtime.ts 2>/dev/null || trueRepository: stablyai/orca
Length of output: 14778
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- create-worktree adoption request ---'
nl -ba src/renderer/src/store/slices/worktrees/create/create-worktree.ts | sed -n '35,90p'
printf '%s\n' '--- runtime adoption RPC helper ---'
nl -ba src/renderer/src/store/slices/worktrees/create/runtime-provisioned-root-adoption.ts
printf '%s\n' '--- adoption argument type ---'
nl -ba src/preload/api/worktree-api.ts | sed -n '45,85p'
printf '%s\n' '--- create argument type ---'
nl -ba src/shared/worktree/create-types.ts | sed -n '110,150p'Repository: stablyai/orca
Length of output: 9123
🏁 Script executed:
#!/bin/bash
set -e
nl -ba src/renderer/src/store/slices/worktrees/create/worktree-create-payload.ts | sed -n '80,150p'
rg -n -F --glob '*.{ts,tsx}' -- 'type AdoptProvisionedRootArgs' srcRepository: stablyai/orca
Length of output: 3164
Preserve pendingFirstAgentMessageRename in runtime adoption.
sharedCreateFields sends this field to worktree.adoptProvisionedRoot, but WorktreeAdoptProvisionedRoot strips it before buildProvisionedRootMeta stores the worktree metadata. The first-agent rename hook then does not detect the pending rename.
Proposed fix
createdWithAgent: create.createdWithAgent,
+ pendingFirstAgentMessageRename: z.boolean().optional(),
name: z.string().min(1, 'Missing workspace name'),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { z } from 'zod' | |
| import { OptionalString } from './rpc-param-primitives' | |
| import { WorktreeCreate } from './worktree-create-params' | |
| const create = WorktreeCreate.shape | |
| /** A recipe's provisioned project root, adopted on its host as the main worktree's workspace. */ | |
| export const WorktreeAdoptProvisionedRoot = z.object({ | |
| repo: create.repo, | |
| nameWasGenerated: create.nameWasGenerated, | |
| displayName: create.displayName, | |
| displayNameKind: create.displayNameKind, | |
| baseBranch: create.baseBranch, | |
| compareBaseRef: create.compareBaseRef, | |
| branchNameOverride: create.branchNameOverride, | |
| sparseCheckout: create.sparseCheckout, | |
| linkedIssue: create.linkedIssue, | |
| linkedPR: create.linkedPR, | |
| linkedLinearIssue: create.linkedLinearIssue, | |
| linkedLinearIssueWorkspaceId: create.linkedLinearIssueWorkspaceId, | |
| linkedLinearIssueOrganizationUrlKey: create.linkedLinearIssueOrganizationUrlKey, | |
| linkedGitLabMR: create.linkedGitLabMR, | |
| linkedGitLabIssue: create.linkedGitLabIssue, | |
| linkedBitbucketPR: create.linkedBitbucketPR, | |
| linkedAzureDevOpsPR: create.linkedAzureDevOpsPR, | |
| linkedGiteaPR: create.linkedGiteaPR, | |
| linkedWorkItem: create.linkedWorkItem, | |
| linkedItems: create.linkedItems, | |
| linkedTaskSourceContext: create.linkedTaskSourceContext, | |
| workspaceStatus: create.workspaceStatus, | |
| manualOrder: create.manualOrder, | |
| pushTarget: create.pushTarget, | |
| createdWithAgent: create.createdWithAgent, | |
| name: z.string().min(1, 'Missing workspace name'), | |
| expectedPath: z.string().min(1, 'Missing provisioned project root'), | |
| expectedRefHead: OptionalString | |
| }) | |
| import { z } from 'zod' | |
| import { OptionalString } from './rpc-param-primitives' | |
| import { WorktreeCreate } from './worktree-create-params' | |
| const create = WorktreeCreate.shape | |
| /** A recipe's provisioned project root, adopted on its host as the main worktree's workspace. */ | |
| export const WorktreeAdoptProvisionedRoot = z.object({ | |
| repo: create.repo, | |
| nameWasGenerated: create.nameWasGenerated, | |
| displayName: create.displayName, | |
| displayNameKind: create.displayNameKind, | |
| baseBranch: create.baseBranch, | |
| compareBaseRef: create.compareBaseRef, | |
| branchNameOverride: create.branchNameOverride, | |
| sparseCheckout: create.sparseCheckout, | |
| linkedIssue: create.linkedIssue, | |
| linkedPR: create.linkedPR, | |
| linkedLinearIssue: create.linkedLinearIssue, | |
| linkedLinearIssueWorkspaceId: create.linkedLinearIssueWorkspaceId, | |
| linkedLinearIssueOrganizationUrlKey: create.linkedLinearIssueOrganizationUrlKey, | |
| linkedGitLabMR: create.linkedGitLabMR, | |
| linkedGitLabIssue: create.linkedGitLabIssue, | |
| linkedBitbucketPR: create.linkedBitbucketPR, | |
| linkedAzureDevOpsPR: create.linkedAzureDevOpsPR, | |
| linkedGiteaPR: create.linkedGiteaPR, | |
| linkedWorkItem: create.linkedWorkItem, | |
| linkedItems: create.linkedItems, | |
| linkedTaskSourceContext: create.linkedTaskSourceContext, | |
| workspaceStatus: create.workspaceStatus, | |
| manualOrder: create.manualOrder, | |
| pushTarget: create.pushTarget, | |
| createdWithAgent: create.createdWithAgent, | |
| pendingFirstAgentMessageRename: z.boolean().optional(), | |
| name: z.string().min(1, 'Missing workspace name'), | |
| expectedPath: z.string().min(1, 'Missing provisioned project root'), | |
| expectedRefHead: OptionalString | |
| }) |
A recipe VM's hidden SSH target was counted as owned by another runtime, so every connect refused to deploy a managed server and fell back to the relay. Its runtime owner only records when the VM is created and destroyed, so it no longer blocks the deploy. The VM's workspace then lives on that server: the server adopts the provisioned root as its main worktree, and removing the project destroys the VM and forgets its server.
654af0f to
6d273cd
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7a710041-9ce4-4250-8240-2499a9e66068
📥 Commits
Reviewing files that changed from the base of the PR and between 654af0f744a34273842e514d3409484f4e121516 and 6d273cd.
⛔ Files ignored due to path filters (1)
src/shared/rpc-contract/rpc-params-catalog.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing (7)
src/renderer/src/components/sidebar/RemoveFolderDialog.test.tsxsrc/renderer/src/components/sidebar/RemoveFolderDialog.tsxsrc/renderer/src/lib/ephemeral-vm-worktree-creation.tssrc/renderer/src/store/repos/recipe-vm-project-removal.tssrc/renderer/src/store/repos/repo-removal.tssrc/renderer/src/store/slices/repos-ephemeral-vm-cleanup-retention.test.tssrc/renderer/src/store/slices/repos-runtime-routing-fixture.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| if (!knownServerTarget && !hasProvisionedRoot && !directTarget) { | ||
| return false | ||
| } | ||
| return destroyRecipeVm(ownerHostId, workspaceIds, knownServerTarget, directTarget) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Reload the catalog before ruling out a runtime-hosted recipe VM.
If the catalog refresh in prepareRequestForCreate fails, a portable recipe project can have a runtime: host, no runtime-owned connectionId, and no provisioned-root worktree. This branch returns false before checking the server catalog again. removeProject then sends repo.rm but leaves the recipe VM running. Check the live catalog for a runtime host before concluding that no VM needs cleanup.
| if (cleanup.retainedSshTargetIds.includes(targetId)) { | ||
| throw new Error('The cloud VM could not be destroyed. Retry cleanup before removing it.') | ||
| } | ||
| return serverTarget !== null |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Report server destruction only after cleanup destroys the target.
When listRuntimes() finds no matching runtime, cleanupEphemeralVmRuntimesForDeleted returns empty destroyed and retained target sets. This line still returns true when the catalog contains the server target. removeProject then skips repo.rm and deletes the project row although the VM was not destroyed. Require cleanup.destroyedSshTargetIds to contain targetId; otherwise retain the project and report the cleanup failure.
ELI5
When a VM recipe creates a machine and hands Orca an SSH login for it, Orca should put a managed Orca server on that machine, the same way it does for every other SSH host. It refused, because it thought the VM's login was already "owned" by something else. It wasn't: the VM record only remembers when to create and destroy the machine. Now Orca deploys the server, the workspace lives on it, and removing the project still destroys the VM.
What Changed
Before: creating a workspace from a recipe whose result is an SSH login (for example a "provisioned root" recipe) logged
Conversion refused by: [{"code":"orcad_migration_target_owned"}]. Every connect fell back to the old relay. A build without the relay could not open the workspace at all.After: the first connect deploys a managed Orca server on the VM. The workspace appears on that server (
runtime:<server>), adopted as the main worktree with no linked worktree created. Removing the project runs the recipe's destroy step, closes the server's tunnel and forgets the server, then removes the hidden SSH login.Mechanism:
ssh-target-orcad-claims.tstreated anytarget.owneras an exclusive holder. A recipe VM's hidden target always carriesowner: { type: 'on-demand-runtime' }, so the host never counted as empty. It went to the conversion path instead, and that path refuses owned targets. An ephemeral runtime owner now no longer blocks the claim. Unmigrated legacy owners still do.<label> VM <runtime id>, so two VMs made by one recipe don't collide on the unique server name.connectRuntimeOwnedSshTargetreturns the managed server when the connect routes to one, instead of waiting for direct SSH providers. The VM record stores that server id, and provisioning returns it.worktree.adoptProvisionedRoot. The host runs the same checks the direct-SSH adoption already ran: the root is the only checkout, it is the main checkout, it is not bare or sparse, and it is on the requested branch and commit. That shared logic moved intoprovisioned-root-checkout.tsso both paths use one copy. The host then records the workspace metadata.Why
This fixes the actual refusal instead of adding a recipe-only exception to the connect flow. A VM host now goes down the same empty-host deploy path as any new SSH host, so it needs no relay code. Alternatives considered:
ssh:<vm target>and routing it through the server. No owner routing maps a direct SSH host id to a managed server, and conversion moves projects to the server's catalog anyway.The new RPC sits behind a capability (
worktree.provisioned-root.v1). A VM's server is deployed from the same build, but an older server gets a clear "update Orca on the VM" error instead of a failed call.Linked Issue
N/A (maintainer). This is blocker 1 for the relay removal in #27214, from the managed-host e2e lane added in #27323.
Visual Proof
N/A. No UI changes; the workspace now appears through the managed path.
tests/e2e/ssh-orcad-vm-provisioned-root.spec.tscovers the full journey and now requires the workspace to be on the managed server (runtime:), not the relay.Testing
New unit tests:
The existing direct-SSH adoption tests still pass against the shared checks.
pnpm tc,pnpm lintandpnpm run check:code-quality:changedpass. CI'sorcad-journeys-dockerjob runs the e2e spec.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)