Skip to content

fix(runtime): project removal and edits stay on the selected project's host - #30584

Merged
nwparker merged 2 commits into
mainfrom
nwparker/repo-removal-host-identity
Oct 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/repo-removal-host-identity

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​238 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​238
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​128

ELI5

The same project id can be registered twice: once on this computer and once on an SSH host. Three project actions picked the right copy but then acted on the wrong one, or skipped work entirely:

  1. Removing a project stopped its terminals but left its native Claude/Codex chats running, with their chat tabs saved for next launch.
  2. After an SSH project was removed, a terminal could still start in it as long as a local project with the same id existed.
  3. Editing an SSH project (renaming it, converting a folder to Git, changing its base branch) could edit the local project with the same id instead.

What Changed

Before: removing a project on a host left native chats (which have no terminal) running and their tabs restorable. After removing the SSH copy of a project, a terminal spawn that was queued behind the removal could still start there because a same-id local row survived. repo.update / repo.setBaseRef resolved the right row and then called store.updateRepo(repo.id, …) with no host, so persistence wrote the first row with that id.

After:

  • Chats on removal. Once the project row is gone, the host closes the project's live structured sessions on its own execution host and retires every member's chat tab, through the same helpers worktree removal already uses (structured-session-worktree-teardown.ts; new listStructuredSessionsForProject). The close runs alongside the post-removal terminal pass and still runs if that pass throws. It gets a 3 s floor past the shared 10 s budget, which keeps it inside repo.rm's 15 s client timeout. Chats are only touched after the removal commits, so a removal the WSL-move check refuses leaves them alone.
  • Spawn admission. The host now records each removed project's terminal connection, not just its id. A spawn passes its own connectionId (both spawn paths already had it). A spawn into a removed id is refused unless a surviving row with that id is on the spawn's own host. If no row with that id survives at all, every spawn is refused, as before.
  • Settings writes. update and setBaseRef now pass getRepoExecutionHostId(repo) into store.updateRepo, so the host-scoped row lookup that persistence already has is used.

Why

Each fix reuses something that already exists rather than adding a parallel path: the worktree-teardown structured-session close and tab retirement, the PTY host fence that project removal already uses (getRepoSshConnectionId), and the optional hostId argument persistence's updateRepo already accepts.

  • Chat close placement. I considered a separate controller dependency for the chat close, but the existing terminal-stop dependency already runs on the host at the right moment. An option on it keeps the wiring in one place. I also considered closing chats on the first pass, before the row is removed. Tab retirement can't be undone, though, and the WSL fence can still refuse the removal after that pass.
  • Spawn admission. The spawn's connection id is what picks its PTY provider, and it is the same fence the stop uses. Comparing the two keeps admission and stopping in agreement.

Nothing changes on the wire. The new fields are in-process options only.

Linked Issue

Internal review findings (codex-review-4 #1, #2, #3). No issue filed. Follow-ups to #29964 and #29282.

Visual Proof

N/A. This is main-process runtime behaviour with no UI change. Covered by tests.

Testing

  • New failing-then-passing tests:

    • src/main/runtime/project-removal-structured-sessions.test.ts: chats closed and tabs retired on removal, fenced to the host; still closed when the terminal stop throws or has spent the budget.
    • src/main/runtime/project-removal-terminal-stop.test.ts: an SSH spawn is refused after removal despite a local sibling; any-host refusal once no row survives.
    • src/main/runtime/runtime-remove-project-host-scope.spec.ts: repo.update and repo.setBaseRef write the SSH row a path selector picked.
  • Neighbouring suites (src/main/ipc/pty, runtime terminal, construction, structured-session, retirement contracts): 171 files / 1818 tests pass. pnpm tc:node, changed-code quality and the static ratchets pass.

  • Live verification: unit and integration tests only, plus the managed-SSH Docker e2e lane dispatched on this branch (see comment).

  • I manually tested these changes locally

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

Review

Codex (gpt-6.1-sol, high) and an Opus review. Round 1 (both reviewers) found that a failed or budget-spent terminal pass skipped the chat close, and that admission stopped refusing a different-host spawn once no row survived. Both are fixed here. Round 2: Codex and Opus found nothing further.

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

  • SSH: chats are matched by the session record's execution host, the same as worktree teardown. A same-id sibling that shares the fence makes both sweeps stand down.
  • Liveness: a chat whose close is unproven is reported live or unverifiable, never exited.
  • Folder workspaces are matched by repo id prefix like git worktrees.
  • Known narrow gap: a chat created while repo.rm is still running, after the chat snapshot, is not closed. Chat creation has no removal fence the way terminal spawns do.
  • Several other store.updateRepo(id, …) calls without a host remain: runtime-project-host-setup-controller.ts, ipc/repos/project-host-setup-handlers.ts, ipc/folder-repo-git-upgrade.ts, the clone controllers, and runtime-repository-registration-controller.ts. They are the same class of bug and left out of scope.

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)

…d execution host

- Removing a project now closes its native Claude/Codex chats on this host and retires their tabs.
- A terminal spawn after removal is admitted only by a surviving row on the spawn's own host.
- repo.update and repo.setBaseRef write the resolved row's host, not a same-id sibling.
…heir own floor

- A failed or budget-spent terminal stop no longer skips the chat closes.
- Spawn admission still refuses on any host once no row with the removed id survives.
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: a475c6dd-cd60-493c-8130-01a14869b1f5
📥 Commits

Reviewing files that changed from the base of the PR and between 6c40f91 and 7431da7.

📒 Files selected for processing: 9
  • src/main/ipc/pty/ipc/spawn-options.ts
  • src/main/ipc/pty/runtime/spawn-execute.ts
  • src/main/runtime/construction/runtime-host-services.ts
  • src/main/runtime/project-removal-structured-sessions.test.ts
  • src/main/runtime/project-removal-terminal-stop.test.ts
  • src/main/runtime/runtime-remove-project-host-scope.spec.ts
  • src/main/runtime/runtime-repository-settings-controller.ts
  • src/main/runtime/structured-session-worktree-teardown.ts
  • src/main/runtime/terminal/stop/project-terminal-stop.ts

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

📝 Walkthrough

Repository updates now use the selected execution host when writing changes. Worktree spawn acquisition passes the connection ID, and spawn admission uses surviving project rows and SSH connection fences. Project removal can also close structured chat sessions and retire their tabs, while retaining host-scoped session filtering.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 7431d

The inspected host-scoping paths preserve the intended separation between local and SSH projects. No identified issue prevents merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 38.46% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly describes the main host-scoping fix for project removal and project edits. It is concise and directly related to the changes, although it does not mention terminal-spawn admission ex…
Description check Passed The description is complete and aligned with the repository template. It explains the user impact, implementation, rationale, known gap, testing, review status, and cross-platform or SSH consideration…
Full details: Title check

Explanation

The title clearly describes the main host-scoping fix for project removal and project edits. It is concise and directly related to the changes, although it does not mention terminal-spawn admission explicitly.

Full details: Description check

Explanation

The description is complete and aligned with the repository template. It explains the user impact, implementation, rationale, known gap, testing, review status, and cross-platform or SSH considerations. It documents that manual testing was not performed and provides internal review references instead of a linked issue.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker
nwparker merged commit 75b6fa2 into main Oct 19, 2026
42 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