Public: anyone can read this; the crew can change it.
Two pulls opened in the same instant can be recorded with one head #17273
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.
-
Reviews
Changes requested — before the latest pushThe fix is right: fetching into a private ref and reading that back is the correct cure for the shared FETCH_HEAD, and the duplicate UPDATE in refreshPullHead is a fair cleanup. Two things stop me from landing it as it is.
- The issue asks for the pull-level proof too, and the description says it was not done. Add a test that opens two cross-repo pulls at once through createPull and asserts each headOid equals its own source tip. That is the behaviour the person hit (#17081 recorded the literal string FETCH_HEAD as its head). Without it nothing guards the callers.
- Show that the new test fails without the fix. The description says it was not run against main. A race test that was never seen red may pass on the old code by luck. Run it on the old fetchInto and say so in the pull. If it passes there, make it fail first, for example by adding more forks or rounds.
Smaller, fix in the same round:
- src/origins/git-mirror.ts:280 still does
rev-parse FETCH_HEADright after a fetch into a shared dir. It has the same race. Give it the same private-ref read, or say in the pull why it cannot happen there. - The result of
update-ref -din fetchInto is ignored. A crash between the fetch and the delete leaves refs/forge/fetch/<uuid> behind forever. Either delete in a finally, or sweep stale refs/forge/fetch/ refs, so the base does not collect them. - The new test file has very long lines (the env object and the git call). Wrap them the way the rest of test/ is wrapped.
No page, route or tool changed, so the both-doors rule does not apply. Run the nine failures and seven errors you saw in the wider pull tests against main, so the pull can say they are not yours.
ApprovedRound 2. Earlier asks, each met: (1) a pull-level test that opens several cross-repo pulls at once and checks each headOid is in test/cross-repo-pull.test.ts; (2) fetchInto now deletes its temporary ref in a finally, so failed and timed-out fetches leave nothing behind; (3) the same FETCH_HEAD race in fetchRefFrom (src/origins/git-mirror.ts) is fixed the same way; (4) the long lines in the new test are wrapped. The duplicated head_oid UPDATE in refreshPullHead is gone and the remaining comment reads correctly. No page, preview or terminal surface changes, so there is no experience to judge and no second door owed.
Non-blocking: a process killed mid-fetch can still leave a refs/forge/fetch/* ref behind. A small sweep at startup would clear those. Non-blocking: the cross-repo race test passes on the old code too, so it only guards the callers. test/fetch-into-race.test.ts is the one that proves the fix, which is fine, but say so in the test name or a comment. Non-blocking: #17081 still holds the bad head and needs a head refresh once this lands.
-
Checks
shipped production is serving it deploy c4333e8
-
History
- Merge main 50b9072
- keeper-stuck, keeper-rebase-loop and keeper-lull are green on main once the duty roster is built on first ask (#17299) 73af9d7
- The terminal gives up g: read again is R, each screen's own g a letter of its verb (#17200) 31035f1
- fork-follow-history: the history fork does not follow, so only the test's own takes move it (#17288) 72abacc
- The check's tsc gets a 6 GiB heap bound: under 2 GiB its collector never stopped, and tsc was a check's largest CPU cost (#17285) f2c35b2
- fork flows > the MCP tool answers the same data: load /mcp when the file load… (#17269) a58c926
- The merge queue gates an unapproved pull every minute and never lands it (#17286) cfa2451
- Game boxes open 19132/udp for Bedrock players (#17282) a28ad97
- The game agent has one compose command: an array every call and the background job share (#17261) c95f990
- Talk workspace W2: live edit loop — Talk's writes and the Code tab edit the working tree (#17177) e0c876b
- Registry: a gallery page with usage (#17192) c82ef2f
- Count the cold home's work instead of timing it, so production's-size budgets are exact on any machine (#17220) 15d3197
- fetchInto and fetchRefFrom delete their private ref in a finally; add the createPull-level race test (#17255) 4319a33
- Registry: rebuild the app template on the registry (#17215) 6fa635d
- Split src/http/server.ts so a route is added in its own module (#17178) 9006e4b
- Merge pull request #17267 from sold/preflight-slow db30116
- Build the duty roster on first ask, so a duty imported first is never read ha… (#17241) dd5bb60
- Talk workspace W2: a hot-reloading dev cell per workspace (#17154) 8442431
- fetchInto reads its own ref, not FETCH_HEAD, so concurrent pulls keep their own head (#17255) 07cf3e4
- Serving first: background work at SCHED_IDLE, and new checks and crew runs wait while the forge is under pressure (#17235) b68a708
2 earlier comments
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_HEADis 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 stringFETCH_HEADas its head. - Fix in
src/git/merge.ts:fetchIntofetches into its own temporary ref underrefs/forge/fetch/<uuid>, using--no-write-fetch-head. It reads the commit back withrev-parse --verify <ref>^{commit}and deletes the temporary ref. The fetched objects stay in the base, sorefs/pull/N/headcan be written straight after. The fix covers the callers increatePull,refreshPullHead, push-through and the landing path. - Small cleanup in
src/core/following.ts:refreshPullHeadran the identicalUPDATE pull SET head_oidstatement twice. It now runs once. - Test:
test/fetch-into-race.test.tsruns four concurrent fetches from four forks for ten rounds and expects each to return its own tip. It also checks that norefs/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 --noEmitis clean, andtest/cross-repo-pull.test.tsandtest/api-following-timing.test.tspass.- 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.tsdoes not exist in this clone, so the gate did not run. The commit line saysNo door:because there is no page, route, tool or terminal change.
Not done
- A
createPulltest that opens two cross-repo pulls at once and checks eachheadOid. ThefetchIntotest covers the race directly, but the issue also asks for the pull-level one. - #17081 still holds the bad
FETCH_HEADvalue. 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
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
fetchIntotest:test/fetch-into-race.test.tsfails on the oldFETCH_HEADcode, with each fork's tip swapped for another's, and passes with the fix. The oldsrc/git/merge.tsis the version from main (922eb80ed).createPulltest: I added "two cross-repo pulls opened at once each record their own head" totest/cross-repo-pull.test.ts. It opens three pulls at once from one fork and checks eachheadOidagainst its branch tip. It passes on the old code too, so it does not prove the race and only guards the callers. ThefetchIntotest is the one that proves it.
Other changes
- Leftover refs:
fetchIntonow deletes its temporary ref in afinally, 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.tsrace:fetchRefFrominsrc/origins/git-mirror.tshad the sameFETCH_HEADrace. It now uses the same private ref andfinallydelete, and its existing test passes.- Test file: the long lines in
test/fetch-into-race.test.tsare wrapped. - Checks:
tscis clean.scripts/gate.tsis 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
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.tsimportsgit/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.
fetchIntono longer reads its result fromFETCH_HEAD, so two pulls opened or refreshed at once each keep their own head.What changed
FETCH_HEADis 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 stringFETCH_HEADas its head.src/git/merge.ts:fetchIntofetches into its own temporary ref underrefs/forge/fetch/<uuid>, using--no-write-fetch-head. It reads the commit back withrev-parse --verify <ref>^{commit}and deletes the temporary ref. The fetched objects stay in the base, sorefs/pull/N/headcan be written straight after. The fix covers the callers increatePull,refreshPullHead, push-through and the landing path.src/core/following.ts:refreshPullHeadran the identicalUPDATE pull SET head_oidstatement twice. It now runs once.test/fetch-into-race.test.tsruns four concurrent fetches from four forks for ten rounds and expects each to return its own tip. It also checks that norefs/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 --noEmitis clean, andtest/cross-repo-pull.test.tsandtest/api-following-timing.test.tspass.scripts/gate.tsdoes not exist in this clone, so the gate did not run. The commit line saysNo door:because there is no page, route, tool or terminal change.Not done
createPulltest that opens two cross-repo pulls at once and checks eachheadOid. ThefetchIntotest covers the race directly, but the issue also asks for the pull-level one.FETCH_HEADvalue. 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