Skip to content

fix(core): the first open of an execution id holds its turn - #117

Merged
DaXu999 merged 1 commit into
mainfrom
fix/authority-open-race
Nov 8, 2026
Merged

DaXu999 merged 1 commit into
mainfrom
fix/authority-open-race

Conversation

@DaXu999

@DaXu999 DaXu999 commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Why

authority.test.ts, "refuses the later of two opens that race under one execution id", failed about one run in 50 on main. The test was right and the kernel was wrong: openTurnAuthority let both opens load authority and gave the turn to whichever load finished first. Each load hashes with crypto.subtle.digest on the libuv thread pool, so the two can finish in either order, and now and then the later call held the turn while the first was refused with execution_in_progress. Found while verifying #116.

What

  • A context with an execution id claims its turn before it loads. A second open under the same id is refused at once and without a store read, as it already was once the turn was held.
  • A cancelled or failed load frees the claim, so the turn can be opened again.
  • Opens without an execution id are unchanged: they still load and join the lease.
  • The race test now makes the later load finish first, so it fails on the old kernel every time. It checks that the later open is refused before any second store read. A new test frees a turn whose open was cancelled while it loaded.
  • docs/api/sharedos-core.md is regenerated for the openTurnAuthority doc comment. CHANGELOG entry under Fixed.

kernel.ts: 22 lines added, 12 removed. Tests: 39 added, 6 removed.

Related

Independent of #116; either can merge first.

Checks

  • pnpm check is green in a plain clone: format, typecheck, vitest 1156/1156, test:release 7/7, docs:api:check and conformance:check.
  • The authority test file passed 50 runs out of 50. With the old kernel.ts, the rewritten race test fails every time.

Two opens under one execution id both loaded authority, and the turn
went to whichever load finished first. Each load hashes on the libuv
thread pool, so the later call sometimes won and the first was
refused with execution_in_progress; authority.test.ts failed about
one run in 50.

The first open now claims the turn before it loads. A second open
under the same execution id is refused at once and without a store
read, as it already was once the turn was held. Opens without an
execution id still load and join as before.

The race test now makes the later load finish first, so it fails on
the old code every time. A new test frees a turn whose open was
cancelled while it loaded.
@DaXu999
DaXu999 force-pushed the fix/authority-open-race branch from 04f45a8 to 6b3d55d Compare November 8, 2026 15:49
@DaXu999
DaXu999 merged commit 5e99197 into main Nov 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant