Public: anyone can read this; the crew can change it.

Two pulls opened in the same instant can be recorded with one head #17273

opened this

Merged 32h 54m ago, live in production

fetchInto no longer reads its result from FETCHHEAD, so two pulls opened or refreshed at once each keep their own head. What changed Cause: FETCHHEAD is one file per repository, so concurrent fetches into the same base read whichever tip was written last.

Notes

opened this

fetchInto no longer reads its result from FETCH_HEAD, so two pulls opened or refreshed at once each keep their own head.

What changed

  • Cause: FETCH_HEAD is one file per repository, so concurrent fetches into the same base read whichever tip was written last. It can also be momentarily empty, which is how #17081 recorded the literal string FETCH_HEAD as its head.
  • Fix in src/git/merge.ts: fetchInto fetches into its own temporary ref under refs/forge/fetch/<uuid>, using --no-write-fetch-head. It reads the commit back with rev-parse --verify <ref>^{commit} and deletes the temporary ref. The fetched objects stay in the base, so refs/pull/N/head can be written straight after. The fix covers the callers in createPull, refreshPullHead, push-through and the landing path.
  • Small cleanup in src/core/following.ts: refreshPullHead ran the identical UPDATE pull SET head_oid statement twice. It now runs once.
  • Test: test/fetch-into-race.test.ts runs four concurrent fetches from four forks for ten rounds and expects each to return its own tip. It also checks that no refs/forge/ ref is left behind and the fetched commit stays readable. The test passes with the fix. I did not run it on main, so I haven't confirmed it fails there.

Checks

  • bun x tsc --noEmit is clean, and test/cross-repo-pull.test.ts and test/api-following-timing.test.ts pass.
  • A broader run of the pull-related test files, matched by file-name pattern, showed 9 failures and 7 errors. I did not look at them or compare against main, so whether they are unrelated is unconfirmed.
  • scripts/gate.ts does not exist in this clone, so the gate did not run. The commit line says No door: because there is no page, route, tool or terminal change.

Not done

  • A createPull test that opens two cross-repo pulls at once and checks each headOid. The fetchInto test covers the race directly, but the issue also asks for the pull-level one.
  • #17081 still holds the bad FETCH_HEAD value. It needs its head re-read, through a push to its branch or a head refresh, once this lands.

Try it: bun test test/fetch-into-race.test.ts

🤖 Generated with Claude Code

Closes #17255

2 earlier comments
commented

fetchInto no longer reads its result from FETCH_HEAD, so two pulls opened or refreshed at once each keep their own head.

What changed

  • Cause: FETCH_HEAD is one file per repository, so concurrent fetches into the same base read whichever tip was written last. It can also be momentarily empty, which is how #17081 recorded the literal string FETCH_HEAD as its head.
  • Fix in src/git/merge.ts: fetchInto fetches into its own temporary ref under refs/forge/fetch/<uuid>, using --no-write-fetch-head. It reads the commit back with rev-parse --verify <ref>^{commit} and deletes the temporary ref. The fetched objects stay in the base, so refs/pull/N/head can be written straight after. The fix covers the callers in createPull, refreshPullHead, push-through and the landing path.
  • Small cleanup in src/core/following.ts: refreshPullHead ran the identical UPDATE pull SET head_oid statement twice. It now runs once.
  • Test: test/fetch-into-race.test.ts runs four concurrent fetches from four forks for ten rounds and expects each to return its own tip. It also checks that no refs/forge/ ref is left behind and the fetched commit stays readable. The test passes with the fix. I did not run it on main, so I haven't confirmed it fails there.

Checks

  • bun x tsc --noEmit is clean, and test/cross-repo-pull.test.ts and test/api-following-timing.test.ts pass.
  • A broader run of the pull-related test files, matched by file-name pattern, showed 9 failures and 7 errors. I did not look at them or compare against main, so whether they are unrelated is unconfirmed.
  • scripts/gate.ts does not exist in this clone, so the gate did not run. The commit line says No door: because there is no page, route, tool or terminal change.

Not done

  • A createPull test that opens two cross-repo pulls at once and checks each headOid. The fetchInto test covers the race directly, but the issue also asks for the pull-level one.
  • #17081 still holds the bad FETCH_HEAD value. It needs its head re-read, through a push to its branch or a head refresh, once this lands.

Try it: bun test test/fetch-into-race.test.ts

🤖 Generated with Claude Code

commented

I've pushed the changes for all the review points except the nine failures and seven errors in the wider run. I did not run those against main, so I can't say they aren't mine. The wider run passed the argument test/cross-repo-pull.test.ts test/api-following-timing.test.ts, and the runner reported 135 tests across 38 files. I did not find out why. test/cross-repo-pull.test.ts and test/api-following-timing.test.ts pass when run on their own.

Where the new test goes red

  • fetchInto test: test/fetch-into-race.test.ts fails on the old FETCH_HEAD code, with each fork's tip swapped for another's, and passes with the fix. The old src/git/merge.ts is the version from main (922eb80ed).
  • createPull test: I added "two cross-repo pulls opened at once each record their own head" to test/cross-repo-pull.test.ts. It opens three pulls at once from one fork and checks each headOid against its branch tip. It passes on the old code too, so it does not prove the race and only guards the callers. The fetchInto test is the one that proves it.

Other changes

  • Leftover refs: fetchInto now deletes its temporary ref in a finally, so a failed or timed-out fetch no longer leaves one. A process that dies mid-fetch can still leave one behind, and there is no sweep for those.
  • git-mirror.ts race: fetchRefFrom in src/origins/git-mirror.ts had the same FETCH_HEAD race. It now uses the same private ref and finally delete, and its existing test passes.
  • Test file: the long lines in test/fetch-into-race.test.ts are wrapped.
  • Checks: tsc is clean. scripts/gate.ts is absent in this clone, so the gate did not run.

#17081 still holds the bad FETCH_HEAD value until its head is refreshed.

🤖 Generated with Claude Code

commented

Concurrent fetches into one repository no longer read each other's tip. Each fetch now writes to its own temporary ref (refs/forge/fetch/<uuid>) and reads the tip from that. It deletes the ref afterwards, including when the fetch fails or times out. This replaces the shared FETCH_HEAD file, which two simultaneous fetches would overwrite. The change is in fetchInto (src/git/merge.ts) and fetchRefFrom (src/origins/git-mirror.ts).

I also removed a duplicated UPDATE pull SET head_oid (with its comment) in refreshPullHead; the other copy stays. New tests: test/fetch-into-race.test.ts and a race case in test/cross-repo-pull.test.ts.

I didn't reproduce the check's three failures, and I don't think this change causes any of them:

  • test/fork-follow-history.test.ts: it passed on three repeated runs locally, and again after merging main.
  • Terminal "assign" test: it failed at the 30-second timeout in a shard, which looks like load. I didn't run it locally.
  • test/git-sweep-14780.test.ts: it is red on main too. apps/dev_launch.ts imports git/local.ts, which that test forbids. I left it alone because it is outside this issue.

I merged main into the branch and pushed, because rebasing would have needed a force push. bun x tsc --noEmit is clean, and the tests for this change pass.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs