Skip to content

3.x.x: let the async-promotion drill's new-tip shares wait for work at the payout revision the final block's confirmation set (#724) - #753

Merged
RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/724-stale-job-new-tip-share
Oct 8, 2026
Merged

RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/724-stale-job-new-tip-share

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #724: this fixes its original symptom in pg_failover_tests::async_live_miners::async_promotion_with_live_miners_accounts_for_every_share_and_lands_a_block, miner N's share on work for the new tip was answered stale-job. It changes the test only. The server behaviour it waits out is filed as #752.

Required CI hit it in jobs 112241378522 (miner 0) and 113174599773 (miner 1, #750's head).

The drill's last check took the first job built on the new tip as current work. The final block moves the payout revision twice on that tip, and new-tip work published between the two moves is superseded at once. The drill now waits until each session's job on the new tip comes from work at the ledger's revision. It also keeps the original symptom as a check: a share on superseded work must be refused and never credited.

A scratch delay on the server side reproduces CI's message every time. The server's refusal names the cause: the job's work on revision 2, the ledger on 3. The drill as amended passes every run with that delay (Proof, below).

Mechanism

  1. The drill: for each surviving session it called work_on(tip), which returns at the first job whose parent is the new tip, then submitted a share on it and required accepted (tests/support/live_pg_async_live_miners.rs, the new-tip loop).
  2. Two revision bumps on one parent:
    • The first frontend to record the new tip bumps the payout revision and chain epoch (ledger/window.rs ~557). That frontend is either a refresh woken by waitfornewblock, or the landing's own observe_candidate (coordinator.rs ~2038-2052).
    • The landing then confirms the block and bumps the revision again, in the transaction that sets chain_state='confirmed' (ledger/blocks.rs ~322-334).
  3. The refusal: work a frontend publishes on the new tip between the two bumps carries the first revision. Once the confirmation commits, submit_share refuses a plain share whose work revision, or whose frontend's published revision, differs from the durable one: StaleJobCause::PayoutRevision (coordinator/miner_submit.rs ~486-497). That includes a share on the frontend's own still-published work. share_lease covers only a tip change (coordinator/tip_observation.rs ~540-553).
  4. How long it lasts (3.x.x: after each pool block, the second payout-revision bump makes non-landing frontends refuse shares on just-published new-tip work as stale-job until their next blockpoll tick (post-cutover) #752): the landing frontend wakes its refresh right after confirming (coordinator.rs ~3021). Other frontends learn at their next refresh tick, PRISM_BLOCKPOLL_SECONDS (0.2 s in the drill; 2 s by default, config.rs ~636).
  5. When CI hits it: a session whose first new-tip job came from first-revision work, and that hasn't read its frontend's republished job yet, fails the check. With only the republication delayed, 2 of 4 local runs failed. Usually the earlier replays read the republished job first, so CI hits it rarely.

Fix

Waiting for current work:

  • One 30 s deadline bounds the whole new-tip phase.
  • After work_on(tip), each session reads its job's prepared record and the cluster's payout revision on the promoted primary (work_revision). It compares the prepared record's revision, context.prepared.snapshot.payout_revision, which is what submit_share checks. An issued row stores the revision current at issuance, which can differ under a share lease.
  • A job on superseded work is passed over: the drill waits for the session's next job (ShareClient::newer_work) and checks again. If an answer already brought the next job, it doesn't wait.
  • A job without its issued row or prepared record is passed over the same way and reported. The final block's loop treats such a window the same way (3.x.x: after an async promotion, a block on a job issued in the replication gap is offered and lands on chain but can never be landed in the pool (window range incomplete) #619).

Submitting:

  • On work at the ledger's revision, the session submits. The share must be accepted and credited exactly once, as before.
  • If it is refused stale-job because the revision moved past its work after the check, the drill checks that the share left no ledger row, records it among the post-promotion answers, and waits for newer work.
  • Any other refusal fails, naming the job and the revisions before and after the share.

Bounds and checks:

The accounting of the drill's earlier phases is untouched. The only shares this phase adds are the refused ones above, each checked against the ledger.

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. The scratch was never committed:

  • the landing held 500 ms between observe_candidate and finish_candidate_counted_at_revision (coordinator.rs ~3013);
  • each same-tip revision republication (RefreshTrigger::Revision) held 1.5 s before its reservation (coordinator.rs ~1800);
  • a warn line at the PayoutRevision refusal, logging the job's, durable and published revisions.
Tree Runs Pass Fail Notes
old drill (97bcd7e) + both delays 6, then 4 after review 0 10 every run CI's message; each refusal payout_revision, job's work 2, ledger 3, published 2
old drill, republication delay only (diagnostic) 4 2 2 CI's message, miners 1 and 0
old drill, landing hold only (diagnostic) 6 6 0 the sessions read the republished job before submitting
as amended + both delays 6 6 0 every session passed over one job on revision-2 work (ledger 3); the kept share refused stale-job, no ledger row
as amended, unpinned 6 6 0 nothing passed over
as amended, taskset -c 0-1 6 6 0 nothing passed over
as amended + one injected revision move between a check and its share (test-side scratch) 3 3 0 the later-move path: the share refused stale-job, no row, then accepted on the next job
first revision + both delays / unpinned / pinned 8 / 10 / 10 28 0 before review

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 the test under the same name (97 tests), as test/prism-gated-tests.txt pins it.
  • The single live test: the runs above.

Review

A /code-review high of the first revision confirmed the ordering, the comparison, the bound and the accounting, and raised 9 minor items. All 9 are fixed:

  1. A late revision bump: a share refused stale-job because the revision moved past its work after the check is waited out within the deadline. Its ledger row is checked absent. Any other refusal fails with the work and ledger revisions before and after the share. This was exercised with an injected move (3 of 3).
  2. A missing record: a job without its issued row or prepared record is passed over and reported, as the finisher loop does (3.x.x: after an async promotion, a block on a job issued in the replication gap is offered and lands on chain but can never be landed in the pool (window range incomplete) #619), instead of failing at once.
  3. The superseded jobs are bounded: at most one distinct stale revision per session. Jobs on it aren't counted, since a republication for new shares before the confirmation can add one. The comment gives the justification.
  4. The original symptom stays as a regression check: one share on the first superseded job met, answered stale-job, no ledger row, in after. In ordinary runs no superseded job is met, so the check runs only when the race does. With the delays it runs every time.
  5. The timeout message on a later pass says the session got new-tip work only at a superseded revision (or without its record), and lists what it passed over.
  6. newer_work's inner error carries the miner, the job and its revisions.
  7. The comment references 3.x.x: after each pool block, the second payout-revision bump makes non-landing frontends refuse shares on just-published new-tip work as stale-job until their next blockpoll tick (post-cutover) #752 as the server behaviour waited out.
  8. One deadline before the per-session loop, through one left() closure.
  9. The job ids are in the superseded (and unrecorded) entries, so the summary joins to qbit_prism_jobs and the logs.

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.

…t the payout revision the final block's confirmation set (#724)

The async-promotion drill's last check sends a share from each
surviving session on work for the tip the final block moved to, and
requires it accepted and credited once. It took the first job built
on the new tip as that work. The final block moves the payout
revision twice on the same parent, though. The frontend that first
records the new tip bumps it (the chain observation in window.rs),
and the block's landing bumps it again when it confirms the block
(blocks.rs). Work a frontend publishes on the new tip between the two
carries the first revision. Once the confirmation commits, the
frontend refuses shares on that work, and on anything else it still
publishes, as stale-job for the payout revision until it republishes
on the confirmed one: the landing frontend at once, others at their
next refresh (#752). A session whose first new-tip job came from that
work submitted on it and was answered stale-job. Required CI answered
this way twice (jobs 112241378522 and 113174599773).

Each session now waits, under one 30 s deadline for the whole phase,
until its latest job on the new tip comes from work at the ledger's
payout revision. The drill reads the job's prepared record and the
cluster's revision on the promoted primary, and reads past a job on
superseded work to the session's next one through a new
ShareClient::newer_work. A job without its issued row or prepared
record is passed over the same way, as the final block's loop passes
over a window the promoted ledger lacks (#619). A share refused
stale-job because the revision moved past its work after that check
is waited out too, after its ledger row is checked absent; any other
refusal fails with the job's and the ledger's revisions. A session
may meet work on one superseded revision, possibly on more than one
job; a second is a revision move this drill never makes and fails.
The first job on superseded work the drill meets gets one share,
which must be refused stale-job and leave no ledger row, the original
symptom kept as a check, and it joins the answers after the
promotion. The jobs passed over and that share are reported in the
drill's summary line, with their job ids.

To prove it, two scratch delays, never committed, held the landing's
confirmation 500 ms after its chain observation and each same-tip
revision republication 1.5 s. The old drill then failed 6 of 6 runs,
and 4 of 4 again after review, with CI's message, each share refused
for its payout revision with the job's work on revision 2, the ledger
on 3 and the published work on 2. The drill as amended passed 6 of 6
with the delays, every session passing over one job on revision 2
and the kept share refused stale-job without a row. Without them it
passed 6 of 6 runs unpinned and 6 of 6 pinned to two CPUs, and with
one injected revision move between a check and its share, 3 of 3.
The first revision passed 8 of 8 with the delays and 10 of 10 each
unpinned and pinned.

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-08T09:36:32.323352Z 036fc79 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: a6ff6d19f7

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

… in the drill's regression check (Codex on #753)

Codex on #753: the drill's kept share on a superseded new-tip job had
to be answered stale-job, but a correct server can also answer
unknown-job. A session's job is retired when the server delivers the
job that replaces it, whether or not the miner has read it, and it is
pruned once retired past its retention
(PRISM_STRATUM_SAME_TIP_JOB_RETENTION_SECONDS, 30 s by default)
before a submission looks it up. A pruned job is resumed from its
durable rows only while its frontend still publishes that payout
revision, so a superseded one is answered unknown-job even though
work_revision still finds its issued row and prepared record. A slow
run can outlast the retention before it reads the session: the jobs
are published before the phase's deadline starts, and the sessions
are read one at a time.

The kept share now passes with stale-job or unknown-job. Either way
it must leave no ledger row, it joins the answers after the
promotion, and the summary line names which answer came back. The
retry after a refused share on work that was current at its check
waits out unknown-job the same way, after the same no-row check, and
lists such jobs as retired past retention. Any other answer still
fails with the job's and the ledger's revisions.

With the two scratch delays the drill passed 3 of 3, the kept share
answered stale-job each time. Held 35 s more before that share, a
further scratch, the share was answered unknown-job and accepted
without a ledger row (1 of 1). Without the scratch the drill passed 3
of 3.

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

@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: 5cddaac435

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

…se deadline (Codex on #753)

Codex on #753: the new-tip phase's 30 s deadline bounded only its
reads of new work. Its share submissions could each wait for an
answer up to the client's 70 s limit, and its ledger reads had no
bound, so one slow answer could run the phase far past its deadline
or leave later miners nothing of it.

Every step in the phase now runs under what is left of one deadline,
through a small PhaseDeadline helper: the tip read, the revision
reads, the share on current-revision work and its retries, the share
on superseded work, the no-row checks, the wait for newer work and
the credit count. An expiry fails the drill, naming the phase, the
miner's session and job and how long the phase had run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke merged commit c8efdae into 3.x.x Oct 8, 2026
39 checks passed
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]>
@RobertClarke
RobertClarke deleted the RobertClarke/724-stale-job-new-tip-share branch November 3, 2026 20:46
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