Skip to content

fix(worktree): stop push-target rollback deleting a sibling's remote - #16569

Merged
nwparker merged 1 commit into
mainfrom
nwparker/push-target-rollback-sibling
Aug 26, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/push-target-rollback-sibling

Conversation

@nwparker

@nwparker nwparker commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

Split out of 616d2a4ec8c, which also carried the Windows relay fix that shipped as #16550. Original work by @AmethystLiang; I dropped it from that branch so the release cherry-pick stayed minimal, and this is it getting its own PR. Unrelated to Windows.

The bug

When a push target reuses an existing Orca-created fork remote, it deliberately inherits ownership of it, so that the last worktree using it can clean it up:

// Why: if a later PR worktree reuses an Orca-created fork remote, it
// must inherit ownership so deleting the final user can remove it.
remoteCreated = isRemoteCreatedByKnownWorktree(existingRemote)

Rollback then reused that same flag to decide whether to undo its own work:

} catch (error) {
  if (remoteCreated) {
    await execGit(['remote', 'remove', remoteName], repoPath).catch(() => {})
  }
  throw error
}

But remoteCreated being true doesn't mean this call added the remote — it can equally mean a sibling worktree added it and is still pushing to it. So if the fetch fails while creating a worktree that reused a sibling's fork remote, rollback deletes that remote out from under the sibling.

The two meanings were never separable from one flag: cleanup needs "does anyone own this," rollback needs "did I add this."

The fix

Track remoteAddedHere alongside remoteCreated. Ownership semantics are unchanged — cleanup still inherits. Rollback now only removes a remote this call actually ran remote add for.

The local path (worktree-push-target-setup.ts) and the SSH path (worktree-remote.ts) had the same bug independently, so both are fixed.

Validation

Both regression tests were confirmed to catch the bug — reverting just the production change while keeping the tests fails exactly the two new cases:

FAIL  worktree-push-target-setup.test.ts > keeps a reused remote a sibling worktree owns when the fetch fails
  AssertionError: expected [ [ 'remote', 'remove', …(1) ] ] to deeply equal []
FAIL  worktrees-ssh-fork-push-target-remote.test.ts > keeps a reused fork remote a sibling worktree owns when the SSH head fetch fails
  AssertionError: expected "vi.fn()" to not be called with arguments: [ [ 'remote', 'remove', …(1) ], …(1) ]

With the fix: 17/17 pass. pnpm tc clean, oxlint clean.

A push target that reuses an existing Orca-created fork remote inherits
ownership of it (`remoteCreated = isRemoteCreatedByKnownWorktree(...)`),
so the final worktree to be deleted can remove it. Rollback then reused
that same flag to decide whether to undo its own work -- but a reused
remote was not added by this call, and a live sibling worktree is still
pushing to it. A failed fetch during create therefore deleted a remote
another worktree depends on.

Track `remoteAddedHere` separately: ownership stays inherited for
cleanup, while rollback only removes a remote this call actually added.
Both the local and the SSH path had the same bug and are fixed together.

Original work by Jinjing (AmethystLiang) in 616d2a4ec8c; split out of
that branch so the release fix in #16550 stayed a clean cherry-pick.
@coderabbitai

coderabbitai Bot commented Aug 26, 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: 49b844c9-e331-4ba3-abf4-71c4e3beb02c

📥 Commits

Reviewing files that changed from the base of the PR and between 868fc39 and ebef7a8.

📒 Files selected for processing (4)
  • src/main/ipc/worktree-push-target-setup.test.ts
  • src/main/ipc/worktree-push-target-setup.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-ssh-fork-push-target-remote.test.ts

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


📝 Walkthrough

Walkthrough

Push-target preparation now distinguishes remotes created by the current invocation from reused remotes. Standard and SSH setup paths remove a remote after fetch failure only when the current invocation added it. Regression tests verify that reused remotes owned by sibling worktrees remain configured and that fetch errors propagate.

Merge Risk: ⚪ Minimal · up to ebef7

This change narrows rollback cleanup so reused remotes owned by sibling worktrees are preserved while locally added remotes are still removed; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the bug, the fix, the affected local and SSH paths, and the validation results. However, it omits the required Linked Issue entry, Visual Proof or an explicit N/A expl… Add the required template sections and complete them. Include a linked issue using Fixes #..., state N/A with a reason for Visual Proof because this is not a UI change, complete the Testing and repository checklists, and address AI Disc…
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 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 and concisely describes the main fix: preventing rollback from deleting a sibling worktree's remote.
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.
Full details: Description check

Explanation

The description clearly explains the bug, the fix, the affected local and SSH paths, and the validation results. However, it omits the required Linked Issue entry, Visual Proof or an explicit N/A explanation, the Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the repository Checklist.

Resolution

Add the required template sections and complete them. Include a linked issue using Fixes #..., state N/A with a reason for Visual Proof because this is not a UI change, complete the Testing and repository checklists, and address AI Disclosure, Review, Agent skill upstream boundary, and Notes.

  • Fix all pre-merge checks with AI
✨ 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.

@nwparker
nwparker merged commit 1c9fb84 into main Aug 26, 2026
49 checks passed
@nwparker
nwparker deleted the nwparker/push-target-rollback-sibling branch August 26, 2026 06:48
Pierre-Mike pushed a commit to Pierre-Mike/orca that referenced this pull request Aug 26, 2026
…tablyai#16569)

A push target that reuses an existing Orca-created fork remote inherits
ownership of it (`remoteCreated = isRemoteCreatedByKnownWorktree(...)`),
so the final worktree to be deleted can remove it. Rollback then reused
that same flag to decide whether to undo its own work -- but a reused
remote was not added by this call, and a live sibling worktree is still
pushing to it. A failed fetch during create therefore deleted a remote
another worktree depends on.

Track `remoteAddedHere` separately: ownership stays inherited for
cleanup, while rollback only removes a remote this call actually added.
Both the local and the SSH path had the same bug and are fixed together.

Original work by Jinjing (AmethystLiang) in 616d2a4ec8c; split out of
that branch so the release fix in stablyai#16550 stayed a clean cherry-pick.

(cherry picked from commit 1c9fb84)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…tablyai#16569)

A push target that reuses an existing Orca-created fork remote inherits
ownership of it (`remoteCreated = isRemoteCreatedByKnownWorktree(...)`),
so the final worktree to be deleted can remove it. Rollback then reused
that same flag to decide whether to undo its own work -- but a reused
remote was not added by this call, and a live sibling worktree is still
pushing to it. A failed fetch during create therefore deleted a remote
another worktree depends on.

Track `remoteAddedHere` separately: ownership stays inherited for
cleanup, while rollback only removes a remote this call actually added.
Both the local and the SSH path had the same bug and are fixed together.

Original work by Jinjing (AmethystLiang) in 616d2a4ec8c; split out of
that branch so the release fix in stablyai#16550 stayed a clean cherry-pick.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…tablyai#16569)

A push target that reuses an existing Orca-created fork remote inherits
ownership of it (`remoteCreated = isRemoteCreatedByKnownWorktree(...)`),
so the final worktree to be deleted can remove it. Rollback then reused
that same flag to decide whether to undo its own work -- but a reused
remote was not added by this call, and a live sibling worktree is still
pushing to it. A failed fetch during create therefore deleted a remote
another worktree depends on.

Track `remoteAddedHere` separately: ownership stays inherited for
cleanup, while rollback only removes a remote this call actually added.
Both the local and the SSH path had the same bug and are fixed together.

Original work by Jinjing (AmethystLiang) in 616d2a4ec8c; split out of
that branch so the release fix in stablyai#16550 stayed a clean cherry-pick.

(cherry picked from commit 1c9fb84)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#16569)

A push target that reuses an existing Orca-created fork remote inherits
ownership of it (`remoteCreated = isRemoteCreatedByKnownWorktree(...)`),
so the final worktree to be deleted can remove it. Rollback then reused
that same flag to decide whether to undo its own work -- but a reused
remote was not added by this call, and a live sibling worktree is still
pushing to it. A failed fetch during create therefore deleted a remote
another worktree depends on.

Track `remoteAddedHere` separately: ownership stays inherited for
cleanup, while rollback only removes a remote this call actually added.
Both the local and the SSH path had the same bug and are fixed together.

Original work by Jinjing (AmethystLiang) in 616d2a4ec8c; split out of
that branch so the release fix in stablyai#16550 stayed a clean cherry-pick.
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