fix(genesis-writer): flush and drain before checkpointing a step - #521
Open
rickyrombo wants to merge 1 commit into
Open
fix(genesis-writer): flush and drain before checkpointing a step#521rickyrombo wants to merge 1 commit into
rickyrombo wants to merge 1 commit into
Conversation
Step completion was recorded as soon as step.fn returned. Rows accumulate in w.blockTxs and are written by an async pipeline through a buffered channel, so returning does not mean the step's rows are durable -- its trailing block may still be unflushed, or queued and unwritten. That lets the checkpoint outrun the data. A resume then skips a step whose tail never landed, and nothing detects it: the step reads as complete. Measured on the 2026-08-07 snapshot, the events step was recorded complete holding only the first 73 of 112 rows -- a clean prefix, which is the signature of a lost queue tail rather than a filtered source (event_id order correlates with time at 0.154, and the missing rows span the same dates as the migrated ones). It cost 39 events, 606 event subscriptions and 63 comments. Flushes the current block and drains the writer before the progress insert, so the checkpoint means what the README already claims it means. Each step now ends its block early, which costs a few partial blocks. No direct test: exercising it needs a live database and an interruption injected between step return and queue drain. The existing suite passes.
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 checkpoint can outrun the data
Step completion was recorded as soon as
step.fnreturned:But rows accumulate in
w.blockTxsand are written by an async pipeline through a buffered channel (blockWriteCh, size 4). A step returning does not mean its rows are durable — its trailing block may still be unflushed, or queued and unwritten.So the progress row can land while the step's tail has not. A later resume then skips a step that never finished, and nothing detects it: the step reads as complete.
What it cost
On the 2026-08-07 snapshot the
eventsstep was recorded complete holding only the first 73 of 112 rows.That it is a clean prefix is the signature of a lost queue tail rather than a filtered source —
event_idorder correlates with time at only 0.154, and the missing rows span the same date range (2025-04 to 2026-08) as the migrated ones.The cascade:
Fix
Flush the current block and drain the writer before the progress insert, so the checkpoint means what the README already claims:
That was the intent; it just wasn't enforced. Each step now ends its block early, costing a few partial blocks — already true of the last block of any run.
Testing
The existing suite passes. There is no direct test: exercising this needs a live database and an interruption injected precisely between step return and queue drain. The change is structural — the barrier is unconditional — but I want to be straight that the failure path itself is not covered.
🤖 Generated with Claude Code