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

opened this

Merged 20d 7h ago, live in production

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

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.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs