Repository navigation
fix(tests): pin AC12 restart shape with a synchronous persist barrier - #3345
Merged
Merged
Conversation
The simulated-restart strips mutated session memory directly while debounced saves were still armed; whichever snapshot a timer found at fire time became the record the next boot read. When the phase-2 boot adoption's debounce fired before the strip (event-loop span > debounce window, e.g. CI load), the child loaded WITH blocks at final boot and legally adopted the grandchild, closing its gate and tripping the derivedBlocksAdopted assertion. flushSync after each strip cancels the timer, writes the stripped record now, and bumps the commit fence against stale in-flight writes. Test-only; no runtime behavior change.
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3946-pr.3345.3db5721This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3345.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.486-master.745be9f # this exact build
npm install -g billion-context@master # always the newest merged build
|
This was referenced Oct 16, 2026
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.
What
tests/lineage-reconcile-boot.test.tsAC12 ("a multi-hop grandchild stays eligible when its intermediate parent has nothing to adopt yet") failed intermittently — including on pure master (issue repro: 1/10 local runs, CI shard hit on #3144). This makes the test deterministic.Test-only change. No runtime behavior change.
Closes #3336
Root cause (test-side race, implementation verified sound)
The test simulates a bili restart by mutating session memory directly (
blocks.length = 0,delete metadata.derivedBlocksAdopted) while debounced saves are still armed, then reads back whatever landed on disk. The debounced save builder captures whichever in-memory snapshot exists at fire time, andclose(proxy)performs no store flush.The decisive window: at the second boot, the boot reconcile legitimately adopts the child from the root parent (#2807 behavior) and arms the child's debounce timer. If the event-loop span from that boot to the test's strip exceeds the debounce window (default 500ms — easily exceeded under CI load / GC / shard contention), the timer fires pre-strip and persists the child's adopted record (blocks>0, marker set). The final boot then loads the child WITH blocks; since the sweep visits the grandchild first (lastSeen descending) and the grandchild replays the root's full history byte-exactly, the adoption succeeds,
derivedBlocksAdoptedis set on the grandchild, and the assertion at line 468 fails. When the span stays under the window (typical locally), the post-strip snapshot wins and the test passes — hence the low local rate and the CI-only signature.Probe evidence: identical runs produced both disk shapes for the child (adopted record surviving to final boot vs stripped record); the failing interleaving requires exactly {child file = adopted, grandchild file = stripped}, which the sweep order then turns into the observed single-assertion failure.
Implementation audit (no change needed): every non-success branch in
reconcileDerivedLineageleaves the gate open (parent-not-on-disk / parent-no-blocks / no-refs / adoptedActive===0 / catch allcontinuewithout setting the marker); success requires the parent to genuinely hold blocks whose effective ids are a subset of the child's raw ids. A parent that legitimately persisted blocks → child adopting is correct #2807 behavior, not a gate mis-close. Multi-hop convergence at ≤1 hop per boot is documented intended behavior.Fix
After each artificial strip, force a synchronous persist of the exact post-strip state:
getStore().flushSync(session)(asserted). Per id this cancels the armed debounce timer, writes the record now, and bumps the commit fence so any stale in-flight async write for that id cannot land afterwards. Sites:setupForkOnDisk: flush the stripped child and the parent's folded ledger (every boot-reconcile assertion in this file depends on it being on disk).This also removes the same latent exposure in AC9/AC10/AC11 (their premise "the child is exactly the post-restart state" was previously timing-dependent; e.g. AC11 could have tripped its own
marker !== trueassertion if the adopted record leaked).Verification
npm run typecheckclean.BILI_PERSIST_DEBOUNCE_MS=200(amplified window pressure): 10/10 pass.