Repository navigation
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
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
a158f38 to
f1fd312
Compare
There was a problem hiding this comment.
💡 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".
0537759 to
a98ca18
Compare
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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]>
04ec7f2 to
9b9c326
Compare
…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]>
…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]>
…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]>
Refs #622.
This fixes the mechanism behind the
tip polling stalerefusal. 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 thanPRISM_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:
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/healthzunready 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.
PRISM_TEMPLATE_MAX_AGE_SECONDS.ChainObservationBehind) stops poll renewal until a refresh agrees again.fee_policy.getmempoolinfobefore renewing; a failed read renews nothing and revokes nothing.getmempoolinfowas sent, and an earlier read never replaces a later one.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.getblockchaininfo;getnetworkinfoon a public chain, because the peer floor is part of readiness;getmempoolinfounder CTV settlement, and only when the poll could renew.PRISM_BLOCKWAIT_ENABLED=0there is no such poll, and readiness ages with the refresh as before.Unchanged. The revision, fee and lease checks.
qbit_prism_work_refresh_stalled_secondsstill 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;-1while readiness is unavailable.qbit_prism_job_preparation_deferrals_total{reason}(counter), one perjob preparation deferredWARN. Thereasonlabel set is closed:tip_polling_staletip_polling_unavailablenew_tip_pendingwork_retiredpayout snapshot stale(a payout revision or balance change, a newer tip replacing the parent, or a lease or publication mismatch), or aswindow_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_floorothertip_polling_stalecan hide retired work behind it.Docs.
work_refresh_stalled_secondstext no longer says a completed refresh is the only thing that renews readiness.PRISM_BLOCKWAIT_ENABLEDare updated.PrismWorkRefreshStalledCriticaldescription and basis are updated. The alert expression is unchanged. The qbit-tools patch was regenerated from the pinned snapshota007a142, andscripts/test_prism_alert_deployment.pypasses.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_admittedbuild_jobanswerspool-closed(tip polling stale). After the fix it passes, and also asserts: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.x90327e8f(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 --checkandpython3 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):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 base90327e8ffails 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 mediumran 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:
Not run here and why
live_regtest, the 3.x.x: Chain-event scenarios under session load (L4) (#487 S15) #553 chain-events load and the 2,000-wallet weighted-recipients case did not run, and the mechanism is unproven on a real node.scripts/test_prism_alert_promql.pyneeds promtool, which is not on the host. The alert expression is unchanged.What would confirm #622
Run
wallets_2000_share_to_spend_starves_first_jobs_until_604_is_fixedin release withPRISM_L4_SERVER_RUST_LOG=info, on the base and on this branch. Read each frontend's/metricsevery second, in particular:qbit_prism_job_preparation_deferrals_total{reason};qbit_prism_tip_poll_age_seconds,qbit_prism_work_refresh_stalled_secondsandqbit_prism_node_observation_age_seconds.How to read the result:
tip_polling_stale. Branch:tip_poll_agestays under about 5 s and every worker gets work within 30 s.work_retiredclimbs withtemplate refresh deferrederrors.tip_poll_ageand node observation age grow together.Follow-ups (not fixed here)
refresh_oncehas no overall deadline. It makes about ten serial RPCs, each allowedrpc_timeout, and that equals the health timeout.Ledger::observe_chain_view_checkedtakes SETTLEMENT_LOCK and the cluster rowFOR UPDATEeven for a no-op same-tip observation. A publication does this at least four times, and the CTV broadcaster on every pass. ContinuousFOR KEY SHAREissued-job batches from both frontends can starve thatFOR UPDATE: PostgreSQL lets new KEY SHARE lockers bypass a queued FOR UPDATE. This is a plausible source of slow refreshes under fan-out.work_retiredstill lumps the revision, tip and lease causes together.Merge notes
3.x.x90327e8f. The observability census now has 79 families, 312 startup series and 963 populated series, counting everything since merged (3.x.x: return a landing's freed heap to the kernel with malloc_trim after each block landing (#600) #627, 3.x.x: give first jobs their own admission, so a session opening during a same-tip rebuild storm no longer waits for the whole fan-out (#604) #625, 3.x.x: answer a session's submits while its own job rebuild is built and persisted, and measure what still waits for it (#621) #642, 3.x.x: refuse a block on work from a lost replication gap before its offer, and stop issuing that work after an async promotion (#619) #645) and these two.work_retired.a98ca185…04ec7f24, which Codex approved at04ec7f24with CI green; the message names every earlier SHA.stratum.rs, 3.x.x: give first jobs their own admission, so a session opening during a same-tip rebuild storm no longer waits for the whole fan-out (#604) #625's admission code or 3.x.x: answer a session's submits while its own job rebuild is built and persisted, and measure what still waits for it (#621) #642's session-loop changes.🤖 Generated with Claude Code