Skip to content

3.x.x: retry a post-offer write that lost a payout-revision race in place, instead of an ALERT and reconciliation (#630) - #798

Merged
kiwidream merged 3 commits into
3.x.xfrom
orca/630-post-offer-revision-retry
Oct 28, 2026
Merged

kiwidream merged 3 commits into
3.x.xfrom
orca/630-post-offer-revision-retry

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #630. When the payout revision moved between the post-offer observation and the write, settle_offered_candidate sent the row to reconciliation with "ALERT: offered candidate could not be processed". That happened about once every 3 landings on the 400k two-frontend soak. #696 only documented the lines as benign.

What changes

Tests

  • New gated post_offer_revision_race: 5 tests. The 4 race tests fail on the base, and the node-failure test passes.
  • offer_lifecycle 26/26, lib coordinator 357/0 and lib ledger::candidates 22/0.
  • An independent check found no defect. Every retried write is refused by the revision fence before its first write, and nothing committed is applied twice. Its 10 mutations were caught except one test gap.
  • ledger_postgres 253/253, ledger_single_execution, lost_race_pin, migration_rollback and offer_latency pass.

Follow-up round (b018925)

  • Landing retry. The landing is split into Ledger::verify_landing, which does the verification, coinbase check and durable-range proof once, and land_verified_at_revision. Only the fenced transaction is retried, right after a fresh observation, so a retry has only a narrow race window. require_revision still runs before the first write.
  • Reorg. A retry whose observation shows the block inactive lands nothing; the row is reconciled as not active (WARN, not ALERT), and recover stops with NotActive.
  • Budgets. Landing and settlement get separate budgets. Retries use jittered backoff (about 50 ms, doubling, ±50%, capped by the deadline).
  • candidates recover retries its finish too, and counts blocks by first_confirmation.
  • Tests. Paused-time unit tests pin the deadline from the first lost race.
  • Metric and logs. Side effects run straight-line after the committed write. New counter qbit_prism_post_offer_revision_races_total{phase,outcome}, with the regenerated docs. The spent message names its real reason.
  • Results: post_offer_revision_race 8/8, revision_retry_tests 3/3, offer_lifecycle 26/26, ledger_single_execution 22/22, lost_race_pin 8/8, observability 17/17. Each new test fails on ac15308.

🤖 Generated with Claude Code

…lace, instead of an ALERT and reconciliation (#630)

Each post-offer write (the landing, the finish as submitted, the orphan
settlement) is fenced on the payout revision its own candidate observation
returned. When a sibling frontend recorded a tip or confirmed the block
between that observation and the write, require_revision refused the write
with an untyped error. settle_offered_candidate then settled the row in
reconciliation and logged "ALERT: offered candidate could not be processed"
(or "could not land"), about once in three landings on the 400k two-frontend
soak, although nothing had failed. #696 documented the line as benign.

- require_revision returns a typed ObservedRevisionChanged (same message),
  raised before the refused transaction's first write.
- One RevisionRetry per post-offer phase: on that error alone the caller
  observes again and writes again at the new revision, at most 3 times per
  phase. No retry starts 60 s or more after the phase's first lost race (not
  its start: the rebuild before the first write can take most of a minute
  under the load that makes the race likely), and a started write is never
  cancelled, so its outcome stays known. The landing is retried from the same
  rebuilt parts. A finish or orphan settlement is retried from a fresh
  observation and never repeats a committed landing. A confirmation a sibling
  already committed is not applied again.
- Each retry logs an INFO line ("post-offer write lost a payout revision
  race; observing again and writing at the new revision"). Every other error,
  and a race that outlasts the budget, keeps today's ALERT and reconciliation;
  the spent budget is named in the reason.
- candidates recover gets the landing retry through land_offered; its finish
  is unchanged.
- docs/prism-ledger-ops.md: the #630 runbook section now describes the retry,
  the INFO line, and when the ALERT can still appear.

Tests: tests/post_offer_revision_race.rs (PostgreSQL-gated, listed in
test/prism-gated-tests.txt) points the coordinator at a front for the
scripted node. The front runs a scripted step on the getblockhash that every
candidate observation makes after reading the revision and before the write,
so a revision move lands strictly between the two. It covers:
- a sibling confirmation racing the finish, after the landing committed;
- a bump racing the landing;
- a race on every write that spends the budget;
- a node failure after the landing;
- an orphan settlement whose race is retried and whose second, genuine
  refusal (the block is confirmed) keeps the ALERT.
Raced cases equal a no-race control's balances, payout entries, carry rows,
blocks and credits, with one submitblock and one confirmation. On the base,
the four race tests fail and the node-failure test passes. Lib unit tests
cover the error classification and the deadline running from the first lost
race.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T17:43:02.576762Z 5eb8a73 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.

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

No findings.

…nced commit, with a budget per write phase

Follow-ups from the pre-PR review of the post-offer revision-race retry.

- Effective landing retry. The landing is split into
  Ledger::verify_landing (the whole-window verification, the coinbase check,
  the stored body and the durable-range proof, done once) and
  Ledger::land_verified_at_revision (the fenced transaction alone).
  land_offered verifies first, then observes and commits. Only the commit is
  retried, each time right after a fresh observation, so the revision is read
  just before the transaction instead of before seconds of verification. The
  guarantees are unchanged: require_revision runs before the transaction's
  first write, and an audit that landed meanwhile is compared by digest.
- A landing retry lands only a block its fresh observation still shows
  active. If the block left the active chain, nothing lands and the row is
  reconciled as a block not active after its offer (WARN, no ALERT).
  candidates recover stops with NotActive.
- One budget per write phase. A generic through_revision_races driver owns
  a RevisionRetry for the landing and another for the settlement (finish or
  orphan), so the landing's races no longer spend the settlement's retries or
  start its clock.
- Jittered backoff between retries: about 50 ms, doubling per retry, ±50%,
  capped by the deadline.
- candidates recover retries its finish through the same driver, and
  counts qbit_prism_blocks_total by first_confirmation instead of
  unconditionally.
- The driver writes nothing itself; every side effect (the blocks counter,
  the wake, the orphan metric and its WARN) is applied straight-line after the
  committed write returns.
- New counter qbit_prism_post_offer_revision_races_total{phase,outcome}
  (landing|settlement, retried|spent), with registry, zero-registration,
  metadata, the generated inventory and the observability census and
  cardinality pins.
- A spent budget names its actual reason: all 3 retries used, or the 60 s
  deadline from the first lost race passed after N retries.
- Runbook (#630 section) updated for all of the above.

Tests:
- tests/post_offer_revision_race.rs gains three PostgreSQL-gated tests:
  - a landing retry after a reorg lands nothing;
  - the landing and the settlement each have their own budget;
  - candidates recover retries its finish and counts only a first
    confirmation.
- Each fails on ac15308's coordinator, and the counting half fails on a
  mutant that counts unconditionally.
- New unit tests drive the phase driver under paused time. The deadline runs
  from the first lost race (they fail on the M4b-style mutant that seeds it
  when the phase begins), only a lost race is retried, the backoff stays
  within bounds, and the counter counts.

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: b018925873

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

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

No findings.

…etry starts at or past it (Codex P2 on #798)

RevisionRetry::again decided to retry before its backoff. The backoff is
clipped to the time left before the deadline, and the runtime can wake late,
so a race lost just before the 60 s deadline, with retries left, slept to the
deadline or past it and then still started another full observation and
write, contrary to the documented limit.

again() now sleeps first and decides afterwards. Once the deadline has
passed, it returns the spent-budget refusal that names the deadline as the
reason. The retry count, the INFO line and the retried counter are recorded
only when a retry really starts; the INFO line's backoff_ms is the time
actually waited.

New paused-time unit test
coordinator::revision_retry_tests::a_race_lost_just_before_the_deadline_starts_no_retry.
A refusal 1 ms before the deadline, with retries left, produces no further
attempt. The test fails (3 attempts) when the deadline is checked against
the time before the sleep.

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

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

No findings.

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