Repository navigation
test(git): pin FETCH_HEAD lock order in the admission lifetime test - #17641
Conversation
`serializes FETCH_HEAD callers before they enter admission` assumed that two same-repo fetches join the FETCH_HEAD lock lane in call order. They do not. `runWithGitFetchHeadLock` first `await`s `fetchLockPath`, which walks the filesystem (`realpath`, `stat` per parent directory, `readFile` of `commondir`, `realpath` again) before it calls `runWithGitOperationLock`, and the lane is registered only after that walk resolves. For a non-existent `/repo` that is five libuv threadpool round-trips per caller. Two callers issued back to back run their chains concurrently, so lane order is threadpool completion order, not call order. When the `interactive` fetch won that race it entered the lane ahead of the `background` fetch. On the first caller's release it reached admission immediately and, being interactive, took the free network headroom slot instead of queueing, while the background fetch stayed parked on the lock. `queued` therefore settled at 0 and never reached the asserted 1. Measured inversion rate for the bare lock-path walk was 54/500 on an idle machine; the test itself failed 5/20 locally, always at the same assertion, matching the two CI failures on unrelated PRs (stablyai#17530, stablyai#17630) at the same line. Fix the premise rather than the symptom: stub only the key derivation, keeping the real FIFO `runWithGitOperationLock` that the test actually exercises, so the lane is registered synchronously with the call. Key derivation keeps its own coverage in `src/shared/git-fetch-head-lock.test.ts`. This also stops the fetch tests in this file from sharing one global `/.git/FETCH_HEAD` lane with each other and from touching the real filesystem. Verified deterministic: 40/40, then 30/30 clean runs, plus 25/25 with twelve CPU hogs and a concurrent `src/main/git/command-runner/` run saturating the box.
Greptile SummaryThe PR makes FETCH_HEAD admission-lifetime tests deterministic by mocking only asynchronous lock-key derivation while retaining the real FIFO operation lock.
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness or test-validity issues identified. The mock keeps the real operation-lock implementation, and every affected test uses identical worktree paths for callers expected to share a FIFO lane.
|
| Filename | Overview |
|---|---|
| src/main/git/command-runner/git-exec-admission-lifetime.test.ts | Adds a narrowly scoped module mock that preserves the tested FIFO lock semantics for all current same-path fetch scenarios. |
Reviews (1): Last reviewed commit: "test(git): pin FETCH_HEAD lock order in ..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe test adds a type-only import for the Git FETCH_HEAD lock module. It mocks Merge Risk: ⚪ Minimal · up to This change makes the Git admission lifetime test deterministic without changing production behavior or user-facing functionality. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. Full details: Description checkExplanation The description gives strong root-cause, fix, and validation details, but it does not follow the required template. It omits the required Linked Issue, Visual Proof with an explicit N/A statement, Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Resolution Update the description to include all required template sections. Add the issue link after
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.
✅ No new issues found.
Reviewed changes
- Pin FETCH_HEAD lock order in the admission lifetime test — the test now mocks
runWithGitFetchHeadLockto delegate straight torunWithGitOperationLock(worktreePath, signal, run), so same-repo fetch callers register the lock lane synchronously in call order instead of in libuv threadpool completion order.
The fix is sound: the FIFO lock under test stays real (only the fs key walk is stubbed), resolveGitFetchHeadCommand is preserved through ...actual, and the key derivation retains its own coverage in src/shared/git-fetch-head-lock.test.ts (including linked-worktree and symlink serialization). The two tests that exercise the lock (/repo and /same-repo) still share a lane via their cwd key, so the serialization premise holds. Verified locally: the file passes 10/10 consecutive runs, and oxlint reports 0 warnings/errors on the changed file.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…tablyai#17641) `serializes FETCH_HEAD callers before they enter admission` assumed that two same-repo fetches join the FETCH_HEAD lock lane in call order. They do not. `runWithGitFetchHeadLock` first `await`s `fetchLockPath`, which walks the filesystem (`realpath`, `stat` per parent directory, `readFile` of `commondir`, `realpath` again) before it calls `runWithGitOperationLock`, and the lane is registered only after that walk resolves. For a non-existent `/repo` that is five libuv threadpool round-trips per caller. Two callers issued back to back run their chains concurrently, so lane order is threadpool completion order, not call order. When the `interactive` fetch won that race it entered the lane ahead of the `background` fetch. On the first caller's release it reached admission immediately and, being interactive, took the free network headroom slot instead of queueing, while the background fetch stayed parked on the lock. `queued` therefore settled at 0 and never reached the asserted 1. Measured inversion rate for the bare lock-path walk was 54/500 on an idle machine; the test itself failed 5/20 locally, always at the same assertion, matching the two CI failures on unrelated PRs (stablyai#17530, stablyai#17630) at the same line. Fix the premise rather than the symptom: stub only the key derivation, keeping the real FIFO `runWithGitOperationLock` that the test actually exercises, so the lane is registered synchronously with the call. Key derivation keeps its own coverage in `src/shared/git-fetch-head-lock.test.ts`. This also stops the fetch tests in this file from sharing one global `/.git/FETCH_HEAD` lane with each other and from touching the real filesystem. Verified deterministic: 40/40, then 30/30 clean runs, plus 25/25 with twelve CPU hogs and a concurrent `src/main/git/command-runner/` run saturating the box.

Root cause
git-exec-admission-lifetime.test.ts>serializes FETCH_HEAD callers before they enter admissionassumed that two same-repo fetches issued back to back join the FETCH_HEAD lock lane in call order. They do not.runWithGitFetchHeadLockfirstawaitsfetchLockPath, which walks the filesystem —realpath(worktree), astatper parent directory up to/,readFileofcommondir, thenrealpathagain — and only callsrunWithGitOperationLock(which registers the lane synchronously) after that walk resolves. For the test's non-existent/repothat is five libuv threadpool round-trips per caller. The two callers run their chains concurrently, so lane order is threadpool completion order, not call order.When the
interactivefetch won that race, it entered the lock lane ahead of thebackgroundfetch. As soon as the first fetch released the lock,interactivereached admission, and because its tier is interactive it took the free network headroom slot immediately instead of queueing — while thebackgroundfetch stayed parked on the lock and never entered admission at all. Soqueuedsettled at0and never reached the asserted1, andvi.waitFortimed out.Instrumented failure state confirms it exactly:
This is a test-premise defect, not a scheduler bug. The scheduler behaved correctly in both orderings; only one of the two orderings matches what the test asserts.
Evidence it was a flake, not a regression
node_modulessource maps) and ci(release): publish main-process source maps with each release #17630 (YAML workflow only) — two changes that cannot touch git admission.git-exec-admission-lifetime.test.ts:221:75,AssertionError: expected +0 to be 1, with 1 failed / ~899 passed.main: 5/20 failures, always at 221:75 with the same message.Fix
Fix the premise rather than the symptom — no timeout bump, no retry, no weakened assertion. The test file now stubs only the FETCH_HEAD key derivation, delegating to the real
runWithGitOperationLock. The FIFO lock that the test actually exercises stays real, and the lane is now registered synchronously with the call, so lock order is call order.Key derivation keeps its own coverage in
src/shared/git-fetch-head-lock.test.ts; this file has never been the place that verifies it. Two incidental improvements fall out: the fetch tests in this file no longer share one global/.git/FETCH_HEADlane with each other, and they no longer issue real filesystem syscalls against/from a unit test.Determinism proof
git-exec-admission-lifetime.test.tsalonesrc/main/git/command-runner/vitest runsrc/main/git/command-runner/directorysrc/shared/git-fetch-head-lock.test.ts(unaffected)pnpm exec oxlinton the changed file andpnpm tcboth clean.Follow-up worth considering (not in this PR)
The same fs-walk race exists in production: two same-repo fetches acquire the FETCH_HEAD lock in threadpool completion order rather than call order. It is not a correctness bug — mutual exclusion still holds — and the exposure is narrow: it only shuffles arrivals issued within the same sub-millisecond window, since outside that window the walk completes in call order anyway.
Worth being precise about what a fix would and would not buy, so nobody over-values it:
runWithGitOperationLockis pure FIFO with no tier awareness at all, so the FETCH_HEAD lock already sits as a priority inversion in front of the tiered, aging-aware admission scheduler by design — an interactive fetch issued after a background fetch on the same repo waits behind it regardless. Memoizing the in-flight lock-path resolution per worktree would make lane order deterministic and skip a repeated 5-syscall walk per fetch; it would not restore tiered priority. That would take a tier-aware FETCH_HEAD lock, which is a much larger design. Left out here because sharing an in-flight resolution across callers with differentAbortSignals needs its own design too.