Repository navigation
3.x.x: open the async-promotion drill's gap session on published work, not on the persisted prepared row (#724) - #747
Merged
Conversation
…, not on the persisted prepared row (#724) The async-promotion drill opens a Stratum session inside the replication gap and requires its job's prepared window to reach past the last share the standby replicated. It waited for that by polling qbit_prism_jobs every 200 ms for a saved prepared:live-0 row past the replicated share, then opened the session. A new session is issued the work the frontend has published in memory, though, and a refresh saves the prepared row before it publishes the work: reserve_fresh_compact commits the row, the work is checked against the node and the ledger twice more, and only then does publish() install it. A session opened in between is issued the work published before. At the drill's 1 s reanchor a frontend keeps its published work while shares arrive, rebuilding at once only for the first share, so when the gap is reached within about a second of the first share that work is still the first share's window. Required CI failed this way three times, each with a window ending at share 1 or 2 against 22 to 24 replicated (jobs 112476793983, 113062547171 and 113070225231), and #697 lists the same failure from local runs. The drill keeps its wait for the saved row, which still fails first for a frontend that never prepares work over the gap. It then opens the gap session in a loop bounded at 5 s, a few reanchor intervals, while the miners keep submitting in the gap. Each pass is bounded by what is left of the 5 s. It connects, takes the id of the session's first job from its first notify through a new ShareClient::job_id accessor, and reads that job's prepared window. A session whose window does not reach past the replicated share is dropped, and another opens 200 ms later. A first job whose issued row or prepared record is absent fails the drill at once, since issuance saves both before it announces a job. The first session whose window does reach past it solves the gap share and the gap block, which must both be on that job. That check replaces the old re-query of the block's window, which the shared notify made redundant. A replaced session solves and submits nothing, and the book records only the four scripted miners' submissions and kept work, so it and every count built on it are unchanged. The replaced sessions' windows are reported in the drill's summary line, and the timeline marks when the gap session opened. To prove it, a scratch 300 ms sleep between the reservation and the publication, never committed, made the old drill fail 8 of 8 runs with CI's message (last share Some(1) against 22). With the same sleep the drill passed 8 of 8 runs in its first form and 4 of 4 as amended, each run replacing one or two sessions issued the first share's window. Without the sleep, the first form passed 10 of 10 runs unpinned and 10 of 10 pinned to two CPUs, and the amended drill 3 of 3 unpinned and 4 of 6 pinned. Both pinned failures were the other setup race #697 lists, a COMMIT held across the fence answered as acknowledged, which happens after the gap session has opened. Interleaved and pinned, the base, the first form and the amended drill then passed 8 of 8 runs each. This addresses only the gap-window failure; #724's stale-job and backend-rpc-unavailable answers and #697's other items are separate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
RobertClarke
added a commit
that referenced
this pull request
Oct 8, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.5: rc.4 plus #737's fixes in #742 (fatal-state clear accepts a tip that only grew, takes --timeout-seconds, and runs the integrity report under its own statement timeout) and #744 (migration 026: the report computes each set once); the deferred share-hash backfill in #743 and #746 (migrate --defer-share-hashes, then the throttled backfill-share-hashes after go-live); #745 (migrate --offline-indexes, which composes with --defer-share-hashes); the cutover tooling merged after rc.4's tag (#728, #732, #736, #740); and #747, a test-only fix for #724. Both Cargo.lock files move only their workspace-member entries. doc/release-notes-3.0.0-rc.5.md, dated 2026-10-08, covers: - the changes, with the report's estimated 57 to 29 s since 026, the migrate --defer-share-hashes command measured on the pair at 5 min 06 s (539d6c9, before #745), backfill-share-hashes' throttle, record of 2 and safe rerun, the evidence scripts' changes, and the offline index builds' estimated gain; - upgrading: migrate is needed again (a binary-only upgrade refuses "missing migration(s) 26", and this export refuses a database without 026), the cutover's migrate step with both flags, and finishing the backfill after go-live under #738's snapshot rule, with self-check only at low share rates. Rolling back to rc.4 at fence 2 goes only by finishing the backfill first or from the pre-migrate backup or physical copy, and each rc.4 refusal is quoted where it applies: a start meets the cursor first and says to run migrate, which rc.4's migrate refuses. The rules still in force: #737's statement timeout for rc.4's tools, 026 or not, #738's snapshot rule, and fatal-state clear --timeout-seconds, whose bound ends before the commit; - the same evidence set as rc.4's, with each PR's merge SHA, the pair's serving evidence carried, and the rehearsal's full measurements left to the cutover's go/no-go record; - the known issues: rc.4's, minus #737's F1, F2, F4 and F5, plus #737's open part, #738 (its fix planned for rc.6), #739, #741, #731 and #734, with #582 closed and #712 and #724 updated. docs/prism-rust-migration.md now says how earlier candidates refuse a database at fence 2: a start with the backfill's own refusal, whose advice to run migrate holds only for this release, and their migrate, or a start with PRISM_POSTGRES_INIT_SCHEMA=1, with the fence. The development-line notes name 3.0.0-rc.5, and they and the 3.0.0 notes link all five candidates' notes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke
added a commit
that referenced
this pull request
Oct 8, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.6: rc.5 plus #754 (the pool hashrate series bounds both of its ledger reads, the boundary buckets and the tail past the rollup watermark, at both ends, fixing a 3.x regression that timed it out on large ledgers), #750 (#748: a failed record of 2 is re-checked on a fresh connection when its own one was lost, and each attempt is bounded on the client's side), and #753, a test-only fix for #724. Both Cargo.lock files move only their workspace-member entries. doc/release-notes-3.0.0-rc.6.md covers: - the changes, with #754's figures from its pull request (19 to 40 s and a 504 on a 66M-share ledger before, and 17 to 27 s with only the boundary fixed; 1 to 17 ms on a 6M-share copy after, under every plan mode and random_page_cost tried, with its output matching rc.5's; and on a production-sized ledger, 9 to 23 ms for the pool and 2 to 15 ms for miners in 20 of 20 runs, against rc.5's 15.8 to 25.2 s, with identical output), #750's lost connections, fresh read, client-side deadlines and two new stops, and #753's wait for current work; - upgrading: rc.6 adds no migration, capability, setting or script, so an upgrade from rc.5 and a rollback to it replace the binary only, at fence 2 too, and a database that rc.5's migrate migrated is served by rc.6 unchanged, which a cutover that pinned rc.5 can rely on. An upgrade from rc.4 or earlier is as in rc.5's notes, which the section links: migrate for 026, fence 2 and the deferred backfill, #738's snapshot rule and fatal-state clear --timeout-seconds; - the same evidence set as rc.5's, with the pair's serving evidence carried; - the known issues: rc.5's, with #748 fixed and #724's drill race and new-tip shares fixed on the test side (#747, #753), plus #752 after the cutover, #738's fix now planned after the cutover, and #739 not in this candidate. The development-line notes name 3.0.0-rc.6, and they and the 3.0.0 notes link all six candidates' notes. docs/prism-rust-migration.md names rc.5 where it said "this release" of serving at fence 2 and finishing the backfill. That is in three places: that every build before rc.5 refuses fence 2, that the starts of rc.5 and later accept it, and that only rc.5 and later finish a pending backfill. In this candidate's tree "this release" would have excluded rc.5, which does both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
Part of #724: this fixes the
the gap-issued job's window (last share Some(1)) does not reach past the replicated share 22failure ofpg_failover_tests::async_live_miners::async_promotion_with_live_miners_accounts_for_every_share_and_lands_a_block. That is also the second of the two setup races #697 lists. It changes the test only.The drill opened its gap session as soon as server 0 had saved prepared work over the gap. A new session is issued the work server 0 has published, though, and a refresh saves first and publishes after more checks. The drill now opens the gap session in a bounded retry loop until the session's first job comes from a window past the replicated share.
This race caused all three required-CI failures with this message: jobs 112476793983 (Oct 6, before #745 existed), 113062547171 and 113070225231. A scratch delay on the server side reproduces it 8 of 8 times, and the new drill passes every run with that delay (Proof, below).
Mechanism
qbit_prism_jobsevery 200 ms for a savedprepared:live-0:%row whosewindow_last_share_seqpasses the standby's last share. It then opened the gap session (tests/support/live_pg_async_live_miners.rs, theuntil("server 0's work prepared over the gap", …)).Coordinator::build_job,coordinator.rs~3547). Issuance persists the job before announcing it (stratum.rs~1359), so the job row is always there to read.reserve_fresh_compact(prepared_storage/compact.rs~621; its doc comment, ~105, calls it "an idempotently persisted dependency, still unavailable to miners"). The work then runsprove_fresh_compacttwice more, with node RPCs and ledger reads (~630, ~648). Only after that doespublish()install it (coordinator.rs~1800-1801,compact.rs~144). A session opened in between is issued the work published before.PRISM_PAYOUT_ARTIFACT_REANCHOR_SECONDS=1), a frontend keeps its published work while shares arrive. Only the first share forces an immediate rebuild (coordinator.rs~1590-1606). So when the gap is reached within about a second of the first share, the work still published is the first share's window. Every failure shows a window ending at share 1 or 2, against 22 to 24 replicated, with the cut at 3.1 to 3.8 s.Saving before publishing is deliberate: the dependency must be durable before any issued job can name it. So the test is what changes.
Fix
tokio::time::timeoutof what is left of the 5 s, covering connect, subscribe, authorize, the first notify and the window read. A slow pass can't overrun the bound byANSWER(70 s) per message.ShareClient::job_id, which reads nothing more from the server). It then reads that job's prepared window on the old primary (new helperprepared_last_share, the old assertion's query).replicateddrops the session, and another opens 200 ms later.None) apart from a window without shares (Some(None), older work).replicatedsolvesgap_shareandgap_block. The drill asserts both are on that job:the gap share and block were solved on jobs … not on the gap session's first job …. That replaces the old post-solve re-query of the block's window, which couldn't fail because both solves use the same notify.the gap-issued job's window does not reach past the replicated share N: in the 5.0s after server 0 saved work over the gap, it issued K new session(s) only older work (their windows' last shares: […]). This gives the actual elapsed time and lists each window once.no gap session had a first job and its window within 5s ….server 0 issued gap session job … but the old primary holds no issued row or prepared record for it ….gap sessions replaced first for older work, their windows' last shares: […]). The timeline marksgap session opened on published work.Accounting is untouched. A replaced session solves and submits nothing. The
Bookis written only by the four scripted miners'minetasks, so their submissions and kept work are unchanged, and so arekept_by,acknowledged, theMINERSchecks and every count built on them. All of the gap session's later uses keep their meaning: the kept gap share replayed after the promotion, the stale gap block, andgap_window(now the accepted window's last share) in the landing message. A replaced session leaves only an issued-job row on the old primary inside the gap, which the promotion loses like the gap's other rows. The test opened probe sessions like this before, after the move (b474-probe), and in the final block's loop.Proof
All runs used one test with
--exact --test-threads=1, a fresh database each, PostgreSQL 16.10, pinned qbitd 1.0.0, through the host's heavy-job guard. "First form" is this PR's first revision, before the review amendments.last share Some(1) … replicated share 22, CI's message; cut at about 2.9 sSome(1)Some(1); gap session at 4.2-4.4 staskset -c 0-1taskset -c 0-1taskset -c 0-1: base 2d103c3 / first form / amendedThe scratch, which was never committed, went between the reservation and the publication in
coordinator.rs:Earlier tonight, the old drill passed 22 of 22 runs on each of 539d6c9 and 118b512 without the scratch (4 and 2 pinned CPUs, with and without CPU hogs). The window is a few milliseconds on an idle host. On CI's 2 vCPU runner it is wide enough to hit about once in 12 runs.
Gates
cargo fmt --all --check: clean.cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings: clean.cargo test --locked -p qbit-prism-server --test live_regtest -- --liststill listspg_failover_tests::async_live_miners::async_promotion_with_live_miners_accounts_for_every_share_and_lands_a_block(97 tests), the nametest/prism-gated-tests.txtpins.Review
A
/code-review highof the first form found 7 minor issues and confirmed accounting and the drill's strength unaffected. Five are applied above:Noneis told apart from older work;The optional sixth, reading the job id from the first notify, was a small accessor, so it is applied too: replaced sessions solve nothing.
Declined: dropping the
untilon the saved prepared row. It keeps a distinct, earlier failure for a server that never prepares work over the gap, which is a different fault from slow publication.Seen while proving this, not changed here: #697's held-COMMIT race. It hit 2 of 6 pinned runs of the amended drill. In the interleaved comparison afterwards it hit 0 of 8 for the amended drill, the first form and the base alike. #697 recorded the same failure before this change, and it happens after the gap session has opened.
a COMMIT held across the fence was answered as known: [Record { miner: 1, sent: Gap, answered: Fenced, …, outcome: Acknowledged }].sent-phase race 3.x.x: harden #474 B's async promotion drill: replay coverage, failure-path cleanup, phase sampling and two setup races under load (follow-up to #620) #697 suggests. A share can only be acknowledged if the server received its held COMMIT's reply, which completes only afterhold.open().Relay::fence()(live_pg_failover.rs) only sets a flag and bumps a watch generation. Each relayed connection closes when its own task next polls an unbiasedselect!, and the drill opens the hold right afterfence(). If that task hasn't run before the reply arrives, it can poll the copy branch first and forward the reply. On two pinned CPUs that wait is long enough to matter.fence(), until the relay has closed every connection it was carrying before opening the hold. Abiased;select with the fence branch first would narrow it. That belongs with 3.x.x: harden #474 B's async promotion drill: replay coverage, failure-path cleanup, phase sampling and two setup races under load (follow-up to #620) #697.Not in this PR
stale-jobanswer on new-tip work and itsbackend-rpc-unavailablereplay answer (3.x.x: a share under a tip-change lease is refused 'commit gate closed' when the authority try_read meets a writer, which can drop a valid share's credit and fires PrismShareAppendFailures #716's commit-gate class). Neither involves the gap session, so 3.x.x: flaky live test: async_promotion_with_live_miners_accounts_for_every_share_and_lands_a_block answers a share on new-tip work stale-job #724 stays open.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.