Skip to content

3.x.x: signing-transition command and migration 019 for signing-key rotation (#461 S-B) - #464

Merged
kiwidream merged 6 commits into
3.x.xfrom
cutover-safety/signing-transition
Sep 22, 2026
Merged

kiwidream merged 6 commits into
3.x.xfrom
cutover-safety/signing-transition

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Part of #461 (S-B). Target 3.x.x, base pin 587aef59. 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_fingerprint because "the code has no reset path". This adds the path:

qbit-prism-server signing-transition --confirm (src/ledger/signing_transition.rs, wired like policy-transition in tools.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 row FOR UPDATE (the lock every configure takes), it:

  1. refuses unless the cluster is writable (not halted);
  2. refuses unless the saved fingerprint equals the invoking configuration's (so the journal records the keys being retired);
  3. refuses unless every qbit_prism_instances row is stopped or its heartbeat is older than max(3 × PRISM_HEALTH_REFRESH_SECONDS, 15 s) by the database clock (the self-check rule; a SIGKILLed frontend never writes stopped; an unknown or future-dated age counts as live);
  4. refuses while any row is in CandidateState::UNFINISHED_SQL (stricter than configure, which only refuses other keys);
  5. sets config_fingerprint = NULL (guarded by AND config_fingerprint = $previous) and inserts a row in the new immutable qbit_prism_signing_transitions journal (migration 019_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);
  6. prints the next operator steps. Without --confirm it prints the plan, reads nothing and exits non-zero.

The first new-key frontend's configure then pins the new fingerprint; an old-key configure is refused with the existing mismatch message. policy-transition keeps refusing key changes (#289's trim; the only change there is resolved_policy becoming pub(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.md gains 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 in test/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/reconciliation rows with the same keys refuse (while configure would 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 a FOR UPDATE holder and decides on the committed value; nothing lands between the checks and the reset (a heartbeat and an old-key configure both wait on pg_locks; the reset commits first); a failed journal write rolls the reset back; halted cluster refuses; lock-timeout abort changes nothing; --confirm absent changes nothing.

Mutation checks (applied and restored): commit between checks and reset → nothing_lands_between_the_checks_and_the_reset fails; status-string-only liveness → 4 fail; every non-stopped row quiescent → 4 fail; only pending blocks → offered-rows test fails; LOCK TABLE removed → 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; full make test-prism-postgres green apart from the host's known ledger_postgres connection exhaustion at full parallelism.

Not covered (deliberate)

  • Multi-epoch verification stays deferred. Every ledger-attestation verifier (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, and backfill-ctv/import-audits abort 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.
  • A partitioned-but-alive old frontend with a stale heartbeat can still write fatal_error while the fingerprint is NULL (fatal-error writers are not fingerprint-fenced); same exposure as today's hand reset; recovery documented.
  • One-shot tools write no heartbeat and are invisible to the instance check; CTV fanout claims are not checked (only outbox rows). The signing journal is not exported by prism-recovery-evidence.sql. An old-key restart after the reset re-pins the old fingerprint (safe, tested, documented: keep restarts disabled).
  • Overlaps open PRs Isolate compact job persistence from settlement locking #456 (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


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

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@blacksmith-sh

This comment has been minimized.

kiwidream and others added 6 commits September 18, 2026 15:31
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
kiwidream force-pushed the cutover-safety/signing-transition branch from a9d75bf to 9276919 Compare September 18, 2026 19:36
@kiwidream
kiwidream merged commit 2e9bf19 into 3.x.x Sep 22, 2026
20 checks passed
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