Skip to content

3.x.x: a block-only proof whose offered block lost a tip race is answered stale-job, not ledger-confirmation-failed (#885) - #960

Open
kiwidream wants to merge 3 commits into
3.x.xfrom
orca/313-orphaned-proof-answer
Open

kiwidream wants to merge 3 commits into
3.x.xfrom
orca/313-orphaned-proof-answer

Conversation

@kiwidream

@kiwidream kiwidream commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Refs #885. This PR targets 3.x.x, so GitHub will not close the issue on merge: close #885 by hand once it lands.

What was wrong

A block-only proof waits in deferred_share_disposition (crates/qbit-prism-server/src/coordinator/miner_submit.rs) for its candidate's outcome. So does a share-pass proof whose block was captured under #657. If the node refused the offered block, or the chain proved it an orphan, the poll returned SaveOutcome::Failed. The miner was answered ledger-confirmation-failed and the frontend logged WARN share persistence failed. One such answer fires PrismShareAppendFailures, which points the operator at PostgreSQL even when the ledger is healthy and the block simply lost a tip race. A candidate abandoned before its offer has answered stale-job since #478. A block that lost a race after its offer did not.

The issue's proposed fix (answer every rejected or orphaned candidate stale-job) is too broad. The same reconciliation + rejected row is also written when:

  • the node refused an invalid block, or
  • the block's landing or post-offer processing failed (a real ledger or node failure).

Neither is a tip race.

What changed

  • candidate_lost_tip_race (miner_submit.rs) decides when the chain has proven a lost race. A proven race is answered stale-job, cause parent_grace, with an INFO line that names the block, its state, the node's reply and the row's reason. That is the answer a race lost before the offer already gets. Two cases count as proven:
    • The row is orphaned (3.x.x: lost-race regression test and a terminal orphan disposition for reconciliation rows #415), unless the node had rejected the block with a non-side-chain reply.
    • The row is in reconciliation, its offer was rejected with a side-chain reply (inconclusive, duplicate or duplicate-inconclusive, SIDE_CHAIN_REPLIES), and its last_error is the ordinary "block is not on the active chain after the offer" reason, or "block left the active chain" (the landing ran again after a lost payout-revision race and found the block inactive).
  • Everything else keeps ledger-confirmation-failed: an invalid-block reply, a landing refusal, a post-offer error. Its WARN now names the proof's path, the candidate state and the node's reply.
  • The poll reads offer_reply in the same statement and snapshot as its other columns. The column exists since migration 011, so there is no schema change.
  • The two reason prefixes are shared constants, NOT_ACTIVE_AFTER_OFFER_REASON_PREFIX and LEFT_ACTIVE_CHAIN_REASON_PREFIX (ledger/candidates.rs). The settler in coordinator.rs writes the same text as before through them.
  • Docs:
    • docs/prism-rejections.md: the ledger-confirmation-failed row no longer claims abandoned, side-chain and orphaned blocks, and the parent_grace cause row names the post-offer race.
    • docs/prism-ledger-ops.md: the capture section says the same, and names what is still answered ledger-outcome-unknown.

Unchanged: no metric family, label value, alert rule, configuration, migration or dependency. Cardinality and rule counts are unchanged.

No path of the found-block "not recorded" counter (#954) reaches this answer. That counter acts before the candidate is written, and these blocks were recorded and offered. The branch merges cleanly with orca/313-found-block-counter and orca/313-found-block-retry (git merge-tree).

Miner-visible change for these submissions: error code 20 ledger-confirmation-failed / share was not confirmed by the database becomes code 21 stale-job / stale job.

The node's reply for a lost race (verified from source)

The pinned qbit (v1.0.1, .github/scripts/install-prism-qbit.sh) answers submitblock as Bitcoin Core does. In src/rpc/mining.cpp (ProcessSubmittedBlock, around line 1370), a block it already had returns duplicate. A new valid block that was never connected returns inconclusive. The second case is a block with no more work than the tip, so the BlockChecked callback never fired. So a block that reaches the node after the competing block is answered inconclusive, and this fix applies. Not verified against a running node; no qbitd run was made.

Mixed 3.1.2/3.1.3 pair and rollback

Each frontend writes its own database and peer sync copies rows between the two; the candidate outbox is a local table that peer sync does not copy (ledger/table_inventory.rs). The answer is computed locally by the frontend that holds the submission, from its own database's outbox row. The row's columns and the last_error texts the settler writes are byte-for-byte what 3.1.2 writes. So in a mixed pair:

  • A 3.1.3 frontend answers a lost race stale-job and a 3.1.2 frontend still answers ledger-confirmation-failed.
  • Neither reads anything the other cannot write.

Rollback to 3.1.2 needs nothing: no stored data or format changed.

Tests

Run locally against a private PostgreSQL 16 cluster with PRISM_TEST_REQUIRE_INTEGRATION=1:

  • cargo test --locked --offline -p qbit-prism-server --lib -- --test-threads=4 miner_submit::acquire_tests d2_below_target_tests window_switch_tests::leased_candidate: 17 passed.
  • ... --lib -- commit_reconcile_tests::commit_reconcile_: 17 passed (after the review fixes, both lib runs together: 34 passed).
  • cargo test --locked --offline -p qbit-prism-server --test post_offer_revision_race --test lost_race_pin -- --test-threads=4: 8 + 8 passed. They assert the two reason texts.

New or changed tests:

  • miner_submit::acquire_tests::block_only_poll_terminal_results_preserve_checkout_success (extended) checks the real poll against a real outbox row. Expected answers:

    Row Answer
    orphaned after an accepted offer ParentGrace
    orphaned after an invalid-block rejection Failed
    orphaned after a side-chain reply ParentGrace
    rejected with inconclusive and the left-the-active-chain reason ParentGrace
    rejected with an invalid reply and the left-the-active-chain reason Failed
    rejected with inconclusive, duplicate or duplicate-inconclusive and the not-active reason ParentGrace
    rejected with an invalid reply and the not-active reason Failed
    rejected with a side-chain reply and a landing-failed reason Failed
    rejected with a side-chain reply and a post-offer-failed reason Failed
  • d2_below_target_tests::block_only_proof_whose_block_loses_the_tip_race_is_stale_job_without_credit (new, gated). The scripted node answers inconclusive. Asserts:

    • wire answer code 21 stale-job;
    • parent_grace counted once, payout_revision not counted;
    • no persistence WARN;
    • no credit.
  • commit_reconcile_tests::commit_reconcile_captured_block_that_loses_the_tip_race_is_answered_stale_job (new, gated): the same for a 3.x.x: a block found on the current tip is dropped when the payout revision moves between its submit check and its append's revision fence (#478 capture gap) #657 capture on the share path.

  • d2_below_target_tests::block_only_proof_the_node_rejects_fails_the_submission_without_credit (unchanged): its scripted reply "rejected" is not a side-chain reply, so it still asserts ledger-confirmation-failed.

Mutations, each applied, built and run, then reverted:

Mutation Caught by
predicate always false (the base's behaviour) acquire test, both new tests
reply check dropped acquire test, existing D2 rejection test
last_error check dropped acquire test (landing-failed row)
cause payout_revision acquire test, D2 test
orphan ignores the reply acquire test (invalid orphan row)
orphan branch ignores a side-chain reply (!rejected) acquire test (side-chain orphan row)
left-the-active-chain reason dropped acquire test

Lints and guards:

  • cargo fmt --all --check and cargo clippy --locked --offline -p qbit-prism-server --all-targets -- -D warnings are clean. The only warnings are the existing ones in vendor/sqlx-core.
  • scripts/check_prism_pool_acquires.py, scripts/check_gate_env_reads.py and scripts/check_toolchain_pin.py pass.
  • Both new gated tests are listed in test/prism-gated-tests.txt in sorted position.

Left to CI: the full PostgreSQL shards, the gate manifest proof (this host runs the gate in downgraded mode), the dual-writer lane and every other suite.

Engineering lessons

  • EP-OBSERVABILITY. The answer is attributed to the chain fact the frontend observed: a side-chain reply plus a not-active observation, or orphan evidence. Unproven, unknown and failed outcomes keep their own answers. Verified by the landing-failed and post-offer-failed rows, which still answer ledger-confirmation-failed, and by the null-reply race left at ledger-outcome-unknown. Operator docs now match the code.
  • EP-ERRORS. No new await, timeout or cancellation. The poll stays one statement in its own task under the existing bound, so no statement is orphaned and no lock is held longer.
  • EP-COMPAT. No schema, stored-format or written-text change. Old rows are read unchanged, and 3.1.2 and 3.1.3 frontends read each other's peer-synced rows as before.

Unverified

  • The qbit reply was read from source, not observed on a running node.

  • Load harness: crates/qbit-prism-load/src/run.rs (classify_committed_gap) treats a share later found in PostgreSQL after ledger-confirmation-failed as an ACK/commit divergence (exit 5). After stale-job it treats it as a durability loss (exit 4). The harness is not changed here. A real-node run where a race-lost block is later reorganised back onto the chain, crediting its share after a stale-job answer, would now report exit 4 instead of exit 5. Not observed; likely rare.

  • A side-chain race in which a third block arrives during the chain observation ("tip changed while observing candidate") is recorded as a post-offer processing failure and is still answered ledger-confirmation-failed. The window is milliseconds.

Release note

A block-only proof (or a captured share-pass proof) whose block lost a tip race after its offer, by a side-chain reply (inconclusive) or a proven orphan the node did not refuse as invalid, is answered stale-job (counted under qbit_prism_stale_job_rejections_total{cause="parent_grace"}). It is no longer answered ledger-confirmation-failed, so it no longer fires PrismShareAppendFailures or logs "share persistence failed" on a healthy ledger. Miners see code 21 stale job instead of code 20 for these submissions. This does not cover every lost race. A block the node first accepted and a competitor then replaced, or one whose landing is still running at the 15 s acknowledgement bound, is still answered ledger-outcome-unknown and can still fire the warning. A block the node refused as invalid still answers ledger-confirmation-failed.

Follow-ups not done

  • Races the node first accepted (null reply) and then reorganised away (3.2).
  • The unknown-job budget refusal's missing reason ID (3.x.x: a node-rejected or orphaned block-only proof is answered ledger-confirmation-failed, which fires PrismShareAppendFailures on a healthy ledger #885's second item), deferred.
  • A load-harness classification for a share credited after stale-job.
  • docs/prism-metric-metadata.json (the stale_job_rejections_total status, which generates docs/prism-native-metrics.md) and docs/prism-rust-migration.md (around line 2464) do not yet describe the post-offer race. Both are outside this PR's file scope.
  • A stale comment in crates/qbit-prism-server/tests/lost_race_pin.rs (around line 817) still says the acknowledgement path "fails" a proven orphan. That file is outside this PR's scope.

🤖 Generated with Claude Code

kiwidream and others added 3 commits December 2, 2026 18:20
…ered stale-job, not ledger-confirmation-failed (#885)

A deferred-share proof (block-only, or a share-pass block captured under
#657) whose candidate the node held only off its best chain (a side-chain
reply) and the chain observation after its landing found not active, or
that was settled as a proven orphan, is answered stale-job with cause
parent_grace and an INFO line, as a race lost before the offer is. It no
longer warns PrismShareAppendFailures or logs "share persistence failed"
on a healthy ledger.

A block the node refused as invalid, or a side-chain block whose landing
or post-offer processing failed, keeps ledger-confirmation-failed; its
WARN now names the node's reply. The not-active reconciliation reason is
a shared constant, so the answer path and the settler agree. A race the
node first accepted with a null reply is unchanged (ledger-outcome-unknown).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and found it inactive is a lost tip race too (#885)

The landing run again after a lost payout-revision race reconciles a block
it no longer finds active with "block left the active chain ...", now a
shared prefix constant. With a side-chain reply that is the same lost tip
race, so its deferred share is answered stale-job too. The docs say which
proven orphans count (not one the node refused as invalid), and when a
null-reply race can still be answered stale-job (orphan confirmations at 1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ger-confirmation-failed to a rejected offer (#885)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T00:17:49.478420Z 77acc80 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.

@qbit-reviewer qbit-reviewer 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.

Findings without an inline location

1. [low · red team] Load harness flags a share credited after a stale-job answer as durability loss

crates/qbit-prism-load/src/run.rs:5276

The PR changes deferred_share_disposition (crates/qbit-prism-server/src/coordinator/miner_submit.rs:1636-1653) so a lost tip race now returns Superseded(ParentGrace), sent on the wire as stale-job. The deferred share is not discarded. The comment at 1632-1635 says reconciliation can still credit it. If the block later becomes active again, the chain reconciler (ledger/blocks.rs:740-783) calls credit_deferred_share (859-877), which appends the share. The load harness's attribute_unexpected (crates/qbit-prism-load/src/digest.rs:95-125) collects committed rows that were never acknowledged, and run.rs:5405-5463 passes them to classify_committed_gap. That function only recognises ledger-confirmation-failed, ledger-outcome-unknown and NoResponse. A stale-job answer falls through to GapKind::DurabilityLoss at run.rs:5276, and the run reports a false durability finding (exit 4 instead of the earlier exit 5 AckCommitDivergence). The trigger is narrow: a block that lost the race must be reorganised back onto the active chain during a load run. PR.md acknowledges this gap as unverified.

Not posted: 2 nits and 1 lead. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5. Red team: deepseek-v4.1-flash-abliterated, checked by Claude Opus 5.5 (1 added).

@kiwidream

Copy link
Copy Markdown
Member Author

On qbit-reviewer's finding "Load harness flags a share credited after a stale-job answer as durability loss" (review 6161560792): the mechanism is right, and it is a known limit kept out of this PR on purpose. The 3.1.3 contract for #885 leaves crates/qbit-prism-load unchanged. The PR body says so under "Unverified": a race-lost block reorganised back onto the chain during a load run would now give exit 4 instead of exit 5. The harness fix is a non-loss bucket in classify_committed_gap for a deferred block-proof share committed after stale-job. A blanket stale-job exemption would hide real double credits. It is listed as a follow-up. No server change is needed: the server answer is correct, and the share can still be credited if the block becomes active again, as before.

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