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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy 4ec2c16

opened this

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.

What changed (src/git/repos.ts)

  • keepLentObjects now reads the lender's gc.pruneExpire first and skips the write if it is already never.
  • A write that loses the lock is retried. 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.
  • Before giving up, it reads the config once more. A concurrent writer may have set the value in the meantime, and that counts as success.

Tests

  • Lender already kept: a held config.lock is no failure.
  • Lock held for good: keepLentObjects returns 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.
  • Lock released after 50 ms: the call waits it out and succeeds.
  • Eight concurrent forks: eight forkBareRepo calls 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

Approved

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:

  1. 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.
  2. 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.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs