Skip to content

Fix deleted remote worktree reappearing due to host ID mismatch - #16039

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/deleted-remote-worktree-keeps-reappearing
Aug 25, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/deleted-remote-worktree-keeps-reappearing

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 23, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​213 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71

Problem

When a paired client (e.g., running in a remote environment) deletes a worktree, it passes its own host ID spelling (like runtime:env-1). The host machine may store the same worktree under a different host ID spelling (like local). This mismatch prevented cleanup from finding and removing the worktree, causing deleted worktrees to reappear.

Solution

Added resolvePairedCallerHostId() to translate the client's host ID to what the host actually uses for that repo. Worktree removal and branch deletion now resolve the host ID before cleanup operations. When there's ambiguity (same repo stored under multiple host IDs), the call fails safely rather than removing the wrong worktree.

Also optimized: omit host ID from RPC calls when the target environment already matches, reducing unnecessary qualifiers.

Testing

  • Added comprehensive tests for host ID resolution logic covering: passthrough of non-runtime IDs, translation to local when no runtime spelling exists, preservation of stamps still in use, rejection of ambiguous cases
  • Added integration tests for worktree removal with runtime host ID translation
  • Test coverage for preserved branch cleanup using consistent host qualifiers

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered

Notes

Fixes worktrees reappearing after deletion due to host ID mismatch in paired environments.

@coderabbitai

coderabbitai Bot commented Aug 23, 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: 4f2fc2ad-5dce-4202-86a9-018903e4adad

📥 Commits

Reviewing files that changed from the base of the PR and between 6bbbf38e16d2c6fe241ee3f69d8a74904c28967e and 0acf4a3.

📒 Files selected for processing (1)
  • src/renderer/src/store/slices/worktrees/teardown/dispatch-worktree-removal.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds repository-aware paired caller host-ID resolution. Runtime worktree removal and preserved-branch deletion now use the resolved host ID. Force-delete requests validate and normalize hostId. Renderer cleanup omits host IDs when the target runtime environment already identifies the same environment and preserves qualifiers otherwise. Tests cover normalization, routing, ambiguity errors, fallback behavior, and preserved-branch cleanup.

Merge Risk: 🟡 Moderate · up to 0acf4

The change updates worktree removal and branch cleanup host-ID resolution, but both renderer cleanup paths still access a runtime-only host identifier without narrowing, and the supplied typecheck reports build failures. The PR is not merge-ready until the typing issue and failed checks are fixed.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, and tests, but it omits required template sections, an issue link, visual proof or N/A, and test status details. Use the repository template, add a valid Fixes #... link, complete the required sections, and document visual proof, AI disclosure, review, and test or CI status.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 8 files. 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 primary fix for deleted remote worktrees that reappear because of host ID mismatches.
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.
✨ Finishing Touches 💡 1
📝 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.

@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: e93a18f2-d4bb-42ca-a9a1-0bab8c31f1ee

📥 Commits

Reviewing files that changed from the base of the PR and between 202d74a and ebbdb68.

📒 Files selected for processing (8)
  • src/main/runtime/rpc/methods/paired-caller-host-id.test.ts
  • src/main/runtime/rpc/methods/paired-caller-host-id.ts
  • src/main/runtime/rpc/methods/worktree-rm-host-qualification.test.ts
  • src/main/runtime/rpc/methods/worktree-schemas.ts
  • src/main/runtime/rpc/methods/worktree.ts
  • src/renderer/src/store/slices/worktrees-remote-runtime-removal.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/dispatch-worktree-removal.ts
  • src/renderer/src/store/slices/worktrees/teardown/force-delete-preserved-branch.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@OrcaWin
OrcaWin force-pushed the OrcaWin/deleted-remote-worktree-keeps-reappearing branch from fe4bc58 to 6bbbf38 Compare August 24, 2026 18:17
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

m4air added 3 commits August 24, 2026 11:25
Paired clients and servers may use different spellings for execution hosts
(e.g., client 'runtime:env-1' vs server 'local'). Resolve these spellings
before worktree.rm and worktree.forceDeleteBranch to prevent failures and
orphaned worktrees.
Ensure parsed host IDs are actually runtime environments before
accessing their environmentId property. Fixes incorrect host ID
matching during worktree cleanup that caused deleted remote
worktrees to reappear.
When a surviving host has the same ID as the deleted worktree's
original host, use the hostId directly instead of qualifying it
through the runtime call host. This prevents worktrees from
reappearing due to host ID mismatch.
@OrcaWin
OrcaWin force-pushed the OrcaWin/deleted-remote-worktree-keeps-reappearing branch from 6bbbf38 to 0acf4a3 Compare August 24, 2026 18:42
@OrcaWin
OrcaWin merged commit 1a7934c into main Aug 25, 2026
47 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…lyai#16039)

* Fix deleted remote worktree reappearing due to host ID mismatch

Paired clients and servers may use different spellings for execution hosts
(e.g., client 'runtime:env-1' vs server 'local'). Resolve these spellings
before worktree.rm and worktree.forceDeleteBranch to prevent failures and
orphaned worktrees.

* Validate runtime kind before comparing environment IDs

Ensure parsed host IDs are actually runtime environments before
accessing their environmentId property. Fixes incorrect host ID
matching during worktree cleanup that caused deleted remote
worktrees to reappear.

* Use hostId directly when same-ID surviving host exists

When a surviving host has the same ID as the deleted worktree's
original host, use the hostId directly instead of qualifying it
through the runtime call host. This prevents worktrees from
reappearing due to host ID mismatch.

---------

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
(cherry picked from commit 1a7934c)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…lyai#16039)

* Fix deleted remote worktree reappearing due to host ID mismatch

Paired clients and servers may use different spellings for execution hosts
(e.g., client 'runtime:env-1' vs server 'local'). Resolve these spellings
before worktree.rm and worktree.forceDeleteBranch to prevent failures and
orphaned worktrees.

* Validate runtime kind before comparing environment IDs

Ensure parsed host IDs are actually runtime environments before
accessing their environmentId property. Fixes incorrect host ID
matching during worktree cleanup that caused deleted remote
worktrees to reappear.

* Use hostId directly when same-ID surviving host exists

When a surviving host has the same ID as the deleted worktree's
original host, use the hostId directly instead of qualifying it
through the runtime call host. This prevents worktrees from
reappearing due to host ID mismatch.

---------

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#16039)

* Fix deleted remote worktree reappearing due to host ID mismatch

Paired clients and servers may use different spellings for execution hosts
(e.g., client 'runtime:env-1' vs server 'local'). Resolve these spellings
before worktree.rm and worktree.forceDeleteBranch to prevent failures and
orphaned worktrees.

* Validate runtime kind before comparing environment IDs

Ensure parsed host IDs are actually runtime environments before
accessing their environmentId property. Fixes incorrect host ID
matching during worktree cleanup that caused deleted remote
worktrees to reappear.

* Use hostId directly when same-ID surviving host exists

When a surviving host has the same ID as the deleted worktree's
original host, use the hostId directly instead of qualifying it
through the runtime call host. This prevents worktrees from
reappearing due to host ID mismatch.

---------

Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
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