Repository navigation
3.x.x: time CTV fanout claim leases on the taker's monotonic clock, and label session timeouts and hung refreshes by the dependency they wait on (#654, #655) - #667
Merged
Conversation
…o a database clock step neither double-claims nor strands a fanout (#654) #646 moved candidate claims onto an observed lease (#581), but CTV fanout claims still compared `claim_expires_at` and `next_broadcast_attempt_at` with `clock_timestamp()`. A forward database clock step, which a failover can cause, made a live claim look expired: a second frontend took the fanout over and broadcast it again, and the holder's settlement write was refused. A backward step left a dead holder's claim waiting lease + step, and an attempt or confirmation check scheduled before it waiting its delay + step. Migration 022 (offline, as 021) adds `claim_renewals` and `claim_lease_seconds` to `qbit_ctv_fanout_artifacts`, a partial index over claimed fanouts and the `fanout_claim_observed_lease` capability. Fanout claims now follow #581's contract: - Every fanout claim poll surveys the claimed fanouts and times each version (token, renewals) on the frontend's own monotonic clock, through the same ClaimObserver, now shared in ledger/claim_observer.rs with one instance per kind of claim. It takes a fanout over only after watching the same version for the whole lease, by compare and set on that version, before the lane, which takes only unclaimed due fanouts. A claimed fanout is taken over whatever its schedule unless held at infinity. - The holder is fenced on its token alone. Its lease is its own monotonic deadline: the broadcaster's 90 s attempt deadline is below the 120 s lease every renewal takes, now named constants with a compile-time check. - The survey makes due, at once, every unclaimed fanout whose last write is later than the database clock (a backward step), and a shutdown release keeps its schedule but never later than the clock. - Every statement that clears a fanout claim clears its lease and version. - `ledger::revoke_fanout_claims` replaces the tests' ad hoc `claim_expires_at` rewrites. The lane's claimable predicate is unchanged in meaning, written once and shared by the lane, the takeover and the survey. EXPLAIN on 100k settled fanouts: the survey is two index scans (0.3 ms); the lane's plan and cost are the same as before. Tests: five ledger clock-step tests (forward on a live claim and its holder's writes; backward on a dead holder, on a retry, after one renewal, and on a shutdown release) and a broadcaster test with a forward step in the middle of an attempt. All six fail on b8aeb29 with their headline assertion and pass here. The fanout tests that expired a claim by rewriting `claim_expires_at` now revoke it, and assert that only a takeover fences the old holder. Migration pins, the recovery-evidence script, the pool-acquire inventory and the gated-test list include 022. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hey were waiting on, so a database stall no longer reads as the node's (#655) #646 labelled database refusals backend-database-unavailable but left two paths blaming the node during a database stall. The Stratum session's own timeouts (session allocation, job persistence, job resume, initial job delivery) could not tell what the backend was waiting on, and a template refresh that hung on the database, rather than failing, recorded no database failure, so the stale-readiness refusal that followed named the node. A new crate::waiting module lets work name the steps it waits on the ledger database, into a tracker its timer reads when the deadline passes, while the work is still pending (dropping the work ends its marks). The tracker reaches the work through a task-local, as READ_DEADLINE does, so the MiningBackend trait and its implementations are unchanged. The coordinator marks the ledger allocation, the whole issued persistence (consistent with IssuedPersistenceExpired, so the label never depends on which deadline passes first), each ledger step of resume and of the issuance-authority reads, and every ledger step of a refresh. Node calls, CPU work and admission stay unattributed and keep backend-rpc-unavailable. Marks are never placed inside work shared between tasks: a waiter marks its own await of a shared read, and the resume flight's shared reconstruction keeps its own tracker, which each waiting session follows. The session runs each backend call under waiting::timeout and labels an expiry with StratumError::timed_out. The coordinator registers the refresh in flight with its start and tracker; a submit refused for aged-out readiness is the database's when the latest refresh failed on it (#646), or when the refresh in flight has outlived its deadline, the health timeout, and is still waiting on the database. Tests: allocation, persistence and resume stalled on the database through the real coordinator; a refresh held in its first ledger read past its deadline; controls for a refresh held on the node or inside its deadline, and for a backend stall it does not name; a third-party backend naming its step; the tracker's own semantics. The four regressions fail on 3.x.x b8aeb29 with backend-rpc-unavailable. Docs: the rejection registry, the stratum admission note, the metric inventory and the load harness's counted classes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: aca451e924
ℹ️ 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".
…s, mark the replacement-lease payout read, and tighten the revocation hook (#654, #655) CI shard 0 on aca451e: live_regtest's two fanout lost-reply tests waited 60 s for a survivor that, since #654, takes a dead owner's fanout over only after watching its claim for the whole 120 s lease. Their shared expire_dead_lease helper revoked candidate claims but only backdated claim_expires_at for fanouts, which no longer ends a fanout claim. It now revokes both kinds. Both tests pass locally against the pinned qbitd 1.0.0. /code-review high on #667: - prove_published_lease's payout_state read was unmarked, so an issuance under a replacement lease that stalled there still read as the node's. It is now an on_database step. - revoke_fanout_claims touches only claimed fanouts and no schedule. A takeover does not wait for a schedule, and its due_now option could only make held (infinity) fanouts due. - The survey reply decoding and the takeable-claim filter are shared in claim_observer.rs by the candidate and fanout claim polls. - refresh_once_inner's failure flag no longer shadows on_database. - Docs: a claimed fanout is held only at infinity (its own schedule is no hold); push a dead holder's fanout with broadcast-ctv by revoking its claim first; issued-job persistence counts as one database step as a whole, as IssuedPersistenceExpired does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stence, so a session timeout in its repair's encoding or admission is not the database's (#655) Codex on #667 (P2), and /code-review high: persist_issued_job marked the whole issued persistence as a database step. On the compact repair path that includes the repair lock, build-slot admission and the blocking encode, so a session deadline passing during CPU work or admission read as the database's although no statement was pending. The two writes in save_with_dependency are now the marked steps: the issued batcher's save, whose batcher does nothing but write batches, and the compact repair's save. The clock, revision, window and payout reads were already marked where they run. A persistence that outlives the issued job's own deadline stays the database's, as #581 decided (IssuedPersistenceExpired), and docs/prism-rejections.md now says which persistence steps are marked. Test: a persistence whose repair is held in its encode at a session deadline reads Unattributed. With the whole persistence marked it read Database (the test fails); the batch-write stall test still reads the database's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…54-655-ctv-claims-clock # Conflicts: # crates/qbit-prism-server/tests/ctv_fanout_bookkeeping.rs # docs/prism-rust-migration.md # test/prism-gated-tests.txt
This was referenced Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #654. Closes #655.
Both are follow-ups to #581/#646 and are needed before go-live for the PRISM 3 production pair. Safety held before. Both are liveness and attribution problems.
Problem
#654: CTV fanout claims still decided a lease by the database clock.
claim_fanouttook a fanout onceclaim_expires_at <= clock_timestamp().claim_expires_at > clock_timestamp().next_broadcast_attempt_atwith the same clock.#655: two database-stall paths were still labelled
backend-rpc-unavailable.session allocation timed out,job persistence timed out,job resume timed out) could not tell what the backend was waiting on.Change
#654: the observed lease of #581, applied to fanout claims
Migration 022 (
fanout_claim_observed_lease), offline like 021:claim_renewalsandclaim_lease_secondstoqbit_ctv_fanout_artifacts.qbit_ctv_fanout_artifacts_claimed_idx.fanout_claim_observed_lease = 1.stoppedordrained.Takeover.
Ledger::fanout_claim_survey_sql).(claim_token, claim_renewals)on the frontend's own monotonic clock. TheClaimObserver, its survey decoding and its takeable-claim filter are now shared by candidates and fanouts inledger/claim_observer.rs, with one observer per kind of claim.FOR UPDATE SKIP LOCKED). This runs before the lane.infinity.Holder.
Retries and checks.
Other.
ledger::revoke_fanout_claimsreplaces the tests' ad hocclaim_expires_atrewrites. It touches only claimed fanouts, and no schedule.docs/prism-ledger-ops.mdreplaces "Not changed" with a section covering the contract, the cost, revocation,broadcast-ctvand the upgrade.#655: a timeout names the dependency the work was waiting on
Mechanism:
crate::waiting.on_database) into a tracker.READ_DEADLINEdoes, so theMiningBackendtrait and its eight implementations are unchanged.Session timeouts.
waiting::timeout: allocation, persistence, resume, initial job delivery and payout-address validation.backend-database-unavailablewhen the work was on a database step, andbackend-rpc-unavailableotherwise, as before.IssuedPersistenceExpired).Hung refresh.
refresh_once_innerregisters the refresh in flight (its start and tracker) and marks every ledger step of the refresh.Migration notes (D5)
022 is an offline upgrade, exactly like 021. Apply it together with 021 if both are pending.
broadcast-ctvand disable automatic restarts.qbit_prism_instancesrow reportstoppedordrained.A pre-022 binary takes fanout claims over by the database clock and never writes the columns a post-022 one times, so mixed versions are refused at every later connect by the capability. Migration 022 is independent of #663's share-hash backfill, which this branch includes.
Tests
#654. Six new tests. Each fails on b8aeb29 with its headline assertion and passes here:
ledger_postgres::clock_steps::a_forward_database_clock_step_never_ends_a_live_fanout_claim_earlya forward step handed a live fanout claim to another frontend…::a_backward_database_clock_step_never_stretches_a_dead_fanout_holders_leasea backward step stretched a dead fanout holder's lease past its own length…::a_backward_database_clock_step_never_stretches_a_fanout_retrya backward step stretched a fanout retry by the step…::a_backward_step_then_one_renewal_never_strands_a_dead_fanout_holders_rowa renewal after a backward step left a dead fanout holder's row waiting out the step…::a_fanout_release_after_a_backward_step_never_stretches_its_next_attemptthe released fanout is 7198.98 s out, though it was due when claimedctv_fanout_bookkeeping::a_forward_database_clock_step_mid_attempt_keeps_the_holders_claim_and_settlement(the real broadcaster, a forward step while its send is held)a forward step handed a live fanout claim to another frontendThese cover the claim lane, the holder fence and the retry schedule, forward and backward, built like
tests/support/clock_steps.rs.The live lost-reply tests (
live_regtest::lost_reply_tests) kill a fanout's owner and hand its claim to a survivor. Their sharedexpire_dead_leasenow revokes fanout claims as it does candidate claims. Both pass in CI and locally against the pinned qbitd 1.0.0.#655. Four regressions fail on b8aeb29 with
backend-rpc-unavailableand pass here:Controls:
backend-rpc-unavailable;Unattributed. With the whole persistence marked it readDatabaseand the test fails.There are also seven unit tests for
waiting, and a third-party backend test.CI on 44d0a10 (this branch merged with 3.x.x ec29d74): every check green, including the four PostgreSQL shards (live_regtest in shard 0) and "Prove every Rust PRISM gated test executed".
Local runs on 44d0a10. Private PostgreSQL 16,
PRISM_TEST_REQUIRE_INTEGRATION=1,--test-threads=4unless noted:--test ledger_postgres--test ctv_fanout_bookkeeping--test offer_lifecycle--test migration_rollback(--test-threads=2)--test refresh_liveness--test compact_runtime_e2e--test ledger_single_execution--test stratum_protocol/stratum_admission/readiness_rpc--lib(--test-threads=2)-p qbit-prism-load --test harnessOn this loaded host (load average ~11) some lib modules hit
canceling statement due to lock timeoutor a tight lease deadline at 2–6 threads:park_testsandconnect::acquiremigrate one schema per test under the database-wide migration advisory lock. b8aeb29 fails them the same way.All six, and their modules (23 tests), pass in three consecutive
--test-threads=1runs. The same applies to onemigration_rollbacktest at 4 threads.Also clean:
cargo fmt --all --checkcargo clippy --locked --workspace --all-targets -- -D warningscheck_prism_pool_acquires.py,check_deleted_test_map.py,check_e2e_scenarios.pygenerate_prism_metrics.py --check,check_gate_env_reads.py,check_prism_settings.pyrecovery_evidence_requires_the_migrations_startup_requires, which checks thatscripts/prism-recovery-evidence.sqlrequires 022.Plan check. EXPLAIN on 100k synthetic settled fanouts:
broadcast_candidate_idxrange plusclaimed_idx), 0.3 ms;Review
/code-review high, fixed:payout_state()read;revoke_fanout_claimsmaking held fanouts due;on_databasename;/code-review high, filed:broadcast-ctvtaking over only revoked claims within one pass (3.x.x: broadcast-ctv cannot take over a dead frontend's fanout claim within one pass (follow-up to #654) #670), and moving attribution below hand-placed marks (3.x.x: database-stall attribution relies on hand-placed on_database marks (follow-up to #655) #671)./code-review high, declined: one survey per claim poll costs 0.3 ms at 100k rows, and candidates do the same.Not run here
live_regtestvariants (clock jump, disk exhaustion), which need libfaketime and the nightly lane. The 3.x.x: nightly e2e for PostgreSQL disk exhaustion and wall-clock jumps, and a per-PR Stratum transcript replay (#575) #586 clock-jump test does not involve CTV.Risks
broadcast-ctvalone takes over only revoked claims (3.x.x: broadcast-ctv cannot take over a dead frontend's fanout claim within one pass (follow-up to #654) #670); the ops doc gives the revocation SQL.health_timeoutafter that refresh starts.job persistenceandinitial job deliverytimeouts are not answered on the live session path, so their labels show only in tests.Follow-ups
broadcast-ctvcannot take over a dead frontend's fanout claim within one pass.on_databasemarks.🤖 Generated with Claude Code