Repository navigation
Fix fork PR/MR worktree creation race via durable review-head refs - #10429
Conversation
When creating a fork PR/MR worktree, concurrent `git fetch origin` operations clobber the shared FETCH_HEAD, causing the wrong commit to be checked out. Fetch PR/MR heads into dedicated per-review refs (`refs/orca/pull/<N>`, `refs/orca/merge-requests/<N>`) that persist and isolate each head from other fetches. Gracefully keep the compare-base when the fetch fails but the local ref already exists, avoiding silent fallback to the wrong branch on transient network errors.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change introduces durable local refs for GitHub pull request and GitLab merge request heads. Local repositories fetch review heads through explicit refspecs into 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/main/github/pr-start-point.ts (2)
93-127: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCompare-base fallback logic is duplicated in
orca-runtime.ts.
compareBaseRefResolvesLocally/fetchCompareBaseRefhere mirror the same pair inresolveManagedMrBase(src/main/runtime/orca-runtime.ts) almost line-for-line, including the same warning shape and "keep base only if locally resolvable" trade-off. Since both needed the identical fix in this PR, a shared helper (parameterized by ref/log-field names) would reduce the risk of the two copies drifting apart on the next bugfix.
129-152: 🚀 Performance & Scalability | 🔵 TrivialDurable per-PR refs are never pruned.
refs/orca/pull/<N>is created but never removed after use, so long-lived repos that resolve/create many PR worktrees over time will accumulate refs underrefs/orca/pull/*indefinitely. Worth a lightweight cleanup/gc strategy (e.g., prune on worktree removal or periodic sweep) so this durability guarantee doesn't turn into unbounded ref growth.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 43e74992-8015-41ad-94d1-d00ba99d3c27
📒 Files selected for processing (17)
src/main/github/pr-head-tracking-ref.test.tssrc/main/github/pr-head-tracking-ref.tssrc/main/github/pr-start-point-compare-base.test.tssrc/main/github/pr-start-point.test.tssrc/main/github/pr-start-point.tssrc/main/ipc/worktrees.test.tssrc/main/ipc/worktrees.tssrc/main/providers/ssh-git-provider.test.tssrc/main/providers/ssh-git-provider.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/relay/git-handler.test.tssrc/relay/git-handler.tssrc/shared/git-binary-compatibility.test.tssrc/shared/preferred-git-remote.test.tssrc/shared/preferred-git-remote.tssrc/shared/review-head-tracking-ref.ts
Prevent PR/MR creation from hanging when a remote is stalled or unreachable. Both GitHub and GitLab head fetches now enforce a 60-second timeout, matching the bound used in the create-path fetch. Durable refs (refs/orca/pull/*, refs/orca/merge-requests/*) decouple the ref from FETCH_HEAD, preserving legacy client semantics.
PR checks merge into main, which recently changed PowerShell launch args (cwd restore after profiles) and sparse-checkout detection (require core.sparseCheckout). Derive PowerShell spawn args from the production resolver, mock the sparse config flag, reset shared worktree list scan cache between tests, and stop requiring floating polls to avoid getRepos hydration.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/ipc/pty.test.ts (1)
231-245: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep the expected PowerShell argv independent of the implementation.
powerShellOsc133ArgsForCwd()derives the expected arguments by callingresolveWindowsShellLaunchArgsfromsrc/main/providers/windows-shell-args.ts. If that resolver regresses, this test’s expected value changes with it and can still pass. Keep an explicit fixture here and test the resolver’s exact output separately.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: da86d828-66dd-41be-85d1-c49a21cfb4cb
📒 Files selected for processing (3)
src/main/git/remove-worktree.test.tssrc/main/ipc/pty.test.tssrc/main/runtime/orca-runtime.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/runtime/orca-runtime.test.ts
- Unify PR review-head remote selection: local and SSH GitHub paths share
resolveGitHubReviewHeadRemote, which prefers the remote mapping to the
hosting GitHub project (upstream before origin, matching work-item/API
candidate order) so contributor clones fetch refs/pull from the repo
that actually hosts the PR.
- Soft-keep durable review heads: when the PR/MR head fetch fails but
refs/orca/pull/<N> / refs/orca/merge-requests/<iid> still resolves,
keep the pinned SHA (warn) instead of failing resolve, mirroring the
compare-base fallback. Extracted shared compare-base soft-keep into
compare-base-ref-fetch.ts.
- Extract fetchGitLabMergeRequestHeadRef (local + SSH) parallel to the
GitHub helper; bound its local fetch with the shared 60s timeout.
- Share relay-style fetch validation (positive safe-integer id, remote
not starting with "-") between relay and local helpers via
review-head-tracking-ref.ts; move REVIEW_HEAD_FETCH_TIMEOUT_MS there.
- Drop the githubPullRequestHeadLocalRef re-export; resolve head SHAs via
rev-parse --verify <ref>^{commit}.
- Add GitLab anti-FETCH_HEAD regression test plus durable-head soft-keep
and remote-selection unit tests.
Co-authored-by: Orca <[email protected]>
Main's headless tab hydrate (#9343) skips worktree keys whose repo is not in getRepos. Retirement tests that rebuild mobile tabs from a persisted session now advertise the fixture repo as live so PR Checks merge stays green.
Main's SSH external-image wiring (#10323) pushed RichMarkdownEditor.tsx over the 400-line tsx budget, failing PR Checks lint on every merge into main. Move the props type into a sibling module so the component stays under the limit without disabling max-lines.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime-terminal-retirement.test.ts (1)
24-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid casting the test store to
never.
runtimeStorereturns an object but advertisesnever, so TypeScript cannot validate that this fixture still satisfies theOrcaRuntimeServicestorage contract. Use the constructor’s store type or a narrow explicit test-double interface, keeping any unavoidable cast at one boundary.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3b387be0-5395-4893-b399-b7960a3548fe
📒 Files selected for processing (7)
src/main/ipc/worktrees.test.tssrc/main/ipc/worktrees.tssrc/main/runtime/orca-runtime-terminal-retirement.test.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/renderer/src/components/editor/RichMarkdownEditor.tsxsrc/renderer/src/components/editor/rich-markdown-editor-props.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/main/runtime/orca-runtime.ts
- src/main/ipc/worktrees.test.ts
- src/main/runtime/orca-runtime.test.ts
- src/main/ipc/worktrees.ts
Embed remote name + URL hash into refs/orca/pull|merge-requests refs to prevent soft-keep from serving wrong project's PR/MR when FETCH_HEAD is clobbered by concurrent fetch. Fetch functions now return the written ref path (writer-authoritative) so callers rev-parse exactly what was fetched, not re-derive identity. Soft-keep only applies to transient errors (timeout, network); fails hard on missing refs, auth failures, and stale relay. Relay returns localRef so client avoids re-hashing (URL normalization can disagree).
…10443) #9343 broke two contracts at once and #10437 fixed both, but neither is asserted: #10429 repaired the failing tests by deleting the poll assertion and by handing the retirement store a live repo, so a revert would land silently. Restore `expect(getRepos).not.toHaveBeenCalled()` on the floating-tab poll, and add a hydrate case for a store that cannot report repos. Verified both fail against the pre-#10437 code: the poll assertion reports getRepos "called 2 times", and the hydrate case returns [] instead of the persisted tab.
…tablyai#10429) * Fix fork PR/MR worktree creation race via durable review-head refs When creating a fork PR/MR worktree, concurrent `git fetch origin` operations clobber the shared FETCH_HEAD, causing the wrong commit to be checked out. Fetch PR/MR heads into dedicated per-review refs (`refs/orca/pull/<N>`, `refs/orca/merge-requests/<N>`) that persist and isolate each head from other fetches. Gracefully keep the compare-base when the fetch fails but the local ref already exists, avoiding silent fallback to the wrong branch on transient network errors. * Bound PR/MR head fetches with 60s timeout Prevent PR/MR creation from hanging when a remote is stalled or unreachable. Both GitHub and GitLab head fetches now enforce a 60-second timeout, matching the bound used in the create-path fetch. Durable refs (refs/orca/pull/*, refs/orca/merge-requests/*) decouple the ref from FETCH_HEAD, preserving legacy client semantics. * test: align CI expectations with main PowerShell/sparse regressions PR checks merge into main, which recently changed PowerShell launch args (cwd restore after profiles) and sparse-checkout detection (require core.sparseCheckout). Derive PowerShell spawn args from the production resolver, mock the sparse config flag, reset shared worktree list scan cache between tests, and stop requiring floating polls to avoid getRepos hydration. * Address review follow-ups on durable review-head refs - Unify PR review-head remote selection: local and SSH GitHub paths share resolveGitHubReviewHeadRemote, which prefers the remote mapping to the hosting GitHub project (upstream before origin, matching work-item/API candidate order) so contributor clones fetch refs/pull from the repo that actually hosts the PR. - Soft-keep durable review heads: when the PR/MR head fetch fails but refs/orca/pull/<N> / refs/orca/merge-requests/<iid> still resolves, keep the pinned SHA (warn) instead of failing resolve, mirroring the compare-base fallback. Extracted shared compare-base soft-keep into compare-base-ref-fetch.ts. - Extract fetchGitLabMergeRequestHeadRef (local + SSH) parallel to the GitHub helper; bound its local fetch with the shared 60s timeout. - Share relay-style fetch validation (positive safe-integer id, remote not starting with "-") between relay and local helpers via review-head-tracking-ref.ts; move REVIEW_HEAD_FETCH_TIMEOUT_MS there. - Drop the githubPullRequestHeadLocalRef re-export; resolve head SHAs via rev-parse --verify <ref>^{commit}. - Add GitLab anti-FETCH_HEAD regression test plus durable-head soft-keep and remote-selection unit tests. Co-authored-by: Orca <[email protected]> * test: supply live getRepos for terminal-retirement hydrates Main's headless tab hydrate (stablyai#9343) skips worktree keys whose repo is not in getRepos. Retirement tests that rebuild mobile tabs from a persisted session now advertise the fixture repo as live so PR Checks merge stays green. * fix(editor): extract RichMarkdownEditor props to stay under max-lines Main's SSH external-image wiring (stablyai#10323) pushed RichMarkdownEditor.tsx over the 400-line tsx budget, failing PR Checks lint on every merge into main. Move the props type into a sibling module so the component stays under the limit without disabling max-lines. * Make durable review-head refs remote-identity scoped Embed remote name + URL hash into refs/orca/pull|merge-requests refs to prevent soft-keep from serving wrong project's PR/MR when FETCH_HEAD is clobbered by concurrent fetch. Fetch functions now return the written ref path (writer-authoritative) so callers rev-parse exactly what was fetched, not re-derive identity. Soft-keep only applies to transient errors (timeout, network); fails hard on missing refs, auth failures, and stale relay. Relay returns localRef so client avoids re-hashing (URL normalization can disagree). --------- Co-authored-by: Orca <[email protected]>
…tablyai#10443) stablyai#9343 broke two contracts at once and stablyai#10437 fixed both, but neither is asserted: stablyai#10429 repaired the failing tests by deleting the poll assertion and by handing the retirement store a live repo, so a revert would land silently. Restore `expect(getRepos).not.toHaveBeenCalled()` on the floating-tab poll, and add a hydrate case for a store that cannot report repos. Verified both fail against the pre-stablyai#10437 code: the poll assertion reports getRepos "called 2 times", and the hydrate case returns [] instead of the persisted tab.
Summary
Fix a race condition in fork PR/MR worktree creation where concurrent
git fetchoperations clobber the sharedFETCH_HEADref, causing the worktree to resolve to the wrong commit (typically the default branch tip instead of the PR/MR head).The fix replaces reliance on the transient
FETCH_HEADwith durable per-review refs (refs/orca/pull/<N>andrefs/orca/merge-requests/<N>) that persist between resolve and create operations, preventing concurrent fetches from interfering with each other.Changes
review-head-tracking-ref.tsfor durable ref paths andpreferred-git-remote.tsfor intelligent remote selection (prefer origin)git.fetchGitHubPullRequestHeadandgit.fetchGitLabMergeRequestHeadRef(versioned to detect old relays)FETCH_HEADfetchGitHubPullRequestHead()and updatesfetchGitLabMergeRequestHead()with old-relay detection and reconnect promptsTesting
pr-start-point-compare-base.test.tscovering fork PR compare-base scenarios under transient fetch failures and missing basesrev-parseagainst new ref paths instead ofFETCH_HEADNotes