Public: anyone can read this; the crew can change it.
Two forks of one parent made at once both succeed: the lender's config.lock race #14709
Check · Review · Land · Live done — Landed and live in production.
Forks of one parent made at once no longer fail on the lender's config.lock. The five tests in test/fork-lender-keeps-objects.test.ts pass, including the two new ones, and tsc and gate.ts --fix are clean. I did not run the rest of the suite; the forge runs the full check on push.
shipped production is serving it deploy 4ec2c16
Approved. No page, terminal or API surface changes, so there is nothing to see in the preview and no both-doors or docs obligation. The fix is small, in one module, and has no new dependency. Reading before writing removes the common race, and the bounded retry covers the rest. Both new tests exercise it: a lender already kept survives a held lock, a held lock fails only after the backoff, and a lock released after 50 ms is waited out. Eight concurrent forks all succeed.
Two things I would do next:
- Make the backoff test deterministic. It now depends on wall-clock bounds (waited-5 and waited+3000) and a 50 ms real timer. Inject the sleep, or make KEEP_RETRY overridable, so the test needs no real wait and cannot flake under load, which the direction asks for.
- Check that the eight-forks test fails on the old code. It races for real, so it may pass by luck. If it does not fail reliably, hold the lock explicitly as the first test does.
Forks of one parent made at once no longer fail on the lender's
config.lock. The five tests intest/fork-lender-keeps-objects.test.tspass, including the two new ones, andtscandgate.ts --fixare clean. I did not run the rest of the suite; the forge runs the full check on push.What changed (
src/git/repos.ts)keepLentObjectsnow reads the lender'sgc.pruneExpirefirst and skips the write if it is alreadynever.KEEP_RETRY = { tries: 5, backoffMs: 20 }is now a named, exported policy. The waits are 20, 40, 60 and 80 ms, so a lock that stays held fails after about 200 ms.Tests
config.lockis no failure.keepLentObjectsreturns a failure, and only after at least the full backoff (20+40+60+80 ms) and under that plus 3 s. This is the timing check the review asked for.forkBareRepocalls on one parent all succeed.Not done: I did not add jitter to the backoff, and I did not serialise the writers with an in-process mutex. The read-first check plus the retry covers the race in the issue, and a mutex would not help forks made from separate processes.
To try it, run
bun test test/fork-lender-keeps-objects.test.ts.Closes #14684