Skip to content

3.x.x: renew readiness from a guarded tip poll so a slow rebuild no longer refuses current work as 'tip polling stale' (#622) - #643

Merged
kiwidream merged 1 commit into
3.x.xfrom
kiwidream/622-tip-polling-stale
Oct 1, 2026
Merged

kiwidream merged 1 commit into
3.x.xfrom
kiwidream/622-tip-polling-stale

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Refs #622.

This fixes the mechanism behind the tip polling stale refusal. It is not proven to be what #622's 2,000-wallet case hit on qbitd. That needs a #553 re-run, described at the end.

Problem

Readiness (last_poll) gates job preparation, share and block admission and /healthz, and has to be younger than PRISM_HEALTH_TIP_POLL_MAX_AGE_SECONDS (15 s). Before this PR it was renewed only when a refresh completed: by the reuse path or by the compact publication.

Every refresh starts with a refresh-grade node poll, and that poll already renewed the published tip's own observation clock. It did not renew readiness. At a 1 s reanchor every poll is a full rebuild with no overall deadline:

  • the window capture;
  • the bundle build;
  • the reserve, with three node-and-ledger proofs;
  • the publication lock.

Nothing else renewed readiness while that ran. So a rebuild that outlasted the health timeout after its own poll, or a run of rebuilds that failed after polling, made job preparation refuse current, valid work as tip polling stale, and made the frontend report itself unready. All the while, the node was answering on the published tip. #481 measured a 15 s refresh under load, and #598 saw /healthz unready for 12 s.

Change

Poll renewal. A refresh-grade node poll now renews readiness only when all of the following hold. The renewal is stamped when the poll was sent and never moves readiness backwards.

  • No newer observation has found another tip, and the poll found the published tip.
  • No readiness revocation raced it: the epoch is read before the node call. A refresh uses the epoch its compact build proof read.
  • The published template is within PRISM_TEMPLATE_MAX_AGE_SECONDS.
  • Readiness was not already revoked. Only a refresh restores revoked readiness, as before.
  • The chain observation agrees: a refresh renews from its own poll only after its chain observation and reconciliation succeed. A refresh that finds the cluster on a heavier chain (ChainObservationBehind) stops poll renewal until a refresh agrees again.
  • Under CTV settlement, a relay floor read no older than the poll is recorded, and the published fee still meets it.
    • A refresh renews after its own fee_policy.
    • The block wait re-reads getmempoolinfo before renewing; a failed read renews nothing and revokes nothing.
    • Each floor read is stamped with when its own getmempoolinfo was sent, and an earlier read never replaces a later one.
    • A refresh's fee policy must meet the floor actually kept, which may be a later, higher block-wait read. Publication also checks the work's fee against the current floor, so work built before a floor rise is never published.
    • A block-wait read that leaves the kept floor above the published fee revokes readiness, as a refresh's fee read would. Job admissions and submissions in flight then fail their readiness-generation checks.
    • Without CTV, a refresh renews right after its agreeing reconciliation.

Block-wait poll. The block wait polls on an unchanged notification only once readiness is at least one interval old, and at most once per interval. The interval is a third of PRISM_HEALTH_TIP_POLL_MAX_AGE_SECONDS, capped at 5 s: 5 s at the default 15 s. It always falls before readiness expires, so a short timeout polls that often. The interval is also how long the idle block wait waits for a new block. So an idle or healthy frontend makes no extra call, and the default 2 s refresh keeps readiness younger than the interval.

  • Each poll is one readiness check:
    • getblockchaininfo;
    • getnetworkinfo on a public chain, because the peer floor is part of readiness;
    • getmempoolinfo under CTV settlement, and only when the poll could renew.
  • It takes no database connection and no SETTLEMENT_LOCK, and uses the existing RPC deadline.
  • With PRISM_BLOCKWAIT_ENABLED=0 there is no such poll, and readiness ages with the refresh as before.

Unchanged. The revision, fee and lease checks. qbit_prism_work_refresh_stalled_seconds still pages on a stalled rebuild.

Metrics (the census grows by 2 families, 7 startup series and 7 populated series):

  • qbit_prism_tip_poll_age_seconds (gauge): the age of the readiness proof admission reads; -1 while readiness is unavailable.

  • qbit_prism_job_preparation_deferrals_total{reason} (counter), one per job preparation deferred WARN. The reason label set is closed:

    Reason Meaning
    tip_polling_stale readiness is older than the health timeout
    tip_polling_unavailable readiness was revoked
    new_tip_pending a newer tip's work is not published yet
    work_retired logged as payout snapshot stale (a payout revision or balance change, a newer tip replacing the parent, or a lease or publication mismatch), or as window_not_held (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)
    fee_floor the CTV fee is below the live relay floor
    other anything else
    • The tip refusals are now typed, and their log text is unchanged.
    • Tip authority is checked first, so tip_polling_stale can hide retired work behind it.

Docs.

  • The metric metadata and the generated inventory cover both new metrics.
  • The work_refresh_stalled_seconds text no longer says a completed refresh is the only thing that renews readiness.
  • The HA readiness section and the server README row for PRISM_BLOCKWAIT_ENABLED are updated.
  • The PrismWorkRefreshStalledCritical description and basis are updated. The alert expression is unchanged. The qbit-tools patch was regenerated from the pinned snapshot a007a142, and scripts/test_prism_alert_deployment.py passes.

Tests

New tests run against the in-memory coordinator fixture and gated fake-node RPCs (holds and barriers, no sleeps). They are not in the gated list.

coordinator::miner_tests::tip_poll (11 tests):

  • a_rebuild_held_after_its_poll_keeps_the_current_work_admitted
    • Setup: every refresh is a reanchor rebuild, readiness is aged, and the next refresh is held at persistence after its poll and chain observation.
    • Before the fix it fails: build_job answers pool-closed (tip polling stale). After the fix it passes, and also asserts:
      • the deferral counter;
      • a young tip-poll age while the refresh-stall age is at least 120 s, so the stall still pages.
  • Out-of-order cases (EP-STATE). None of these renews readiness:
    • an older poll answering after a newer one found another tip;
    • a poll that raced a revocation;
    • revoked readiness or an old template;
    • after a heavier-chain refusal, both that refresh's own poll and later polls.
  • Relay floor and probe cases:
    • a_refresh_held_before_its_relay_floor_read_does_not_renew_readiness (CTV);
    • without_ctv_a_refresh_renews_once_its_chain_view_agrees_whatever_fails_after;
    • a_refresh_fee_read_overtaken_by_a_later_higher_floor_cannot_vouch_for_its_fee;
    • work_built_before_a_raised_floor_is_not_published;
    • a_relay_floor_read_is_ordered_by_when_its_own_request_was_sent;
    • a_poll_that_raises_the_floor_above_the_published_fee_fences_jobs_in_flight.

coordinator::miner_tests::blockwait:

  • unchanged_notification_polls_for_aged_readiness_at_most_once_per_interval.
  • a_short_health_timeout_polls_before_readiness_expires: a 3 s health timeout gives a 1 s interval.
  • the_poll_interval_stays_inside_the_health_timeout: covers timeouts from 60 s down to 3 ms.
  • unchanged_notification_under_ctv_renews_only_with_a_fresh_relay_floor: a failed floor read renews nothing; a good read renews readiness and the floor together.

Each regression test failed on its parent commit and passes at head.

Run at the head of this branch, on 3.x.x 90327e8f (after #625, #642, #644, #648 and #645):

  • cargo fmt --all -- --check: clean.

  • cargo clippy -p qbit-prism-server --all-targets -- -D warnings: clean.

  • python3 scripts/generate_prism_metrics.py --check and python3 scripts/generate_prism_alerts.py --check: clean.

  • test/prism-native-tests.sh cargo-args -p qbit-prism-server --lib --test observability --test readiness_rpc --test stratum_protocol --test work_refresh_metric --test healthcheck_cli --test api_contract --test metrics_allocation --test stratum_rebuild_lane --test b619_gap_work_after_promotion --test candidate_window_switch (private PostgreSQL 16, test binaries run one after another):

    Suite Passed Ignored
    lib 621 passed, 1 failed (pre-existing, see below) 2
    observability 17 0
    readiness_rpc 11 0
    stratum_protocol 49 1
    work_refresh_metric 1 0
    healthcheck_cli 2 0
    api_contract 6 0
    metrics_allocation 4 0
    stratum_rebuild_lane 7 0
    b619_gap_work_after_promotion 6 0
    candidate_window_switch 15 0

    The lib failure is coordinator::commit_reconcile_tests::commit_reconcile_block_only_poll_errors_are_retried_then_unknown: a 5 s slow statement and a deadlock in fixture cleanup under the full parallel run. It passes alone (3 of 3), and the base 90327e8f fails it the same way on the same host (606 passed, 1 failed), so it is not this PR. It touches the block-only submit path, which this PR does not.

  • /code-review medium ran on each round, and an adversarial verifier approved the series. Its one finding (F1: a poll renewal no longer implied a recent CTV relay-floor read) is fixed here, with the two relay floor tests above.

  • Codex's review on this PR found five issues, all fixed with tests:

    • the interval ignored a shorter health timeout;
    • the 0.2 s floor did too;
    • a refresh's fee could be validated against a floor read that a later, higher block-wait read had already superseded;
    • floor reads were stamped before the market-rate estimate rather than at their own request;
    • a block-wait floor rise did not fence admissions already in flight.

Not run here and why

What would confirm #622

Run wallets_2000_share_to_spend_starves_first_jobs_until_604_is_fixed in release with PRISM_L4_SERVER_RUST_LOG=info, on the base and on this branch. Read each frontend's /metrics every second, in particular:

  • qbit_prism_job_preparation_deferrals_total{reason};
  • qbit_prism_tip_poll_age_seconds, qbit_prism_work_refresh_stalled_seconds and qbit_prism_node_observation_age_seconds.

How to read the result:

Observation Meaning
Base: refresh-stall age passes 15 s while node observations stay young, then tip_polling_stale. Branch: tip_poll_age stays under about 5 s and every worker gets work within 30 s. This was #622's mechanism.
work_retired climbs with template refresh deferred errors. A rebuild fails after the 6th landing; this PR does not fix that.
tip_poll_age and node observation age grow together. The node's RPC is saturated.

Follow-ups (not fixed here)

  • refresh_once has no overall deadline. It makes about ten serial RPCs, each allowed rpc_timeout, and that equals the health timeout.
  • Ledger::observe_chain_view_checked takes SETTLEMENT_LOCK and the cluster row FOR UPDATE even for a no-op same-tip observation. A publication does this at least four times, and the CTV broadcaster on every pass. Continuous FOR KEY SHARE issued-job batches from both frontends can starve that FOR UPDATE: PostgreSQL lets new KEY SHARE lockers bypass a queued FOR UPDATE. This is a plausible source of slow refreshes under fan-out.
  • A publication still stamps readiness against a relay floor read at the start of its refresh. This predates the PR.
  • work_retired still lumps the revision, tip and lease causes together.

Merge notes

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 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-01T20:57:06.822213Z 9b9c326 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: a158f38c8f

ℹ️ 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: f1fd312882

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

@kiwidream
kiwidream force-pushed the kiwidream/622-tip-polling-stale branch from 0537759 to a98ca18 Compare October 1, 2026 18:08

@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: a98ca18538

ℹ️ 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: 86c827c7b7

ℹ️ 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: c5b43f4dc4

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

…onger refuses current work as 'tip polling stale' (#622)

Readiness (last_poll), which job preparation, share and block admission
and /healthz require within PRISM_HEALTH_TIP_POLL_MAX_AGE_SECONDS, was
renewed only when a refresh completed. Every refresh starts with a
refresh-grade node poll, but at a fast reanchor each poll is a full rebuild
with no overall deadline, so a rebuild that outlasted the health timeout
after its poll, or a run of rebuilds failing after polling, refused the
current, valid work as 'tip polling stale' and reported unready while the
node answered on the published tip.

A refresh-grade poll now renews readiness, stamped when it was sent and
never backwards, only when: no newer observation found another tip and it
found the published tip; no readiness revocation raced it; the published
template is within PRISM_TEMPLATE_MAX_AGE_SECONDS; readiness was not already
revoked; no refresh has since found the cluster on a heavier chain; and,
under CTV settlement, a relay floor read no older than the poll is recorded
and the published fee meets it (a refresh renews after its own fee_policy,
or without CTV right after its agreeing reconciliation; the block wait
re-reads getmempoolinfo, and a failed read renews nothing). The block wait
polls on an unchanged notification once readiness is one interval old, at
most once per interval: a third of the health timeout, at most 5 s, which
is also its long-poll wait. Revision, fee and lease checks are unchanged;
work_refresh_stalled_seconds still pages on a stalled rebuild.

New metrics: qbit_prism_tip_poll_age_seconds (-1 while unavailable) and
qbit_prism_job_preparation_deferrals_total{reason} (tip_polling_stale,
tip_polling_unavailable, new_tip_pending, work_retired, fee_floor, other);
the tip refusals are typed with unchanged log text. Docs, the generated
inventory, the HA readiness section, the server README and the
PrismWorkRefreshStalledCritical rationale follow.

This fixes the mechanism behind the refusal; that it was #622's trigger on
qbitd is unproven until a #553 2,000-wallet release re-run reads the
deferral reasons beside tip_poll_age and work_refresh_stalled.

Under CTV settlement a refresh's fee policy must also meet the floor kept,
publication checks the work's fee against the current floor, floor reads are
ordered by when their own getmempoolinfo was sent, and a block-wait floor
read that leaves the kept floor above the published fee revokes readiness,
so admissions and submissions in flight fence. A retired authority keeps
#645's refusal context (payout snapshot stale, or window_not_held after a
writer timeline change) and counts as work_retired.

Squashed onto 3.x.x 90327e8 from the reviewed series a98ca18, 86c827c,
c5b43f4, 04ec7f2 (Codex approved 04ec7f2), itself squashed from
4a43b83, 9a13168, 8ed5f6c, 43882f5, 81c4b07, f1fd312, 0537759
(originally 1ba4776e, 9cccdb24, d671cbe9, 5d56b114, 3abba7cb on 4f4b218).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kiwidream
kiwidream force-pushed the kiwidream/622-tip-polling-stale branch from 04ec7f2 to 9b9c326 Compare October 1, 2026 20:52
@kiwidream
kiwidream merged commit d7812be into 3.x.x Oct 1, 2026
34 checks passed
kiwidream added a commit that referenced this pull request Oct 2, 2026
…bel database refusals truthfully, and page a PostgreSQL outage on its own rule (#581)

#586's nightly variants showed two gaps. Every outbox deadline was the
database clock, so a clock step moved it by the step. Forward, a second
frontend took a live claim whose block was still being offered. Backward,
the reconciliation row that takeover left waited two hours, and a dead
holder's claim would have waited lease + step. Separately, a PostgreSQL
outage held only PrismBlockCandidateMetricsUnavailable: the share-refusal
rules were gated on a snapshot whose freshness flaps while the publisher
waits on the database, and their counters were frozen in it. Database stalls
were refused backend-rpc-unavailable, blaming a healthy node.

Leases (option B, operator-chosen): migration 021 adds claim_renewals and
claim_lease_seconds, a partial index over claimed rows, and the
candidate_claim_observed_lease capability (offline, as 018). A frontend
times each claim version (token, renewals) on its own monotonic clock from
the reply that first shows it, and takes the row over only after the whole
lease, by compare and set on that version, whatever the row's schedule
unless it is parked. Holders fence on their token; their heartbeat deadline
is never extended from the database clock. A row last written later than
the clock proves a backward step and is due at once. candidates recover
waits out an observed lease (--unsafe-database-clock-expiry keeps the old
rule) and its release keeps a schedule within the row's own backoff.
candidates abandon times a claim the same way and abandons by compare and
set on the version it watched, so a forward step no longer lets it take a
pending row from a live holder (Codex on #646); the same flag keeps the
old rule. The pool-acquire inventory classifies the revocation helper.

Attribution and alerting: backend-database-unavailable for session
allocation, the payout reads, job persistence and resume when a SQLx error
is in the chain, and stale readiness when the latest refresh failed on the
database. rejections_total and accepted_shares_total render at scrape time,
the two share-refusal rules drop the snapshot gate, and
PrismDatabaseUnavailable (database collector unavailable for 2 m, paging)
is added, with the qbit-tools patch regenerated. #586's nightly tests now
assert the new behaviour.

Three adversarial verifications: leases and labels requested changes (a
renewal after a backward step stranding a dead holder's row; stale readiness
during an outage still blamed the node), both fixed with regression tests;
the re-verification approved. Rebased onto 3.x.x eedf331 as one commit
(PR #646's series eb5f65e, 1604a75, 5ce263d), past #642, #645 and
#643: the cardinality pins are 79 families, 313 startup and 964 populated
series; the stratum normalization pin stays 15. ReadinessState keeps
#643's poll fields and refresh_failed_on_database, whose comment now says
that a guarded tip poll (#622) decides whether readiness ages during a
database outage and this flag decides the label once it does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 2, 2026
…resh lock, so an older refresh cannot overwrite a newer one's (#581)

Codex on #646: refresh_once wrote refresh_failed_on_database after
refresh_once_inner had returned and dropped refresh_lock. Two overlapping
refreshes run serialized under that lock, but the older one could record
its outcome after the newer one had: a success overwriting the database
failure that followed it. If readiness then aged out, the refusal would
blame the node although the latest refresh failed on PostgreSQL.

The work under the lock moves to refresh_locked, and refresh_once_inner
records the outcome before the lock guard drops, so outcomes land in the
order the refreshes ran. The lock order (refresh lock, then readiness) is
the one the refresh already takes.

Test: a refresh paused in its revision read fails on the database while
the test holds readiness, so it cannot record yet. The refresh lock must
still be held, and the newer, successful refresh's outcome is the one
left. On the old code the lock was already free (the headline assertion
fails). The stale-readiness test's comment now names #643's guarded tip
poll.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 2, 2026
…bel database refusals truthfully, and page a PostgreSQL outage on its own rule (#581) (#646)

* 3.x.x: time candidate claim leases on the taker's monotonic clock, label database refusals truthfully, and page a PostgreSQL outage on its own rule (#581)

#586's nightly variants showed two gaps. Every outbox deadline was the
database clock, so a clock step moved it by the step. Forward, a second
frontend took a live claim whose block was still being offered. Backward,
the reconciliation row that takeover left waited two hours, and a dead
holder's claim would have waited lease + step. Separately, a PostgreSQL
outage held only PrismBlockCandidateMetricsUnavailable: the share-refusal
rules were gated on a snapshot whose freshness flaps while the publisher
waits on the database, and their counters were frozen in it. Database stalls
were refused backend-rpc-unavailable, blaming a healthy node.

Leases (option B, operator-chosen): migration 021 adds claim_renewals and
claim_lease_seconds, a partial index over claimed rows, and the
candidate_claim_observed_lease capability (offline, as 018). A frontend
times each claim version (token, renewals) on its own monotonic clock from
the reply that first shows it, and takes the row over only after the whole
lease, by compare and set on that version, whatever the row's schedule
unless it is parked. Holders fence on their token; their heartbeat deadline
is never extended from the database clock. A row last written later than
the clock proves a backward step and is due at once. candidates recover
waits out an observed lease (--unsafe-database-clock-expiry keeps the old
rule) and its release keeps a schedule within the row's own backoff.
candidates abandon times a claim the same way and abandons by compare and
set on the version it watched, so a forward step no longer lets it take a
pending row from a live holder (Codex on #646); the same flag keeps the
old rule. The pool-acquire inventory classifies the revocation helper.

Attribution and alerting: backend-database-unavailable for session
allocation, the payout reads, job persistence and resume when a SQLx error
is in the chain, and stale readiness when the latest refresh failed on the
database. rejections_total and accepted_shares_total render at scrape time,
the two share-refusal rules drop the snapshot gate, and
PrismDatabaseUnavailable (database collector unavailable for 2 m, paging)
is added, with the qbit-tools patch regenerated. #586's nightly tests now
assert the new behaviour.

Three adversarial verifications: leases and labels requested changes (a
renewal after a backward step stranding a dead holder's row; stale readiness
during an outage still blamed the node), both fixed with regression tests;
the re-verification approved. Rebased onto 3.x.x eedf331 as one commit
(PR #646's series eb5f65e, 1604a75, 5ce263d), past #642, #645 and
#643: the cardinality pins are 79 families, 313 startup and 964 populated
series; the stratum normalization pin stays 15. ReadinessState keeps
#643's poll fields and refresh_failed_on_database, whose comment now says
that a guarded tip poll (#622) decides whether readiness ages during a
database outage and this flag decides the label once it does.

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

* 3.x.x: record a refresh's database failure before it releases the refresh lock, so an older refresh cannot overwrite a newer one's (#581)

Codex on #646: refresh_once wrote refresh_failed_on_database after
refresh_once_inner had returned and dropped refresh_lock. Two overlapping
refreshes run serialized under that lock, but the older one could record
its outcome after the newer one had: a success overwriting the database
failure that followed it. If readiness then aged out, the refusal would
blame the node although the latest refresh failed on PostgreSQL.

The work under the lock moves to refresh_locked, and refresh_once_inner
records the outcome before the lock guard drops, so outcomes land in the
order the refreshes ran. The lock order (refresh lock, then readiness) is
the one the refresh already takes.

Test: a refresh paused in its revision read fails on the database while
the test holds readiness, so it cannot record yet. The refresh lock must
still be held, and the newer, successful refresh's outcome is the one
left. On the old code the lock was already free (the headline assertion
fails). The stale-readiness test's comment now names #643's guarded tip
poll.

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

* 3.x.x: label an issued persistence that outlived its deadline as the database's, whichever of the deadline and the statement failed first (#581)

CI shard 0 on 0b21539 failed compact_runtime_e2e's
issued_expiry_during_sql_wait test: a persistence queued on a database
lock past its 1 s deadline was refused backend-database-unavailable when
the statement its shortened statement_timeout cancelled failed first, and
backend-rpc-unavailable when the deadline fired first (a plain string
error). The label depended on which future completed first.

Persistence waits on the ledger alone (its clock and revision reads, the
batch transaction and its row locks, the compact repair it writes), so an
expiry is the database not answering in time. save_issued_record, the one
place that knows the persistence's own deadline, now marks a failure that
outlived it with a typed IssuedPersistenceExpired, and persist_issued_job
labels that backend-database-unavailable before the SQLx-chain rule. A
failure inside the deadline keeps that rule (a statement error is the
database's; an authority refusal stays backend-rpc-unavailable). The full
error chain is logged.

Tests: a unit test forces both orderings on the fake ledger (a statement
failing inside the deadline; the deadline elapsing while the save still
waits, its statement failing afterwards), both
backend-database-unavailable; without the classification the second is
labelled the node's, as in CI. The e2e test now runs both orderings on
PostgreSQL (the waiting statement cancelled inside the deadline; the lock
held past it) and expects the database label for each. A sweep of other
backend-rpc-unavailable assertions found none on a database-wait path.
prism-rejections.md names the case.

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

---------

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