Repository navigation
3.x.x: signing-transition command and migration 019 for signing-key rotation (#461 S-B) - #464
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Closed
3 tasks
This comment has been minimized.
This comment has been minimized.
Signing-key rotation resets the pinned cluster fingerprint, and today the rehearsal does that by hand with nothing recording it. Migration 019 adds qbit_prism_signing_transitions: an immutable journal (trigger like 014's) that keeps the retired fingerprint, the retired policy document with both old public keys, every instance row with its measured heartbeat age and the freshness window applied, and the unchanged payout revision. It is additive and declares no capability: a binary that does not know the table never reads or writes it, so a 2.x.x or 3.x.x frontend that predates it keeps working. The rest is the mechanical registration a new migration needs: REQUIRED_SCHEMA_VERSIONS, NATIVE_MIGRATIONS and the migrate_schema apply block in migration.rs (mirroring 014: plain, no shutdown proof); the verbatim version lists and messages the tests assert in offer_lifecycle, ledger_2x, index_trim and session_sequence; the pre-006 historical fixture in ledger_2x, which undoes 019 together with 014; the required_versions array in the recovery evidence script; and the migration note in the migration guide. No behaviour beyond knowing 019. Co-Authored-By: Claude Fable 5.1 <[email protected]>
D4 accepted signing keys on every frontend on condition that a rotation is rehearsed before cutover. Ledger::configure already treats a NULL cluster fingerprint as a rotation and refuses to pin over unfinished candidates signed with other keys, but nothing sets the fingerprint to NULL except an operator's hand-written UPDATE, with no guard and no record. `qbit-prism-server signing-transition --confirm` is that reset. Everything is decided and written in one transaction that holds the settlement and order advisory locks, the instance registration lock and the cluster row FOR UPDATE, the same row lock configure takes and every candidate writer reads FOR SHARE, so a concurrent startup or write serialises behind it and then sees the reset. It refuses a halted cluster (fatal-state clear compares the pinned fingerprint, so the halt must be cleared first), a pinned fingerprint that is not the invoking configuration's (the journal must record the keys being retired), any frontend whose row is not `stopped` unless its heartbeat is older, by the database clock, than the freshness window self-check derives from PRISM_HEALTH_REFRESH_SECONDS (a killed frontend never writes `stopped`; an unreadable status or a future-dated heartbeat is unknown and counts as live), and any unfinished block candidate whatever keys it carries, which is stricter than configure's other-keys test. A fingerprint that is already NULL is reported with the last journal row and nothing is written, so a lost commit response is resolved by running again. One 120-second deadline covers the node calls, the lock waits and the transaction; the reset statement runs before the journal insert so any failure rolls both back. Without --confirm the command prints what it would check and do, reads neither its configuration nor the database, and exits non-zero. The invoking configuration is resolved exactly as startup and policy-transition resolve it, by calling policy_transition's resolved_policy; that function's visibility changes from private to pub(super) and nothing else in policy_transition.rs changes, so policy-transition keeps refusing key changes. Multi-epoch verification stays deferred: the journal's previous_policy is its anchor. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Gated tests for signing-transition against a disposable PostgreSQL, each fixture in its own database because the command holds the database-scoped settlement and order advisory locks. The killed frontend is a real health heartbeat never followed by `stopped`, aged by one UPDATE of heartbeat_at rather than a sleep. Refusals: a fresh `starting` or `running` heartbeat, an unreadable status, a future-dated heartbeat, both frontends named when both are live; a killed frontend refuses at ages 0 and 14 seconds and, with PRISM_HEALTH_REFRESH_SECONDS=20, still at 16, then proceeds at 16 under the default window, through the CLI and its real environment reader; a `pending` candidate, and `offer_reserved`, `offered` and `reconciliation` rows whose keys equal the invoking configuration's, which configure itself accepts; a halted cluster; the new-key environment. Effects: the journal row with the old fingerprint, both old public keys, the instance rows with their measured ages and the unchanged payout revision; the first new-key configure pins; old-key configure and old-environment reruns are then refused; the journal is immutable; an old-key start after the reset re-pins and the reset can be repeated. Concurrency: the command waits on a holder of the cluster row and judges what that holder committed; held at its journal write after every check has passed, neither a heartbeat nor a configure can land before its commit; an injected journal failure after the reset statement rolls the fingerprint back and releases the locks. Without --confirm nothing is read or changed, even with an empty environment. Under the three review mutants each fails as intended: a commit between the checks and the reset fails the held-at-journal test; a status-only liveness rule fails the killed-frontend test; ignoring offered rows fails the same-keys test. The successful CLI run prints its wall clock under --nocapture for the rotation rehearsal to compare against. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The ledger operations guide said signing-key rotation was deferred. It now has a command, so the guide gets a "Signing-key rotation" section: what signing-transition checks and writes and under which locks, the step-by-step procedure with the old-key environment, the freshness rule a killed frontend is judged by, that the first configure after the reset pins whatever keys it brings (an old-key start undoes the rotation safely and the command can be rerun), that pre-rotation bundles verify only with the old public keys the journal keeps, and that backfill-ctv and import-audits must not run with the new key against them. Multi-epoch verification remains deferred and is said so. It also records the one exposure the command shares with the by-hand reset: the fatal-state writers are not fenced on the fingerprint, so a partitioned-but-alive old frontend, indistinguishable from a killed one once its heartbeat is stale, could halt the cluster while the fingerprint is unset, when neither fatal-state clear nor any startup can proceed. The recovery (restore previous_fingerprint from the journal row, clear with the old keys, rerun) is written down, and the command's halted refusal points at it. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The deadline comment and the operations guide said one 120-second deadline covers every lock wait. It does not: the operator connection sets lock_timeout from PRISM_DATABASE_LOCK_TIMEOUT_MS (5 seconds by default) and a 15-second statement timeout, so a contended cluster row, instance table or advisory lock ends the command after about five seconds with "canceling statement due to lock timeout". That is safe, it is before COMMIT and rolls back, but the guidance was wrong. Both now say that 120 seconds is the ceiling for the whole command, what bounds a single wait and a single statement, and that a lock timeout means something still holds the row or the locks, which is what a running frontend or tool does: confirm everything is stopped and rerun rather than raising the timeout blindly. The command attaches the same advice to a lock_not_available failure; nothing else about its behaviour changes. A test holds the cluster row, runs the CLI with a 200 ms lock timeout, and checks the message, that nothing changed, and that the same command then succeeds. The guide's rerun sentence also states its assumption: reporting the journal row after an ambiguous commit relies on nothing having pinned a fingerprint in between, which is why restarts stay disabled until the new-key frontends start; if an old-key process did start, the rerun refuses while it is live and otherwise resets a second time. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The census guard added by #457 requires every fresh pool checkout in the production module graph to carry an exact classification. The signing-transition transaction begins through Ledger::begin like policy-transition does, so it takes the same delegated ledger policy. Co-Authored-By: Claude Fable 5.1 <[email protected]>
kiwidream
force-pushed
the
cutover-safety/signing-transition
branch
from
September 18, 2026 19:36
a9d75bf to
9276919
Compare
25 of 40 tasks
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.
Part of #461 (S-B). Target
3.x.x, base pin587aef59. Carries migration 019 (number confirmed free by the C workstream).What
D4 accepted signing keys on every frontend on condition that a rotation is rehearsed before cutover; #291's criterion describes a hand reset of
qbit_prism_cluster.config_fingerprintbecause "the code has no reset path". This adds the path:qbit-prism-server signing-transition --confirm(src/ledger/signing_transition.rs, wired likepolicy-transitionintools.rs) — run with the old-key environment. In one transaction under the SETTLEMENT and ORDER advisory locks,LOCK TABLE qbit_prism_instances, qbit_ledger_writer_lease(share row exclusive) and the cluster rowFOR UPDATE(the lock everyconfiguretakes), it:qbit_prism_instancesrow isstoppedor its heartbeat is older thanmax(3 × PRISM_HEALTH_REFRESH_SECONDS, 15 s)by the database clock (theself-checkrule; a SIGKILLed frontend never writesstopped; an unknown or future-dated age counts as live);CandidateState::UNFINISHED_SQL(stricter thanconfigure, which only refuses other keys);config_fingerprint = NULL(guarded byAND config_fingerprint = $previous) and inserts a row in the new immutableqbit_prism_signing_transitionsjournal (migration019_signing_transitions.sql: previous fingerprint, previous policy document with both old public keys, every instance row with its measured heartbeat age, the freshness window, the unchanged payout revision);--confirmit prints the plan, reads nothing and exits non-zero.The first new-key frontend's
configurethen pins the new fingerprint; an old-keyconfigureis refused with the existing mismatch message.policy-transitionkeeps refusing key changes (#289's trim; the only change there isresolved_policybecomingpub(super)). Migration 019 is registered mechanically (migration.rs, verbatim version lists in tests,prism-recovery-evidence.sql,prism-rust-migration.md).docs/prism-ledger-ops.mdgains a "Signing-key rotation" section that replaces the "deferred" sentence and documents the halted-while-unset recovery and the lock-timeout advice.Tests (
crates/qbit-prism-server/tests/signing_transition.rs, 13 gated tests, ids intest/prism-gated-tests.txt)Fresh heartbeat refuses (running/starting/unreadable/future-dated); killed-not-stopped frontend refuses until its heartbeat is stale, then proceeds; stale rows of every other state do not refuse; pending row refuses;
offer_reserved/offered/reconciliationrows with the same keys refuse (whileconfigurewould accept them over a by-hand NULL); success path with the journal row, new-key pin, old-key mismatch, idempotent rerun; the command waits behind aFOR UPDATEholder and decides on the committed value; nothing lands between the checks and the reset (a heartbeat and an old-keyconfigureboth wait onpg_locks; the reset commits first); a failed journal write rolls the reset back; halted cluster refuses; lock-timeout abort changes nothing;--confirmabsent changes nothing.Mutation checks (applied and restored): commit between checks and reset →
nothing_lands_between_the_checks_and_the_resetfails; status-string-only liveness → 4 fail; every non-stopped row quiescent → 4 fail; onlypendingblocks → offered-rows test fails;LOCK TABLEremoved → same race test fails.Measured on minidev-alex1 (22 cores, PostgreSQL 16.15, the disposable cluster from
test/prism-native-tests.sh, dev-profile binary, empty fixture): successful command 63–67 ms spawn-to-exit (3 runs) — #291's rehearsal should compare against this.signing_transition(13),ledger_postgres(178,--test-threads=4),migration_rollback(8), fmt, clippy, gate/settings/toolchain checks — all pass; fullmake test-prism-postgresgreen apart from the host's knownledger_postgresconnection exhaustion at full parallelism.Not covered (deliberate)
qbit-prism-audit-verify,backfill-ctv,import-audits) checks one configured key and rejects an embedded-key mismatch (crates/qbit-prism/src/lib.rs); after a rotation pre-rotation bundles verify only with the old key, andbackfill-ctv/import-auditsabort on the first old-key row. Public API and read tier verify no signatures and are unaffected. The journal keeps both old keys as the anchor for a future key history.fatal_errorwhile the fingerprint is NULL (fatal-error writers are not fingerprint-fenced); same exposure as today's hand reset; recovery documented.prism-recovery-evidence.sql. An old-key restart after the reset re-pins the old fingerprint (safe, tested, documented: keep restarts disabled).docs/prism-ledger-ops.md) and Isolate compact job persistence from settlement locking #456/3.x.x: complete pool checkout timing and guard its coverage #457 (test/prism-gated-tests.txt): trivial rebase for whichever lands second.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.