Skip to content

fix(worktree): drop a just-added fork remote when its head fetch fails - #15850

Merged
nwparker merged 1 commit into
mainfrom
nwparker/Error-invoking-remote-method-worktrees-create-Error-Destructive-git-remote-operations-are-not-allowed-via-exec
Aug 22, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/Error-invoking-remote-method-worktrees-create-Error-Destructive-git-remote-operations-are-not-allowed-via-exec

Conversation

@nwparker

@nwparker nwparker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19

ELI5

Follow-up to #15827. When Orca sets up a workspace for a fork PR it does two things in a row: "remember where this contributor's copy lives" (git remote add), then "go download their branch" (git fetch). If the download fails — flaky network, private fork, deleted branch — the whole workspace creation gives up, but the remote we just wrote stayed in the repo forever. Nothing ever cleaned it up, because the cleanup only runs when you delete a workspace and no workspace was ever created. Retry three times, get three junk pr-* remotes.

Now, if the fetch fails, we take the remote back out.

Detail

prepareWorktreePushTargetWithExec (local) and prepareWorktreePushTargetSsh (SSH) both remote add then fetch, with no rollback. Flagged as a P2 residual during the readiness review of #15827; the SSH path only became reachable in that PR, so this is a good time to fix both.

Rollback is gated on remoteCreated — the flag already tracking whether this call added the remote — so a reused remote is never touched, whether Orca created it earlier or the user added it by hand. The rollback itself is best-effort (.catch(() => {})) so it can't mask the fetch error that actually aborted the create.

Tests

  • worktree-push-target-setup.test.ts — the local path removes a remote it just added on fetch failure, and leaves a reused remote alone. The stateful fake git now models remote remove, so the assertion is on real resulting state, not just the argv.
  • worktrees-ssh-fork-push-target-remote.test.ts — same for SSH through worktrees:create, with the provider's exec still routed through the real relay validator, and addWorktree asserted never to run.

Verified: full src/relay + src/main/ipc + src/shared suites (9,775 tests), oxlint, tsc -p config/tsconfig.node.json.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds shared validators for Git remote names and push-target URLs. Relay validation now permits only safe fork remote add and remove commands. Git mutation detection recognizes these commands. Worktree push-target setup removes newly created remotes after fetch failures while preserving existing remotes. SSH setup translates older relay authorization errors. Tests cover validation, remote lifecycle operations, rollback behavior, and SSH worktree creation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, implementation, tests, and verification, but it omits several required template sections and the required linked-issue format. Add the required What Changed, Why, Linked Issue with “Fixes #”, Visual Proof, AI Disclosure, Review, boundary, Notes, and Checklist sections.
✅ Passed checks (3 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 summarizes the primary change: removing a newly added fork remote when its fetch fails.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch nwparker/Error-invoking-remote-method-worktrees-create-Error-Destructive-git-remote-operations-are-not-allowed-via-exec

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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2fa4d8f5-0d1b-4d0b-9654-529a7cf8b492

📥 Commits

Reviewing files that changed from the base of the PR and between e7b047f and 759c8ba22122c69de57773066bd255771fcb46a6.

📒 Files selected for processing (11)
  • src/main/ipc/worktree-push-target-cleanup.test.ts
  • 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
  • src/relay/git-exec-validator.test.ts
  • src/relay/git-exec-validator.ts
  • src/relay/git-handler-fork-remote-exec.test.ts
  • src/shared/git-exec-mutation.test.ts
  • src/shared/git-exec-mutation.ts
  • src/shared/git-push-target-validation.ts

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

Comment on lines +111 to +113
if (remoteCreated) {
await execGit(['remote', 'remove', remoteName], repoPath).catch(() => {})
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Separate persistent remote ownership from invocation-local rollback state. Both setup paths use remoteCreated for two different meanings. A reused remote that another worktree owns can be removed when the new worktree fetch fails.

  • src/main/ipc/worktree-push-target-setup.ts#L111-L113: remove the remote only when this invocation added it.
  • src/main/ipc/worktree-remote.ts#L1126-L1128: apply the same rollback condition for SSH setup.
  • src/main/ipc/worktree-push-target-setup.test.ts#L217-L240: add a failed-fetch case where the reuse callback returns true, then assert no removal.
  • src/main/ipc/worktrees-ssh-fork-push-target-remote.test.ts#L215-L268: add the equivalent SSH case for a known owned remote, then assert no removal.
📍 Affects 4 files
  • src/main/ipc/worktree-push-target-setup.ts#L111-L113 (this comment)
  • src/main/ipc/worktree-remote.ts#L1126-L1128
  • src/main/ipc/worktree-push-target-setup.test.ts#L217-L240
  • src/main/ipc/worktrees-ssh-fork-push-target-remote.test.ts#L215-L268

Comment on lines +8 to +11
import {
isSafeGitRemoteName,
isSafePushTargetRemoteUrl
} from '../shared/git-push-target-validation'

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep the relay bundle independent.

src/relay is deployed as a separate bundle. This import crosses into the app-side src/shared bundle and can break remote relay deployment. Define the validators locally in src/relay and keep their rules synchronized with src/shared/git-push-target-validation.ts.

Based on learnings: avoid importing app-side modules, including shared constants, from src/relay.

Source: Learnings

Fork-PR setup adds the contributor's remote, then fetches the head. If that
fetch fails the create aborts, but the remote stayed behind with no owner:
cleanup only runs on worktree removal, and no worktree was ever created. Each
retry then left another orphaned pr-* remote.

Roll the remote back on fetch failure, on both the local and SSH paths, and
only when this call is what added it -- a reused remote (Orca-created or not)
is left alone.
@nwparker
nwparker force-pushed the nwparker/Error-invoking-remote-method-worktrees-create-Error-Destructive-git-remote-operations-are-not-allowed-via-exec branch from 759c8ba to 37be655 Compare August 22, 2026 04:19
@nwparker
nwparker merged commit a157f4c into main Aug 22, 2026
47 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
stablyai#15850)

Fork-PR setup adds the contributor's remote, then fetches the head. If that
fetch fails the create aborts, but the remote stayed behind with no owner:
cleanup only runs on worktree removal, and no worktree was ever created. Each
retry then left another orphaned pr-* remote.

Roll the remote back on fetch failure, on both the local and SSH paths, and
only when this call is what added it -- a reused remote (Orca-created or not)
is left alone.

(cherry picked from commit a157f4c)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
stablyai#15850)

Fork-PR setup adds the contributor's remote, then fetches the head. If that
fetch fails the create aborts, but the remote stayed behind with no owner:
cleanup only runs on worktree removal, and no worktree was ever created. Each
retry then left another orphaned pr-* remote.

Roll the remote back on fetch failure, on both the local and SSH paths, and
only when this call is what added it -- a reused remote (Orca-created or not)
is left alone.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
stablyai#15850)

Fork-PR setup adds the contributor's remote, then fetches the head. If that
fetch fails the create aborts, but the remote stayed behind with no owner:
cleanup only runs on worktree removal, and no worktree was ever created. Each
retry then left another orphaned pr-* remote.

Roll the remote back on fetch failure, on both the local and SSH paths, and
only when this call is what added it -- a reused remote (Orca-created or not)
is left alone.
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