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

A cross-repo pull's head_oid row lags its ref while carryApproval runs, so a concurrent refresh reads the old head #12871

Merged opened this

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

Merged

refreshPullHead now writes pull.headoid immediately after writeRef, before the carryApproval await. A concurrent refresh that finds the ref already moved now reads the new head from the row, not the old one. Change: the row update moved up in src/core/following.ts.

Notes

shipped production is serving it deploy c36cfce

opened this

refreshPullHead now writes pull.head_oid immediately after writeRef, before the carryApproval await. A concurrent refresh that finds the ref already moved now reads the new head from the row, not the old one.

  • Change: the row update moved up in src/core/following.ts. The tail of the function (the fork-combine step) is untouched.
  • Test: a new test in test/pull-head-refresh.test.ts holds the first refresh inside carryApproval with a gate. While it is held, it checks that the ref has moved, that a second refresh returns nothing, and that headOid already equals the ref. It then releases the first refresh and checks it returns the new tip.
  • Check against the old code: the new test fails with the old ordering and passes with the fix. The rest of the file passes.
  • Gate and types: scripts/gate.ts and tsc --noEmit ran clean.
  • Not run: I ran only test/pull-head-refresh.test.ts, not test/crew-proposal.test.ts, where the flake showed up. The forge runs the full check on push.
  • Test setup: the test uses mock.module on carry_approval.ts. It copies the real module before mocking, because the namespace bindings are live and a mock that calls back through them deadlocks. It restores the module afterwards.
  • Left out: I did not change the apart (sealed) path or add any locking between refreshes. The ordering fix is enough for the reported race.
  • Not done: I did not call keep_plan or estimate; neither tool was available to me.

To try it: bun test test/pull-head-refresh.test.ts.

Closes #12870

commented

refreshPullHead now writes pull.head_oid immediately after writeRef, before the carryApproval await. A concurrent refresh that finds the ref already moved now reads the new head from the row, not the old one.

  • Change: the row update moved up in src/core/following.ts. The tail of the function (the fork-combine step) is untouched.
  • Test: a new test in test/pull-head-refresh.test.ts holds the first refresh inside carryApproval with a gate. While it is held, it checks that the ref has moved, that a second refresh returns nothing, and that headOid already equals the ref. It then releases the first refresh and checks it returns the new tip.
  • Check against the old code: the new test fails with the old ordering and passes with the fix. The rest of the file passes.
  • Gate and types: scripts/gate.ts and tsc --noEmit ran clean.
  • Not run: I ran only test/pull-head-refresh.test.ts, not test/crew-proposal.test.ts, where the flake showed up. The forge runs the full check on push.
  • Test setup: the test uses mock.module on carry_approval.ts. It copies the real module before mocking, because the namespace bindings are live and a mock that calls back through them deadlocks. It restores the module afterwards.
  • Left out: I did not change the apart (sealed) path or add any locking between refreshes. The ordering fix is enough for the reported race.
  • Not done: I did not call keep_plan or estimate; neither tool was available to me.

To try it: bun test test/pull-head-refresh.test.ts.

Approved

Approved. The head_oid write now follows writeRef with no await between, so a concurrent refresh that sees the ref current reads the new row. carryApproval takes the old head from the pull object it is passed, not the row, so moving the write earlier does not change what it carries. The test gates the first refresh inside carryApproval and fails on the old ordering. No UI surface changed, so the screenshots are unaffected. Two things I would do next: (1) if carryApproval throws, the row is already at the new head while the approval was not carried; make that failure visible or retried rather than silent. (2) mock.module on a core module is fragile; give carryApproval an injectable seam so the test does not need it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs