beads/internal/workspacegate
Julian Knutsen 685cf848bd
fix(gate): a budget spent during the intent probe still gets the final attempt (#7237)
A farm run of TestAcquireAllExhaustedBudgetFinalAttemptIgnoresIntent
(#7225) failed with "held by a bd maintenance operation queued for
exclusive access" for a gate that was free: a real product race that broke
the guarantee that queued maintenance can delay a shared acquirer but never
fail it.

Acquire decided whether an attempt was final from the clock at the top of
the iteration, then probed the intent lock (open + flock + reading the
sidecar). On a starved machine the probe can take longer than the budget
that was left, so the iteration deferred as "not final", found the budget
spent, and returned ErrBusy without ever trying the gate. Now a deferral
can never end the acquisition: if the budget ran out while deferring, the
loop makes one more attempt at the gate that ignores the queue, and only a
gate that is really held can fail it.

Tests:
- TestSharedFinalAttemptSurvivesStallDuringIntentProbe stalls the
  acquirer past its deadline right after the deferral decision (a
  test-only hook), so the race is reproduced deterministically for both
  Acquire and AcquireAll; it fails with the farm's exact message without
  the fix.
- TestAcquireAllExhaustedBudgetFinalAttemptIgnoresIntent no longer
  releases gate a from a timer racing the budget (a second load-dependent
  failure mode seen in the repro); a is released synchronously after the
  call.

Under load (Bazel server pinned to 2 CPUs with taskset, 32 concurrent test
jobs, race detector): the original test failed 71/200 runs (-test.count=20);
with the fix both tests pass 200/200 (-test.count=10), and the whole
workspacegate_test passes 200/200.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 12:57:09 -07:00
..
BUILD.bazel test(bazel): fully green //..., tag taxonomy + docker lane, sharding, test sandbox ceiling (#6871) 2026-09-27 20:19:38 -07:00
gate.go fix(gate): a budget spent during the intent probe still gets the final attempt (#7237) 2026-10-05 12:57:09 -07:00
gate_test.go fix(gate): a budget spent during the intent probe still gets the final attempt (#7237) 2026-10-05 12:57:09 -07:00