Skip to content

fix(worktree): don't path-sweep sibling sessions when deleting a folder workspace (#10252) - #10268

Merged
AmethystLiang merged 2 commits into
mainfrom
deleting-one-workspace-kills-terminal-agent-sess
Jul 24, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
deleting-one-workspace-kills-terminal-agent-sess

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Deleting one folder-workspace could kill terminal/agent sessions belonging to other workspaces that share the same checkout path — sibling instances, and even worktrees of a different repo rooted under that directory. Both pi and Claude Code agent sessions died at the same instant with no recovery. Fixes #10252.

Root cause

killAllProcessesForWorktree() runs three sweeps to find PTYs to tear down. The runtime and registry sweeps match by exact worktreeId; only the provider sweep's cwdOwned path fallback matches by path:

// sweepProviderByPrefix — only for sessions with worktreeId === undefined
isPathInsideOrEqual(worktreePath, session.cwd)

worktreePath is derived via splitWorktreeIdForFilesystem(), which strips the ::workspace:<uuid> suffix for folder-workspace instances. So deleting instance repo::/Users/me::workspace:<uuid> collapses worktreePath to the shared dir /Users/me, and every untagged session under it gets swept — sibling workspaces, other repos, and, worst case (a home directory registered as a folder repo), nearly every session for that user.

Fix

Disable the path fallback when the worktree being torn down is a folder-workspace instance — its filesystem path can't identify a single instance. The exact ${worktreeId}@@ prefix and authoritative session.worktreeId matches (both carrying the instance uuid) still tear down the deleted instance's own sessions. Normal git worktrees (unique paths) keep the fallback.

  • isFolderWorkspaceInstanceId() in src/shared/worktree-id.ts (reuses the existing FOLDER_WORKSPACE_INSTANCE_SUFFIX regex)
  • gate worktreePath in killAllProcessesForWorktree() (src/main/runtime/worktree-teardown.ts)

Testing

  • New regression tests in worktree-teardown.test.ts: folder-instance delete no longer sweeps untagged siblings; still tears down its own prefix-/worktreeId-matched sessions; a combined 4-quadrant list kills exactly the two own sessions. Plus isFolderWorkspaceInstanceId unit tests. The sibling test fails on main and passes with the fix.
  • Validated in the running Electron dev build: deleting one folder-workspace instance killed its own session, the sibling survived, repo/root intact, no crash.
  • oxlint, oxfmt, and tsc clean; 52 touched-suite tests + 26 folder-scoped tests in the broader suites pass.

Scope / notes

  • Accepted tradeoff: a truly untagged session of the deleted instance is no longer force-killed (ownership is unprovable on a shared path; leaving it alive is the safe direction). Modern folder-instance terminals are tagged with the instance id and are still torn down.
  • The root-id case is covered because root deletion is blocked upstream ("Cannot delete the project root workspace"), so only suffix-bearing instances reach the sweep (existing guard tests referenced in the doc).
  • The folder-delete path sweeps only the local provider today; SSH folder-instance daemon-session teardown is a pre-existing, out-of-scope gap.

Design rationale, alternatives, and edge cases: docs/delete-workspace-cwd-owned-sibling-kill.md.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: de80885a-2d4c-4733-821c-a574d9941320

📥 Commits

Reviewing files that changed from the base of the PR and between 00dc00fc47808ad3828439b7cc585f20cd7f875e and b3c4fd5.

📒 Files selected for processing (3)
  • docs/delete-workspace-cwd-owned-sibling-kill.md
  • src/main/runtime/worktree-teardown.test.ts
  • src/main/runtime/worktree-teardown.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/runtime/worktree-teardown.test.ts
  • src/main/runtime/worktree-teardown.ts

📝 Walkthrough

Walkthrough

Updates worktree teardown so folder-workspace instances no longer use shared filesystem paths to identify untagged sessions. Exact worktreeId and prefix ownership matching remains active. Regression tests verify sibling sessions survive while sessions owned by the deleted instance are shut down. Documentation records the incident, fix invariant, tradeoffs, residual risks, and test plan.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, root cause, fix, testing, and notes, but it omits required sections like Screenshots, AI Review Report, and Security Audit. Add the missing template sections and include a brief AI review, security audit, and screenshots note or 'No visual change'.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing sibling session path sweeps when deleting a folder workspace.
Linked Issues check ✅ Passed The code and tests address #10252 by disabling cwd fallback for folder-workspace instances while preserving exact worktreeId and prefix matches.
Out of Scope Changes check ✅ Passed The added doc, helper, and regression tests all support the workspace-teardown fix, with no unrelated changes apparent.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@AmethystLiang
AmethystLiang force-pushed the deleting-one-workspace-kills-terminal-agent-sess branch from 9797309 to 00dc00f Compare July 24, 2026 02:16

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 605c512e-64fb-4ed4-95f2-749e0e2b4884

📥 Commits

Reviewing files that changed from the base of the PR and between 979730974bdc0358d150573d28934bb87b33abcb and 00dc00fc47808ad3828439b7cc585f20cd7f875e.

📒 Files selected for processing (5)
  • docs/delete-workspace-cwd-owned-sibling-kill.md
  • src/main/runtime/worktree-teardown.test.ts
  • src/main/runtime/worktree-teardown.ts
  • src/shared/worktree-id.test.ts
  • src/shared/worktree-id.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/shared/worktree-id.test.ts
  • src/shared/worktree-id.ts
  • src/main/runtime/worktree-teardown.test.ts

…er workspace (#10252)

Deleting one folder-workspace instance could kill terminal/agent sessions in
OTHER workspaces sharing the same checkout path — sibling instances, and even
worktrees of a different repo rooted under that directory. Both pi and Claude
Code agent sessions died at once with no recovery.

The `cwdOwned` path fallback in killAllProcessesForWorktree() derives its match
path via splitWorktreeIdForFilesystem(), which strips the `::workspace:<uuid>`
suffix and collapses a folder instance's path to the shared checkout dir. Every
untagged session under that dir then path-matched and got swept (worst case: a
home directory registered as a folder repo).

Disable the path fallback for folder-workspace instances — their filesystem
path can't identify a single instance. The exact `${worktreeId}@@` prefix and
authoritative `session.worktreeId` matches (both carrying the instance uuid)
still tear down the deleted instance's own sessions; normal git worktrees
(unique paths) keep the fallback. The runtime and registry sweeps already
matched by exact worktreeId.

Adds isFolderWorkspaceInstanceId() and regression tests. See
docs/delete-workspace-cwd-owned-sibling-kill.md.
@AmethystLiang
AmethystLiang force-pushed the deleting-one-workspace-kills-terminal-agent-sess branch from 00dc00f to b3c4fd5 Compare July 24, 2026 02:23
@AmethystLiang
AmethystLiang merged commit 381e81e into main Jul 24, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…er workspace (stablyai#10252) (stablyai#10268)

* fix(worktree): don't path-sweep sibling sessions when deleting a folder workspace (stablyai#10252)

Deleting one folder-workspace instance could kill terminal/agent sessions in
OTHER workspaces sharing the same checkout path — sibling instances, and even
worktrees of a different repo rooted under that directory. Both pi and Claude
Code agent sessions died at once with no recovery.

The `cwdOwned` path fallback in killAllProcessesForWorktree() derives its match
path via splitWorktreeIdForFilesystem(), which strips the `::workspace:<uuid>`
suffix and collapses a folder instance's path to the shared checkout dir. Every
untagged session under that dir then path-matched and got swept (worst case: a
home directory registered as a folder repo).

Disable the path fallback for folder-workspace instances — their filesystem
path can't identify a single instance. The exact `${worktreeId}@@` prefix and
authoritative `session.worktreeId` matches (both carrying the instance uuid)
still tear down the deleted instance's own sessions; normal git worktrees
(unique paths) keep the fallback. The runtime and registry sweeps already
matched by exact worktreeId.

Adds isFolderWorkspaceInstanceId() and regression tests. See
docs/delete-workspace-cwd-owned-sibling-kill.md.

* rm design doc
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.

Deleting one workspace kills terminal/agent sessions in other workspaces sharing the same checkout path (cwdOwned fallback)

1 participant