Skip to content

fix(runtime): a terminal spawn names its host; the removed-project fence keys by host (R4-2) - #30798

Merged
nwparker merged 2 commits into
mainfrom
nwparker/r4-2-host-spawn-fence
Oct 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/r4-2-host-spawn-fence

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​112 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32

ELI5

When you remove a project, Orca fences it so no new terminal can start inside it. To decide, the fence asks: "is there still a project with this id on the host this terminal would run on?" The "which host" half of that question was optional. A caller that left it out was silently treated as "this computer", even when its terminal was about to start on an SSH host. Now the host is required, so the compiler refuses to build a caller that leaves it out.

What Changed

  • The spawn lease names its host. acquireWorktreeTerminalSpawn is the lease every terminal spawn takes. It now takes a HostWorktreeTarget: the workspace id plus the host whose provider runs the spawn. Before, it took a bare id and an optional connectionId that defaulted to this computer.
    • Both spawn paths (spawn-options.ts, spawn-execute.ts) build the target with the new spawnWorktreeTarget(worktreeId, connectionId), from the same connectionId that picks their PTY provider. So the fence and the provider can't disagree about the host.
  • The removal fence records hosts. It lives in project-terminal-stop.ts and keeps, for each removed project id, the execution host each removed copy was on (local or ssh:<target>, as an ExecutionHostId). It compares that against the spawn's host. Before, it kept a raw connection string.

Before and after, as the user sees it: no difference today. Every current caller already passed its connection, so the fence's answers are unchanged. That includes the case where a local copy and an SSH copy share an id (already covered by tests). This PR closes the door for the next caller: one that forgets the host no longer compiles, where before it got "this computer" silently.

Why

This is the last step of R4-2: store writes and the spawn fence take the row's host instead of a bare id.

Alternatives considered:

  • Make connectionId required instead. A caller could still pass the wrong kind of id, and it wouldn't match the HostWorktreeTarget shape the rest of R4-2 uses.
  • Count only rows that run in this process (rowsRunHere) as survivors. That was this PR's first draft. The Opus review showed it would refuse spawns for a project a paired client registered on this server: such rows carry a runtime: stamp, and repo-execution-host.ts says that stamp names files on this host. So the fence keeps counting every row, and a test pins that case.
  • Key the worktree mutation lock and the sleep state by host as well. When twins share one lock, they only wait for each other, which is safe. Re-keying the sleep state is a store change and is out of scope (D7).

Linked Issue

Part of SSH hardening round 4 (R4-2, the spawn fence). There is no GitHub issue.

Visual Proof

N/A: nothing the user sees changes. This is a type-level change to an in-process lease.

Testing

  • New twin test in src/main/runtime/project-removal-terminal-stop.test.ts. An SSH row and a self-stamped runtime: row share an id. After the SSH row is removed, an SSH spawn is refused and a local spawn for the surviving row is admitted. It fails on this PR's first draft and passes now. The existing local/SSH twin tests still pass.

  • No fail-before on main: main's behaviour was already right for every current caller. The gain is the required host.

  • Static analysis: every step of the static-analysis job ran locally: the oxlint suites, changed-code quality, React Doctor, every ratchet, the RPC catalog check and typecheck:ci.

  • Units, single worker: src/main/ipc/pty/, src/main/ipc/pty-launch*, src/shared/worktree, orca-runtime.test.ts, and every runtime suite that takes the lease.

    • The only failures were two folder-setup cases in orca-runtime.test.ts. They compare /var with /private/var, a macOS temp-path issue that fails the same way without this change.
  • Not verified live. In-process only; there's no wire or host-side change.

  • I manually tested these changes locally

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

Review

  • Codex (gpt-6.1-sol, high): round 1 clean; round 2, on the head, clean.
  • Opus, round 1:
    • P2 fixed: rowsRunHere survivors would refuse self-stamped rows. Reverted to all rows, with a test.
    • P3 fixed: the spawn connection is now trimmed (normalizeHostPart), as before.
  • Opus, round 2: no P1/P2.
    • P3 not changed here, because it predates this PR: projectSiblingSharesFence and releaseProjectHostSessions still use rowsRunHere, so the file has two meanings of "surviving row". The comment now says why the spawn fence counts every row. Follow-up below.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

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)

…nce is per (project, host)

acquireWorktreeTerminalSpawn takes the spawn's HostWorktreeTarget instead of a
bare id plus an optional connectionId that defaulted to this machine. The
removal fence records ExecutionHostIds and only counts surviving rows that run
in this process, so a paired server's same-id residue row no longer readmits a
removed local project's spawn.
@nwparker
nwparker merged commit b30a798 into main Oct 19, 2026
56 checks passed
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