fix: converge concurrent organization handoff publishers under load - #13
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The flake
organizationHandoffAuthorityFsClient.test.ts— "converges full-size concurrentpublishers without leaving staging sidecars" — failed roughly one full-suite run
in six under load, blocking #8, #10 and #12.
Measured with the test run repeatedly under CPU load, arms interleaved within a
single load session so ambient drift hits both equally:
mainThe test itself is unchanged — no loosened assertion, no retry wrapper, no skip.
The cause was not the attempt budget
The prior diagnosis pointed at the worker's
PUBLICATION_*_ATTEMPTSbudget.Once the failures were made diagnosable, no failure was ever a budget
exhaustion. Two unrelated bugs were:
1. The liveness watchdog reaped the helper during its own startup.
anchoris set at the end of an async startup path. On a loaded host that pathtakes longer than one 100ms tick, so the watchdog exited the helper before it
could report ready — surfacing as
exit=0 signal=nullbefore the handshake.The watchdog now reads the expected parent pid synchronously from the
environment, so it never depends on startup having finished.
startstillvalidates the full anchor independently and no request is served until it does.
2. An unlinked staging sidecar was reported as a rejected election.
expectedElectionStateended withreturn stat?.nlink === 1, which maps "theleaf is gone" to
false(fail closed) rather thannull(absent). The helperthat wins an election unlinks its sidecar immediately after linking the final
record, so a losing publisher can find it absent one syscall later — a benign,
converging race turned into a hard failure. Reachable by construction; not
observed as a trigger once (1) was fixed, so this is a correctness fix rather
than the flake's cause.
Diagnosability first
The failure was swallowed three times, not twice: the worker's queue
.catchdropped the reason and sent only
ok: false; the client minted a fresh bareError; and the store'scatch { return fail(); }replaced it again.Failures now carry which budget or invariant failed, the attempt count, real
elapsed wall-clock against the limit, and the structural shape of the
contending state:
The message keeps its historical prefix, so existing expectations hold. The
diagnostic reports shape only — never record bytes, leaf names, or paths — and
the store's public message stays uniform, carrying the detail on
causeso itreaches an operator log without widening what the CLI prints.
Budget shape
Replaced the attempt-counted budget with a wall-clock deadline, an attempt cap
as a secondary bound, and jittered exponential backoff — one budget per
request rather than one per loop.
The loops wait for a peer to finish writing and linking a record. That is a
wall-clock event, so counting attempts measures the wrong thing: the loop's
effective patience varies with load, and nested loops each got their own budget,
which bounded no level usefully — each was too impatient while their product was
effectively unbounded. The jitter matters too: eight symmetric publishers waking
on a fixed 2ms timer retry in lockstep and re-observe the same unfinished state.
The worker's 2s budget now sits inside the client's 5s request deadline, so a
worker failure is reported rather than replaced by a client timeout.
Tests
Both root causes are regression-locked, each verified to go red when the fix is
reverted:
reaches readiness when startup is stalled past a liveness watchdog tick—holds the single libuv threadpool slot so the anchor
lstatcannot completebefore the watchdog ticks. Reverted, it fails with
exit:0:null, the CIsignature.
reports absence when the winning publisher unlinks the sidecar mid-check—the election logic moved behind an injectable
lstatso mid-raceinterleavings can be staged deterministically.
npm run build,npm run typecheck,npm test(3446 passing, coveragethresholds met) and
node check-boundaries.mjsall pass. Total branch coverageis 90.04% both before and after this branch.