Skip to content

3.x.x: open the async-promotion drill's gap session on published work, not on the persisted prepared row (#724) - #747

Merged
RobertClarke merged 1 commit into
3.x.xfrom
RobertClarke/724-gap-session-published-work
Oct 8, 2026
Merged

RobertClarke merged 1 commit into
3.x.xfrom
RobertClarke/724-gap-session-published-work

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #724: this fixes the the gap-issued job's window (last share Some(1)) does not reach past the replicated share 22 failure of pg_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

  1. The drill polled qbit_prism_jobs every 200 ms for a saved prepared:live-0:% row whose window_last_share_seq passes the standby's last share. It then opened the gap session (tests/support/live_pg_async_live_miners.rs, the until("server 0's work prepared over the gap", …)).
  2. A new session's first job is built from the frontend's in-memory published work (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.
  3. A refresh commits the prepared row in 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 runs prove_fresh_compact twice more, with node RPCs and ledger reads (~630, ~648). Only after that does publish() install it (coordinator.rs ~1800-1801, compact.rs ~144). A session opened in between is issued the work published before.
  4. At the drill's 1 s reanchor (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

  • The wait for the saved row stays (see Review).
  • The gap session is then opened in a loop bounded at 5 s: a few 1 s reanchor intervals, while the four miners keep submitting in the gap.
    • Each pass runs under tokio::time::timeout of 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 by ANSWER (70 s) per message.
    • Each pass takes the id of the session's first job from its first notify (new ShareClient::job_id, which reads nothing more from the server). It then reads that job's prepared window on the old primary (new helper prepared_last_share, the old assertion's query).
    • A window that doesn't reach past replicated drops the session, and another opens 200 ms later.
    • A first job whose issued row or prepared record is absent fails at once. Issuance saves both before it announces a job, so that is a fault, not older work. The helper keeps this case (None) apart from a window without shares (Some(None), older work).
  • The first session that reaches past replicated solves gap_share and gap_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.
  • Three failure messages:
    • The bound ran out with only older work issued: 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.
    • A pass didn't finish within the bound: no gap session had a first job and its window within 5s ….
    • The issued row or prepared record is missing: server 0 issued gap session job … but the old primary holds no issued row or prepared record for it ….
  • The drill's summary line reports the replaced sessions' windows (gap sessions replaced first for older work, their windows' last shares: […]). The timeline marks gap session opened on published work.

Accounting is untouched. A replaced session solves and submits nothing. The Book is written only by the four scripted miners' mine tasks, so their submissions and kept work are unchanged, and so are kept_by, acknowledged, the MINERS checks 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, and gap_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.

Tree Runs Pass Fail Notes
old drill + scratch 300 ms sleep 8 0 8 every run last share Some(1) … replicated share 22, CI's message; cut at about 2.9 s
first form + scratch 8 8 0 1 or 2 sessions replaced per run, each issued Some(1)
amended + scratch 4 4 0 1, 1, 2 and 1 sessions replaced, each issued Some(1); gap session at 4.2-4.4 s
first form, unpinned 10 10 0 no session replaced
first form, taskset -c 0-1 10 10 0 no session replaced
amended, unpinned 3 3 0 no session replaced
amended, taskset -c 0-1 6 4 2 both failures are #697's held-COMMIT race, after the gap session opened (Review)
interleaved, taskset -c 0-1: base 2d103c3 / first form / amended 8 + 8 + 8 24 0

The scratch, which was never committed, went between the reservation and the publication in coordinator.rs:

let reserved = self.reserve_fresh_compact(&captured).await?;
tokio::time::sleep(std::time::Duration::from_millis(300)).await; // scratch
self.lock_compact_publication(reserved).await?.publish()?;

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 -- --list still lists pg_failover_tests::async_live_miners::async_promotion_with_live_miners_accounts_for_every_share_and_lands_a_block (97 tests), the name test/prism-gated-tests.txt pins.
  • The single live test: the runs above.

Review

A /code-review high of the first form found 7 minor issues and confirmed accounting and the drill's strength unaffected. Five are applied above:

  • None is told apart from older work;
  • each pass is truly bounded;
  • the messages give the actual elapsed time and print the last window once;
  • the bound is 5 s;
  • the redundant re-query is replaced by the same-job assertion.

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 until on 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.

Not in this PR

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…, 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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T01:27:30.747729Z 4b0d250 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@RobertClarke
RobertClarke merged commit c62ac57 into 3.x.x Oct 8, 2026
39 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/724-gap-session-published-work branch October 8, 2026 01:50
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]>
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