Skip to content

3.x.x: async promotion with live miners: account for every offered, ACKed, rejected and unknown share, keep sessions and work, and land a block on the promoted ledger (#474) - #620

Merged
RobertClarke merged 6 commits into
3.x.xfrom
Anatolie/474-b-async-live-miners
Oct 6, 2026
Merged

RobertClarke merged 6 commits into
3.x.xfrom
Anatolie/474-b-async-live-miners

Conversation

@Anatolie

@Anatolie Anatolie commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Refs #474 (slice B). Test-only: no production code changes. It found #619, which #645 has since fixed. Follow-ups: #697.

What this adds

pg_failover_tests::async_live_miners::async_promotion_with_live_miners_accounts_for_every_share_and_lands_a_block is a child of live_pg_failover.rs. It reuses that module's D3 pair (PostgreSQL 16 primary plus one physical async standby), the stable writer endpoint relay, the replication relay and the promotion procedure. It runs two real native frontends and a real qbitd.

This cites, and does not duplicate, #466's ledger/window/snapshot_delta/tests/physical_failover.rs::physical_async_failover_replaced_history_matches_full_read.

ShareClient gains solve and submit_solved, so a miner can keep solved work and submit it later; submit is unchanged.

What the test found: #619

A block solved on the gap-issued job and submitted after the promotion is accepted by the frontend. It is offered, and qbitd puts it on the active chain with a coinbase paying the lost window. Landing then fails permanently with window range incomplete: expected 15 shares, read 0. The candidate stays in reconciliation under an ERROR ALERT, with no qbit_pool_blocks row and no audit.

Until #619 was fixed, the gated test kept that block unsubmitted and an #[ignore]d reproducer asserted the desired behaviour. #645 fixed it on 3.x.x: the block is refused as stale-job (window_not_held) before its offer. The reproducer passed on the rebased branch, so it is folded into the gated test, which now submits the block.

A sample run

These are the counts from one run:

  • Submissions: 88 offered, 80 acknowledged, 7 rejected (4 backend-rpc-unavailable after the fence, 3 ledger-confirmation-failed queued behind the held COMMIT and truthfully never committed) and 1 unknown (the held COMMIT, which completed on the old primary and was lost in the gap).
  • The gap: 21 shares were committed before the cut. 60 were lost in the gap (181,464 WAL bytes), and 59 of them had been acknowledged and are named.
  • After the promotion: 4 fresh, 4 kept-before-cut, 4 kept-in-gap, 1 gap-job share and 59 lost-share replays were all accepted, and the surviving share was a duplicate.
  • The final block paid 15 shares, equal to the independent full read. On the final revision, 13 of them carry reused sequence numbers.
  • Timeline: cut 2.8 s, fence 3.9 s, promoted 4.3 s.

Placement and runtime

The test runs per PR: it is added to test/prism-gated-tests.txt, and r474-b-async-promotion-under-live-miners is now runs = true. It is cheap, about 7.5 s including the cluster pair.

Verified locally

The environment was PostgreSQL 16 binaries (PRISM_TEST_PG_BIN_DIR=/usr/lib/postgresql/16/bin) with the pinned qbit 1.0.0.

Not covered here

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 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-06T02:47:58.535939Z 159f2f6 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 159662e1a5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch 2 times, most recently from 31e1230 to d465bf1 Compare September 30, 2026 19:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d465bf1603

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa4744298e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch from aa47442 to 4df2b9b Compare September 30, 2026 20:40
@Anatolie
Anatolie force-pushed the Anatolie/474-c-lost-reply branch from 5fa5606 to 2564cc0 Compare September 30, 2026 21:08
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch 2 times, most recently from 9bb1f40 to 56fc8d6 Compare September 30, 2026 21:08
@Anatolie
Anatolie force-pushed the Anatolie/474-c-lost-reply branch 2 times, most recently from b3fbc76 to d368201 Compare September 30, 2026 21:08
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch 3 times, most recently from a0e5d10 to c7fe25e Compare September 30, 2026 21:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7fe25ec6d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Anatolie
Anatolie force-pushed the Anatolie/474-c-lost-reply branch from f250c2c to 346352b Compare September 30, 2026 22:25
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch from c7fe25e to 19843a7 Compare September 30, 2026 22:27
@Anatolie
Anatolie force-pushed the Anatolie/474-c-lost-reply branch from 346352b to 61a40f2 Compare September 30, 2026 22:54
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch 2 times, most recently from 8fe260e to 3072b85 Compare September 30, 2026 22:54
@Anatolie
Anatolie force-pushed the Anatolie/474-c-lost-reply branch from 61a40f2 to 9920be5 Compare September 30, 2026 23:05
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch from 3072b85 to a80b06c Compare September 30, 2026 23:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a80b06c87b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Anatolie
Anatolie force-pushed the Anatolie/474-c-lost-reply branch from 9920be5 to 381bebb Compare September 30, 2026 23:40
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch 2 times, most recently from bdae02c to ebf35df Compare September 30, 2026 23:40
@Anatolie
Anatolie changed the base branch from Anatolie/474-c-lost-reply to 3.x.x October 1, 2026 00:04
@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch 2 times, most recently from f37763f to d9bf601 Compare October 1, 2026 00:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9bf601088

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Anatolie
Anatolie force-pushed the Anatolie/474-b-async-live-miners branch from 46ca90d to 5c17d2a Compare October 1, 2026 00:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c17d2ad2b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 417be0870b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Anatolie and others added 5 commits October 5, 2026 22:10
…CKed, rejected and unknown share, keep sessions and work, and land a block on the promoted ledger (#474)

#474 slice B, a child of live_pg_failover.rs on its D3 pair and relays.
Four scripted Stratum miners, each with its own payout address, submit
shares on two real frontends through a replication cut and a writer fence,
with a share COMMIT held in flight at the fence by a deferred trigger. Every
submission is recorded by identity and reconciled with the old and promoted
ledgers: each ACK was committed, each ACKed-but-missing share is named and
inside the gap, no definite rejection was committed, and the old writer
committed nothing after the fence but the COMMITs it held. After the
promotion the same sessions submit new shares, kept work from before the
cut and from a job issued in the gap, the lost ACKed shares again and a
surviving one again (a duplicate); a block on post-promotion work lands
and its audit, verified against the coinbase, is a full read of the
promoted window, including sequence numbers the lost shares held.

A block on the gap-issued job is offered and put on chain but never lands
(#619); its assertion is an opt-in #[ignore]d test until #619 is fixed.
ShareClient gains solve/submit_solved so a miner can keep work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… promotion case (#474)

Each miner keeps one share of work on its first iteration before the cut
and in the gap. Nothing waited for it, so a miner that scheduling skipped
in a phase left the replay checking less than the case states. The phase
transitions now wait, inside their existing bounded conditions, until
every miner has kept work for the phase, and the replay asserts exactly
one kept share per miner per phase before consuming them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ued after the promotion (#474)

The first post-promotion submissions use each session's current job,
which may predate the cut: frontends push no new work until the tip
moves. Name them so, and add the missing proof: once the final block
moves the tip, every surviving session is notified of work for it and a
share on that work is accepted and credited exactly once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the tip (#474)

In the opt-in #619 case the gap-issued block was submitted after the
final block had advanced the tip, so the stale-parent rule could refuse
it and the reproducer pass without exercising #619. It is now submitted
right after the kept work, on the tip its job builds on; locally it is
accepted, offered and stuck in reconciliation, as #619 describes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, now that #645 refuses it (#474)

#645 fixed #619 on 3.x.x: a block on work from a lost replication gap
is refused as stale-job before its offer. The opt-in reproducer
issue_619_gap_issued_block_after_async_promotion_is_refused_or_pays_only_promoted_rows
passes on the rebased branch, and it asserts everything the gated drill
does plus that refusal. So the gated drill now submits the block it
solved on the gap-issued job, and the ignored copy and the GapBlock
switch are gone.

The comments that described #619 as open now describe #645's behaviour,
and the scenario note and #645's design note name the gated drill
instead of the removed reproducer.

Locally against PostgreSQL 16 and the pinned qbit 1.0.0, the drill
passed 15 of 15 runs; each time the gap-issued block was refused as
stale-job and no session was replaced for a stale window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke force-pushed the Anatolie/474-b-async-live-miners branch from bfa72e0 to 29e45de Compare October 6, 2026 02:20
@RobertClarke

Copy link
Copy Markdown
Member

Taking this over per #626.

Next: /code-review high, then a squash-merge once CI is green and threads are resolved.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29e45de7e0

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…he surviving share before any block moves the tip (#474)

Codex: when the gap-issued block was refused, nothing checked that its
share was not credited. It was not added to the answers the drill holds
to the promoted ledger, so a regression that credited the block as an
ordinary share while refusing its payout authority would have passed.
It is now one of those answers: landed, it must be credited once;
refused, not at all. #645's own gated test asserts the same without
qbitd.

/code-review high: the surviving acknowledged share was replayed after
the final block had moved the tip, and was required to read
`duplicate-share`. The server settles a stale parent, with its 3 s
grace, before it looks for a duplicate. So once the replays of the lost
shares outlasted the grace, the same replay would have read
`stale-job` on a correct server. It is now replayed right after the kept
work, while its parent is still the tip.

The review's other findings are test robustness and cleanup, and are
deferred to #697.

Locally against PostgreSQL 16 and the pinned qbit 1.0.0, the drill
passed 8 of 8 runs with both changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member

159f2f64 addresses Codex's finding on 29e45de7 and the one finding from my /code-review high that could fail the gated test. My token can't reply on review threads, so here is the reply.

P2 verify the rejected gap block was not credited. Fixed. The gap-issued block's submission now joins the answers the drill holds to the promoted ledger (after). Landed, it must be credited exactly once; refused stale-job/unknown-job, it must have no accepted row. #645's own gated test (b619_gap_work_after_promotion) asserts the same without qbitd ("the refused block's share was credited").

From /code-review high: the surviving-share replay was timing-dependent. It was sent after the final block had moved the tip and was required to read duplicate-share. submit_share settles a stale parent, with its 3 s grace, before the save that detects a duplicate. So once the lost-share replays outlasted the grace, a correct server would have answered stale-job. The replay now runs right after the kept work, while its parent is still the tip.

The review's other seven findings are test robustness and cleanup: replay coverage, failure-path cleanup of the advisory-lock hold and the miner tasks, sent-phase sampling, and duplicated helpers. They are filed as #697, together with two setup races I saw only under heavy host load (2 of 6 runs at load ~20 on 16 cores). The drill passed 27 other local runs, and passed in CI shard 0 on 29e45de7.

Local runs on 159f2f64: 8 of 8 against PostgreSQL 16 and the pinned qbit 1.0.0. clippy (-D warnings) and fmt are clean.

🤖 Generated with Claude Code

@RobertClarke
RobertClarke merged commit 2660940 into 3.x.x Oct 6, 2026
34 checks passed
@RobertClarke
RobertClarke deleted the Anatolie/474-b-async-live-miners branch October 6, 2026 03:05
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.

2 participants