Skip to content

3.x.x: hold block submission for the whole cluster from the ledger, whatever each frontend's switch says (#664) - #682

Merged
RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/prism-664-cluster-submission-hold
Oct 5, 2026
Merged

RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/prism-664-cluster-submission-hold

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Closes #664. Part of #291. Builds on #661 (the per-frontend switch) and #676 (#666's page for a held frontend).

Problem

PRISM_BLOCK_SUBMIT_ENABLED=0 (#661) holds one frontend, and only a frontend started with it. On a pre-production or rehearsal deployment against a restored mainnet ledger, any frontend started without the variable would claim and offer every pending row. A leased candidate also skips the pre-offer staleness probe, so its block would reach mainnet's submitblock.

Change

This adds a cluster-wide hold, stored in the ledger, that every frontend obeys whatever its own variable says.

Migration 023 (offline; declares the capability block_submission_hold = 1)

  • qbit_prism_submission_hold: one permanent row holding the reason, when it was set and by whom. A CHECK keeps the three consistent, and a trigger refuses deleting the row.
  • qbit_prism_submission_hold_events: an append-only journal of each set and clear that changes the hold. It records who ran it (session_user and current_user), why, and how many candidates were pending, and a trigger refuses UPDATE, DELETE and TRUNCATE, like the fatal-state journal.
  • The capability makes a pre-023 binary refuse the database at connect, so no older frontend can ignore the hold.
  • Like 021 and 022, 023 is applied with every frontend stopped, in the cutover's stopped window. The pair runs nothing yet, and the mainnet cutover stops every frontend for migrate anyway.

Enforcement

  • Claims. claim_candidate and claim_fanout read the hold in their writer fence and claim nothing while it is set. It is the same single statement as before, so the pinned statement counts do not change.
  • Reservations. reserve_offer_within reads the hold FOR SHARE on the hold's own row in each of its transactions.
    • It refuses with SubmissionHeld, an error and never a Refused, so the claim is released and the row stays pending instead of being abandoned.
    • submission-hold set locks that row FOR UPDATE. A hold therefore commits either before a reservation, which is then refused, or after one, whose single offer completes.
    • Nothing else locks the hold's row, and the read takes no lock on the cluster row, so the hold adds no wait behind a landing or blob GC. A leased candidate's reservation still locks nothing there; a non-leased one's capture check (3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478) reads the cluster row FOR SHARE as before.
  • CTV broadcaster.
    • run_pass refuses while the hold is set, logged at debug level rather than as a warning every pass.
    • Every send rechecks the hold after its claim renewal.
    • A hold set during an attempt hands its claim back unattempted, bounded at 5 s like the shutdown hand-back, which now shares the helper.
  • Write guard. writable and the hold-aware fence share one column list and one check, so a new halt condition reaches both.

Operator command: qbit-prism-server submission-hold show|set|clear

  • show prints read-only JSON: held, reason, set_at, set_by, last_event, schema_supports_hold and pending_candidates.
    • It needs only PRISM_DATABASE_URL, opens one connection, gives up after 15 s, and also reads a pre-023 ledger.
  • set --reason uses the operator connection, which works while frontends run and on a halted cluster. It keeps a hold already in force.
  • clear --reason [--offer-pending-candidates] is refused while candidates are pending, unless the flag says to offer them.
  • Both reasons are checked before connecting, by the operator-reason rule that fatal-state clear and candidates abandon now share.

Visibility

  • check-config stays offline, as documented and tested. It prints that a cluster-wide hold in the database overrides PRISM_BLOCK_SUBMIT_ENABLED, and points at submission-hold show and self-check.
  • self-check reports submission_hold and warns on stderr when held. The value is the show document, sampled read-only beside the heartbeats, or null when unreadable.
  • Health and heartbeat.
    • block_submission_enabled stays the frontend's own switch, as in 3.x.x: add a block submission and broadcast kill switch for rehearsals against a real node (#291) #661, so a frontend started without the variable is still visible under a hold.
    • block_submission_hold carries held, reason, set_at and set_by as the frontend last read them. held is null until the first read succeeds, and a later failed read keeps the last one, so a database outage neither reports nor pages a frontend as held.
    • Health reads the hold in the same statement as the payout revision.
    • A running frontend logs once when the hold appears and once when it clears.
  • Gauge. qbit_prism_block_submission_enabled combines the two at every health publication: 0 when either holds, 1 when neither does, and -1 when the switch is on but the frontend has not read the hold yet. It is now a live family, rendered at scrape time.
  • PrismBlockSubmissionHeld (3.x.x: page when a production frontend runs with block submission held (qbit_prism_block_submission_enabled != 1) #666) now describes the cluster hold and an unread hold, and gives the hold's remedy.

Docs

  • docs/prism-ledger-ops.md: a new subsection, "Holding the whole cluster (023, 3.x.x: hold a rehearsal database for every frontend that connects to it, not only frontends started with PRISM_BLOCK_SUBMIT_ENABLED=0 (#291) #664)". It covers what the hold stops (claims in every state, including the landing of already-offered rows, while candidates recover still lands accepted blocks), the commands, the journal, visibility, and the set and clear procedures for rehearsal and cutover.
  • docs/prism-rust-migration.md: the 023 note, and the migration-transaction range now ending at 023.
  • docs/prism-configuration.md and the server README row for the variable.
  • A go-live check in docs/mainnet-deployment.md: submission-hold show reports "held": false.

Fixtures and gates for 023

  • Version lists and capability counts.
  • UNDO_023 where a fixture models an older writer.
  • Capability rollback pairs in migration_rollback.rs.
  • The recovery-evidence script's versions and capability checks.
  • New checkout-site entries for the pool-acquire gate.

Tests

Test Kind What it shows
candidate_storm_restart::a_held_ledger_holds_a_frontend_started_without_the_switch_until_it_is_cleared real binary The issue's acceptance case, described below
candidate_lease_tests::submit_disabled_tests::a_cluster_hold_stops_an_enabled_frontend_until_it_is_cleared PostgreSQL See below
candidate_lease_tests::submit_disabled_tests::the_hold_fence_waits_for_a_hold_being_set_and_never_for_the_cluster_row PostgreSQL A reservation waits for a hold being set and is then refused. With a landing holding the cluster row FOR UPDATE, clear and a reservation without the capture check, as a leased candidate's is, still complete
ctv_fanout_bookkeeping::a_cluster_hold_claims_and_sends_no_fanout_until_it_is_cleared PostgreSQL Both frontends' passes are refused, and nothing is claimed, attempted or sent; once the hold clears, every fanout is sent
ctv_fanout_bookkeeping::a_hold_set_mid_attempt_hands_the_fanout_claim_back_unsent PostgreSQL A hold set during an attempt refuses its send; the claim is handed back with nothing recorded, no claim is made while held, and everything is sent after the clear
config_cli::check_config_reports_the_block_submission_kill_switch_first CLI The cluster-hold line in both modes
config_cli::submission_hold_set_and_clear_refuse_a_blank_reason_before_reaching_the_database CLI A blank reason is refused before connecting, and --reason is required by both
self_check_cli CLI Report shapes carry submission_hold: null when unreadable, and the show document on a migrated ledger
metrics::snapshots::tests::block_submission_gauge_follows_the_kill_switch_and_the_cluster_hold unit Every combination of the switch and a held, clear or unread hold
coordinator::submission_hold_view_tests::a_failed_read_keeps_the_hold_last_read unit The hold is unknown until a read succeeds, then a failed read keeps the last one

In the real-binary acceptance test:

  • The ledger is held with qbit-prism-server submission-hold set.
  • A frontend started without PRISM_BLOCK_SUBMIT_ENABLED, with a CTV broadcaster configured, runs across two health heartbeats over 3 due candidates.
  • Its counting fake node sees no submitblock, rows stay pending and unclaimed, and no dispatch slot is used. Its heartbeat reports its switch on and the hold set.
  • submission-hold clear is refused with "while candidates are pending (3)".
  • After clear --offer-pending-candidates, show reports the journaled clear as last_event, and the same running frontend offers each block exactly once.

In the in-process PostgreSQL test:

  • An enabled frontend's earlier claim is refused at the reservation with SubmissionHeld, and its row is left untouched.
  • No new claim is made, no dispatch slot is used, and health() reports the switch on and the hold set.
  • set is idempotent and refuses a blank reason; so does clear.
  • clear is refused while one row is pending. Once cleared with the flag, the same frontend lands the row with one offer.
  • The journal holds the set and the clear with their reasons and pending counts. It refuses UPDATE, DELETE and TRUNCATE, and the hold row refuses DELETE and TRUNCATE.

Local runs, on PostgreSQL 16:

  • the in-crate, CLI, CTV, observability and binary tests above;
  • the migration, fixture and statement-count suites: offer_lifecycle, migration_rollback (its backup and restore tests included), ledger_postgres, candidate_storm and candidate_storm_restart (its pinned 27- and 65-statement counts), the window, epoch and orphan migrations, api_2x, audit_completeness, signing_transition, candidate_dispatch_probe, share_partitions_postgres, and the whole lib (its physical-failover tests included);
  • the Python unit suite (938 tests; the Docker-only compose tests run in CI) and scripts/test_prism_alert_deployment.py against the pinned qbit-tools snapshot;
  • fmt, clippy -D warnings, and the settings, metrics, alert-artifact, pool-acquire, gate-read and scenario checks.

Notes and risks

  • Work already past its check completes. A hold stops claims and reservations from the moment it commits. An offer that had already reserved completes its one submitblock, and a fanout send already past its last hold check completes. A hold set before any frontend starts, as the rehearsal procedure says, has neither.
  • Everything the outbox and the broadcaster do waits. Like 3.x.x: add a block submission and broadcast kill switch for rehearsals against a real node (#291) #661's switch, a hold stops claims in every state, not only pending. On a drained cutover or a discarded rehearsal there is nothing else to wait. Otherwise, an offered block's landing and a sent fanout's confirmation tracking resume when the hold clears, and candidates recover can land an accepted block meanwhile.
  • This release needs every frontend stopped. 023 is offline, as the coordinator approved.
  • Silencing the page. While a cluster is held, every frontend reads 0 on the gauge, so PrismBlockSubmissionHeld pages. A rehearsal or cutover hold must be scoped in the alerting as the runbook says.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…hatever each frontend's switch says (#664)

it. On a rehearsal against a restored mainnet ledger, a frontend started
without it would claim and offer every pending row.

Migration 023 (offline, like 021 and 022) adds a permanent one-row
table, qbit_prism_submission_hold, and an append-only journal of each
set and clear that changes it, qbit_prism_submission_hold_events, and
declares block_submission_hold = 1 so a pre-023 binary refuses the
database at connect. While the hold is set:
- claim_candidate and claim_fanout claim nothing, in the same single
  writer-fence statement as before;
- reserve_offer_within reads the hold FOR SHARE on the hold's own row
  and refuses with SubmissionHeld, leaving the row pending. Only
  submission-hold set and clear lock that row, so a hold commits either
  before a reservation or after one, and the read takes no lock on the
  cluster row, so the hold adds no wait behind a landing or blob GC;
- the CTV broadcaster refuses its pass and rechecks before every send;
  a hold set during an attempt hands its claim back unattempted,
  bounded at 5 s like the shutdown hand-back.

qbit-prism-server submission-hold show|set|clear: show is read-only,
needs only PRISM_DATABASE_URL, gives up after 15 s and reads pre-023
ledgers; set and clear require --reason and are journaled, and clear is
refused while candidates are pending unless --offer-pending-candidates.
fatal-state clear, candidates abandon and submission-hold share one
operator-reason rule, and writable shares its columns and checks with
the hold-aware fence.

Health and the heartbeat keep block_submission_enabled as the
frontend's own switch and add block_submission_hold as the frontend last
read it, in one statement with the payout revision: held is null until
the first read succeeds, and a later failed read keeps the last one, so
a database outage neither reports nor pages a frontend as held. A
running frontend logs when the hold appears and clears.
qbit_prism_block_submission_enabled is now live: 0 when the switch or
the hold holds, 1 when neither does, -1 when the switch is on and the
hold has not been read yet. check-config stays offline and says where
the hold is reported; self-check reports submission_hold and warns.
PrismBlockSubmissionHeld (#666) now covers the hold and its remedy.

The ops runbook documents the hold, its journal and the set and clear
procedures for rehearsal and cutover; the migration notes, the
configuration reference, the server README and the go-live checks name
it. Fixtures, capability rollbacks, the recovery-evidence script and the
pool-acquire gate cover 023.

Tests: a real-binary test (a frontend started without the switch on a
held ledger sends no submitblock until clear --offer-pending-candidates,
then offers each block once), PostgreSQL tests of the held claim and
reservation, the hold fence (a reservation waits for a hold being set,
never for the cluster row), the journal's immutability, the held
broadcaster and a hold set mid-attempt, and CLI, self-check, gauge and
hold-view tests.

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

chatgpt-codex-connector Bot commented Oct 5, 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-05T22:08:32.344068Z cb3481f Manual request
ℹ️ 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: 21b41738a5

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

Comment thread crates/qbit-prism-server/src/tools.rs Resolved
…664)

Both went through DatabaseConfig::from_env, which also validates
PRISM_INSTANCE_ID and PRISM_DATABASE_MAX_CONNECTIONS, so a frontend-only
setting left invalid could stop an operator holding or releasing the
cluster, against the documented contract. DatabaseConfig::url_from_env
reads and checks the URL alone, as from_env does, and from_env now
calls it. The real-binary test runs every hold command with an invalid
instance ID and connection count.

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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: cb3481f321

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

@RobertClarke
RobertClarke merged commit 0f132bf into 3.x.x Oct 5, 2026
34 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/prism-664-cluster-submission-hold branch October 5, 2026 22:27
RobertClarke added a commit that referenced this pull request Oct 5, 2026
… lane index becomes migration 024

#682 took 023 for the cluster-wide block submission hold, which is
offline and transactional. The fanout lane index is now 024:
024_fanout_lane_index.sql, REQUIRED_SCHEMA_VERSIONS, NATIVE_MIGRATIONS,
ONLINE_MIGRATIONS (13, 17, 24) and derive_online, so 023 stays in the
migration transaction and only 024 is built online after the commit.
The 2.x.x undo drops 024's index before 023's hold; the version pins,
the recovery-evidence script, the share-hash backfill test's online set,
the cutover rehearsal's step label, the gated-test name and the docs say
024. claim_fanout keeps #682's hold check before the survey and the lane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 5, 2026
…tial index, so a claim never scans settled history (#668) (#679)

Settled fanouts stay in qbit_ctv_fanout_artifacts after their 1,000th
confirmation, and mainnet adds about 65,000 to 130,000 a year at #521's
block rate. The claim lane matched them on its status and schedule
predicates and dropped them only after reading them: a sequential scan of
the whole table on every claim, which a broadcaster pass repeats once per
fanout it attempts. EXPLAIN (ANALYZE, BUFFERS) on PostgreSQL 16, warm
cache, prepared, per claim, 7,500 watched fanouts: 63 ms at 100,000 settled
fanouts and 357 to 412 ms at 1,000,000 (1 GB heap).

Migration 024 adds qbit_ctv_fanout_artifacts_lane_idx, a partial index over
the fanouts the lane may still claim (to broadcast or check, or confirmed
under 1,000 deep), keyed by next_broadcast_attempt_at. The lane
(Ledger::fanout_lane_sql) gathers its candidates into one array first: the
due ones as two ranges of that index, never attempted and scheduled at or
before statement_timestamp() (stable, so the index serves it as a bound),
and the deep checkpoint (FANOUT_CHECKPOINT_SQL) from
qbit_prism_fanout_checkpoint_idx. It looks them up by primary key and
applies its full predicate and order as before. The only change in
behaviour: a fanout falling due during the claim statement itself waits
for the next poll.

After, same data: 1.6 ms (100,000 settled, 377 due) and 1.8 to 2.0 ms
(1,000,000 settled, 377 due), the generic plan included. A claim now costs
what the due fanouts cost; the settled history only deepens the primary
key. When every watched fanout is due, as when the broadcaster cannot
recheck each one every 5 s, it reads them all: 28 ms at 100,000 settled and
38 ms at 1,000,000, against 67 and 412 ms before.

024 is additive like 019 and 020 (no capability, no shutdown proof, not
offline) and applied online like 013 (ONLINE_MIGRATIONS). On an existing
ledger the runner builds the index with CREATE INDEX CONCURRENTLY after the
migration transaction commits and records 24 once it is valid, so no write
to the fanout table waits for the build, a found block's landing
(persist_fanouts) included: about 0.6 s at 1,000,000 settled fanouts. A
fresh or empty source applies the file inside the transaction. It is 024
because #682 took 023, the offline block submission hold: an upgrade from
22 applies 023 in the migration transaction and then builds 024 online.

Tests:
- ledger_postgres::fanout_lane_plan::a_fanout_claim_poll_never_reads_the_settled_history
  plans and executes both statements of a claim poll, the survey and the
  lane, prepared, over 20,000 settled and 500 watched fanouts, through five
  custom plans and the generic one: no sequential scan of the fanout
  table, the lane index read, at most 16 fanout rows visited by the lane
  (lossy-bitmap rechecks counted), the survey within the watched fanouts.
  The pre-024 lane fails it ("scanned the fanout table"), and so does a
  single IS NULL OR range filter ("visited 508 fanout rows").
- ledger_postgres::fanout_lane_plan::migration_024_builds_the_lane_index_without_blocking_fanout_writes
  upgrades a ledger at 23 while a fanout write is open: the build waits
  for it, another fanout write lands meanwhile, then the index is valid,
  every required version is recorded and the lane claims through it. An
  in-transaction build fails it with a lock timeout.
- ledger::fanout::tests pin the lane's copied SQL without a database: the
  candidate predicate against 024's index predicate, and the checkpoint
  against the one FANOUT_CLAIMABLE_SQL admits.

Migration pins, the share-hash backfill test's online set, the cutover
rehearsal's step label, the recovery-evidence script and the gated-test
list include 024; prism-ledger-ops.md and prism-rust-migration.md describe
the lane, its costs and the upgrade.

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