Repository navigation
fix(runtime): a terminal start on an SSH twin no longer wakes or is refused by this computer's sleep - #30860
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
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:
c12432f6-478a-4814-a1a8-b468d829d764
📥 Commits
Reviewing files that changed from the base of the PR and between bd7633f and eb3af5dcf6ec9d66a01e0153c5732dce814d8ab6.
📒 Files selected for processing: 6
src/main/runtime/construction/runtime-identity-state.tssrc/main/runtime/sidebar-inputs/orca-runtime-sidebar-temporal.tssrc/main/runtime/terminal/stop/worktree-terminal-sleep-key.tssrc/main/runtime/terminal/stop/worktree-terminal-sleep.tssrc/main/runtime/terminal/stop/worktree-terminal-stop.tssrc/main/runtime/worktree-terminal-sleep-host-twin.test.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.
| const nestedSshRepo = { | ||
| ...store.getRepos()[0], | ||
| executionHostId: 'runtime:env-a', | ||
| connectionId: 'ssh-nested' | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Fix the typecheck failure: executionHostId is inferred as string.
The object literal at Line 15 widens executionHostId: 'runtime:env-a' to string. resolveWorktreeLaunchHost at Line 85 requires LaunchHostRepo, whose executionHostId is "local" | runtime:${string}|ssh:${string} | null | undefined. This causes TS2345 and fails pnpm run typecheck:ci. Declare the literal with as const on that property.
🐛 Proposed fix
--- "a/src/main/runtime/worktree-terminal-sleep-host-twin.test.ts"
+++ "b/src/main/runtime/worktree-terminal-sleep-host-twin.test.ts"
@@ -12,11 +12,11 @@
await import('./orca-runtime-test-fixtures.spec')
// A `runtime:` stamp with a nested SSH target: this process launches it with no connection.
const nestedSshRepo = {
...store.getRepos()[0],
- executionHostId: 'runtime:env-a',
+ executionHostId: 'runtime:env-a' as const,
connectionId: 'ssh-nested'
}
const nestedSshStore = {
...store,
getRepo: () => nestedSshRepo,
📝 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.
| const nestedSshRepo = { | |
| ...store.getRepos()[0], | |
| executionHostId: 'runtime:env-a', | |
| connectionId: 'ssh-nested' | |
| } | |
| const nestedSshRepo = { | |
| ...store.getRepos()[0], | |
| executionHostId: 'runtime:env-a' as const, | |
| connectionId: 'ssh-nested' | |
| } |
Source: Pipeline failures
…efused by this computer's sleep The host's sleep state was keyed by the bare worktree id, which a repo registered on two hosts publishes twice. A spawn on the SSH copy found the local copy's sleep, so an automatic probe was refused and any other spawn woke the local sleep. Key both sleep maps by host plus workspace, with the sleep side deriving its host the way a spawn does. Co-authored-by: Claude <noreply@anthropic.com>
…H target, as its spawns do Co-authored-by: Claude <noreply@anthropic.com>
…launch scope uses Predicting the host from one repo row disagreed with the launch path for a runtime-stamped project with a nested SSH target. Reuse resolveWorktreeLaunchHost so a sleep and the spawns of the same workspace always name one key. Co-authored-by: Claude <noreply@anthropic.com>
…and refuses an unresolvable host Sleeping this computer's copy also stopped the SSH twin's live PTYs and filed them under this host's key, where the twin's spawn could never wake them. Resolve one sleep scope (key and PTY fence) per sleep from the launch-host resolver, fence the live sets with it, and refuse the sleep when rival rows disagree about the host instead of guessing local. The maps are typed and named by host-scoped key. Co-authored-by: Claude <noreply@anthropic.com>
eb3af5d to
8ead454
Compare
ELI5
When a project is registered both on this computer and on an SSH host, its workspaces on the two machines share one id. Putting this computer's copy to sleep recorded the sleep under that shared id, so a terminal starting on the SSH copy was treated as if it were this computer's copy: a background start there was refused, and any other start there "woke" this computer's sleeping copy.
What Changed
Mechanism: each sleep resolves one scope (a host-plus-workspace key and a terminal host fence) once, from the launch-host resolver, and uses it everywhere. The runtime's two sleep maps (in-flight sleeps and committed sleep state) are keyed by that
HostScopedWorktreeKeyinstead of the bare id, typed so a bare id cannot be passed, and renamed...ByHostWorktree. The sleep's live-terminal inventory is filtered by the same fence, so only that host's terminals are stopped and recorded. When rival project rows disagree about the host, the sleep is refused, as the launch already is, rather than guessing this computer. A spawn already names its host throughspawnWorktreeTarget(localorssh:<target>); the sleep side derives its host from the same launch-host resolver (resolveWorktreeLaunchHost) the terminal launch scope uses to pick that connection, so a sleep and the spawns of the same workspace always name one key. That includes aruntime:-stamped project with a nested SSH target, which this process launches with no connection. Readers that only know the bare workspace id still match any host, as before: the "is this held asleep" check for automatic tab materialization, the sidebar retention gap, and the structured-session "sleeping" probe. They are conservative (a twin's sleep can only make them more cautious), and narrowing them needs host context their callers don't carry.Unchanged on the wire: the
worktreeTerminalSleepStateevents and the status snapshot keep their shape and still carry the bareworktreeId, so older clients see no difference.Why
The spawn side was already host-qualified (#30798 gave every spawn a
HostWorktreeTarget); only the sleep side dropped the host. Keying the record by host is the smallest change that makes both sides compare the same thing. Alternatives considered: checking each sleeping PTY's host at wake time (more moving parts, and the record would still collide for twins sleeping at once).The per-worktree mutation lock stays keyed by the bare id on purpose. The same lock serializes adoption, project removal stops and terminal closes, which still run host-blind. A host-scoped sleep lock would stop excluding those. Over-serializing a twin's spawn behind a sleep is only a short wait, so it is safe.
Known limit: the scope is read when the sleep starts. If a project row is re-pointed to another host while its workspace sleeps, the record stays under the host it was slept on until that host's next spawn or sleep.
Design check (past three review rounds): earlier rounds each found a place where the sleep's host, or the terminals it touched, differed from the launch's. The redesign gives each sleep one scope object from the launch resolver, which every key and terminal filter reads, so there is a single choke point. Comparable remote-terminal designs also pick the host first and key saved terminal state by workspace inside it, so the approach holds.
Linked Issue
Follow-up from the SSH/managed-server deficiency scan (no issue).
Visual Proof
N/A: no UI change; the behavior is in the host runtime's sleep bookkeeping.
Testing
src/main/runtime/worktree-terminal-sleep-host-twin.test.ts:worktree_terminals_sleeping);runtime:-stamped project's spawn, with the connection the launch resolver hands it, still refuses and wakes its sleep;Also ran
src/main/runtime/terminal/stop,automatic-activation-host-sleep,project-removal-terminal-stop,sidebar-inputs,orca-runtime.test.tsand the PTY launch parity tests single-worker,pnpm tc:node, and every step of the static-analysis job locally. Verified only in tests, not live on a real SSH host. The managed-orcad Docker lane is dispatched against this head because path routing selects no e2e spec for this diff.Pre-existing local failures, identical with this change reverted:
orca-runtime-workspace-unread.test.ts,session-tabs/headless-browser-group-persistence.test.tsand two existing-folder import tests inorca-runtime.test.ts, which pass with a canonical TMPDIR. The VM rollback repro step can't build its baseline checkout locally (nozodin that temp tree), so CI covers it.AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)