Repository navigation
v2.0.2 fix: bound candidate replay and audit finalization - #258
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. |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ption The audit artifact store listed its root through the long-lived pinned directory descriptor. Some kernels and overlay filesystems serve a stale or truncated enumeration through a description that was read once and mutated afterwards: on an aarch64 Docker host a conflict snapshot written moments earlier was absent from the next scan, so quarantine deduplication wrote a second copy and metrics and retention observed an empty root. The 2.x.x baseline reproduced this as test_psql_segment_gap_without_ledger_rows_quarantines_existing_slot and six audit-artifact test failures on that host. Every scan now reopens "." relative to the pinned descriptor, verifies the inode identity before and after enumerating, and closes the fresh description. Authority still flows only from the pinned descriptor, no pathname is trusted, and the quarantine, metrics and retention semantics are unchanged. The new tests simulate a stale pinned enumeration and a swapped root, and pin that every scan opens and closes its own description. Refs #255 Co-Authored-By: Claude Fable 5.1 <[email protected]>
A found block's canonical audit bundle carries two window-sized arrays: the accepted shares and the reward manifest's counted shares. The audit store published its external body by reading the candidate whole, decoding it with json.loads, comparing it against the logical bundle as one dictionary graph, cutting segments from a materialized share list, encoding the compact body with one json.dumps and reconstructing the whole window again to verify it, so every accepted block held several window-sized structures in the lease-bearing process. audit_bundle_view adds an immutable, bounded view over a canonical artifact: small members are parsed eagerly, the share arrays and the transaction leaf arrays are replayable lazy sequences decoded through bounded read windows, equality with dictionaries streams record by record, and a streaming encoder reproduces the compact json.dumps bytes in bounded chunks. One JSON value remains the decoder's unit; values above a soft limit are counted in the scan statistics, never rejected. The audit store accepts a view or a dictionary everywhere the logical bundle flows: the canonical source is digested, compared (by identity for a view of that inode, member by member otherwise) and gzip-published through chunks; share segments are cut from slices bounded by the segment size and written through chunked immutable and mutable writers; the compact body is encoded chunk by chunk; the reconstruction check scans the body and each segment lazily and matches records against the logical window; and the byte length comes from the descriptor. Exact canonical bytes, digests, wrapper identity binding, proof validation, immutable publication and idempotent retries are unchanged, and the sorted v1 candidate-identity encoder is never substituted for the typed canonical bytes. Accepted-block persistence consumes the view: externalized rows carry the body pointer as before, the leaf arrays are materialized only for the statement (bounded by the block's transaction count), and the legacy inline lane without a body store splices the verified canonical bytes into the statement literal instead of re-encoding a decoded graph. Refs #255 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…he artifact view The bundle compiler copied a non-list share window into a list before a canonical build and decoded the builder's complete output with json.load, which materialized the whole window twice on the found-block path. The one-shot builder input now streams any replayable share sequence record by record (each json.dumps covers at most one batch), a refuted daemon mirror is routed exactly as before, and a canonical build with an output artifact returns the bounded view of that artifact, scanned once through bounded windows with cancellation checked per read; a scan that decoded an oversized value reports it. Embedders without an artifact still receive the decoded document. Finalization treats the bundle as a mapping, reads only header members after landing, and closes the view on every exit of the ordered phases so a retired landing never pins the candidate file. Exact inode transfer, adopter failure cleanup and first-failure ownership are unchanged. The end-to-end tests drive the real Rust builder and verifier when the tools are available: streamed sequences are never copied, canonical bytes and digests are exact, the compact body reconstructs through the Rust canonicalizer, retries are durable no-ops, tampered or foreign artifacts are rejected, an oversized single field publishes through the bounded writers, generations release their descriptors without cyclic garbage collection, cancellation during the output scan cleans the candidate, and accepted-block persistence consumes the view on both the externalized and the inline lane. Refs #255 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ues within bounded windows The lazy record sequences of a canonical artifact view kept their byte-offset checkpoints in an in-memory array, which grows with the window, and a record larger than a read window was decoded whole during the initial scan to find its end. Checkpoints are now fixed-width entries appended to an unlinked temporary index file shared by the view's lazy arrays and read back by position, so the index scales with the window on disk and retires with the view (an in-memory array remains the fallback when no temporary file can be created, and the scan statistics say so). The scan skips values structurally window by window: a record that straddles a window, a nested value or an oversized string is walked with at most about two read chunks of text held, while structure and termination are still validated. A consumer that needs such a record still decodes it whole; that record-sized decode is the remaining per-value maximum, reported through the scan statistics and the compiler's diagnostic line rather than enforced by refusing valid work. Refs #255 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
… canonical finalization Review of the first audit stack found four places where a window- or recipient-scaled structure could still form in the coordinator: The checkpoint index fell back to an in-memory array exactly when the scratch file could not be created. The fallback is removed; scratch pressure (index, record spool, helper) raises ArtifactResourcePressure, a plain Exception that is neither a decode error nor a corruption classification, so publication fails retry-safe instead of degrading. The artifact view kept balances, payout accounts, entitlements, settlement recipients and fanout manifests eager on the argument that recipient cardinality bounds them; it does not, since recipients can number as many as shares. Every such member is now a lazy on-disk sequence, the compact body's part index and header members are parsed lazily as well, and the share-part index is spooled to disk as it is produced and its digest hashed incrementally, so a small configured segment size cannot turn the index into a window-scaled list. A record above the in-process decode limit is now normalized by an isolated helper process that streams the record in and its compact encodings (original order, and sorted keys for equality) out to a scratch file; the coordinator keeps only the small members and never calls json.loads on the record. Consumers compare and encode such records through their streamed encodings. No valid input cap on share identifiers exists on the coordinator side (the Stratum username is read without a length limit), so isolation rather than a byte bound is the honest treatment. Accepted-block persistence and the CTV recovery statement build their one fenced literal from bounded chunks: lazy accounts, leaf arrays and fanout manifests stream from the view, the inline lane splices the canonical artifact verbatim once, the dollar-quote tag is checked by streaming, and the manifest-set text and per-manifest artifacts are derived on demand. The payout preview seam accepts a mapping with a lazy accounts sequence and walks it row by row. The one-shot builder input splices a daemon mirror's or page-backed window's pre-encoded canonical items instead of parsing records (never touching the parsed cache) and streams balances and leaves in batches. The flat-record skip regex is possessive so a window cut inside a long string fails without a backtracking stack proportional to the window. Refs #255 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…play (#255) Replace the whole-jsonb block-candidate intent with a bounded codec and chunked immutable storage: - candidate_codec.py: streaming encoder whose json.dumps calls cover at most 256 records / ~256 KiB, fixed 256 KiB chunks with per-chunk digests, a scalar manifest with per-field spans and page rows (index kept on disk on replay), jsonb-compatibility rejection (NaN/Infinity, U+0000, unpaired surrogates) at preparation, and a PreparedCandidateIntent mapping whose shares_json is the job's immutable sequence rather than a list copy. The body bytes are the historical v1 identity JSON, so candidate_sha256 is unchanged. - candidate_store.py: staging/seal/index/page/chunk statements, bounded hydration to a spool + index pair, the isolated legacy (v1 jsonb) helper process, the bounded header page with explicit exhaustion, and the split janitor (fenced orphan retirement, lease-free chunk reaping). - 002_candidate_bodies.sql: additive manifest/chunk/span/page tables, DB triggers enforcing sealed-body immutability, the dual-format outbox CHECK that refuses a pre-#255 writer's terminal writes, the bounded header SQL projection and a schema capability row. - share_ledger.py: both durable write routes stage outside the writer gate and publish under the fenced statement with a compare-and-swap on the observed outbox version; the exact content comparator reads the stored bytes page by page with a jsonb-equivalence fallback; metadata-first header pages; bounded hydration; janitor; schema-capability refusal; storage version 1 retained as the compatibility/rollback mode. - block_candidates.py: intent preparation without copies, header-page enumeration honouring the configured replay page size, bounded descriptor window with per-hash obligations, dequeue-time hydration, janitor step. - share_writer/share_submission/coordinator/config/compose wiring and the fake-Postgres harness model for every new statement.
- recover_pending_blocks: read the outbox row's storage version and body reference; a version-2 row is hydrated through the ledger's bounded chunk reader (spool + on-disk index) instead of being misclassified as a missing payload; an unsealed body or an unknown version fails closed. - recovery tests: cover the version-2 decode route and its refusals; the native fixture uses a private search_path only (001's DROP FUNCTION must not touch the shared public schema) and applies 002 after 001. - coordinator: pass lease_retry_sleep through the split ledger constructor; the boot-time schema capability check reports a transport failure instead of swallowing it. - candidate codec: a hydrated intent whose large array fields are spool adapters re-stages verbatim; new tests/test_prism_candidate_codec.py pins oracle byte identity, jsonb-compatibility rejection, bounded json.dumps calls and chunk sizes, daemon/page-backed verbatim copies, spool round trips, hint-page correction, and manifest validation.
A database without qbit_share_ledger and without any 002 object was classified as fresh on that evidence alone, and the post-001 comparison was skipped for it. A selective restore or a hand-installed piece of the schema, qbit_pool_blocks on its own for instance, therefore passed: 001's CREATE ... IF NOT EXISTS kept whatever those objects held, the migration recorded success, and the accounting code ran over a schema nobody had checked. The release definitions are now taken once, before any DDL touches the source: the frozen release SQL (001, plus 002 for a #258 source) is applied to a scratch schema under a savepoint and rolled back, and that one fingerprint serves both checks. A database without qbit_share_ledger is fresh only if it has no table, sequence, index, trigger or function the release 001 creates. Otherwise it is the new source state "partial 001", refused before any DDL and naming the objects present, capped as the drift report is: refusing to migrate a partial 001 source before any DDL: the database has no qbit_share_ledger but holds 4 object(s) that the 2.x.x release's 001_share_ledger.sql creates (table qbit_pool_blocks; index ...), so it is neither an empty database nor a 2.x.x ledger, and 001's IF NOT EXISTS would keep those objects whatever they hold. Nothing was changed. Restore the full pre-migration backup, or migrate into an empty database Objects the release does not create, an operator's own table, do not disqualify a fresh database and are logged as extras. The post-001 comparison now runs for every source state, fresh included, where it passes trivially: 001 has just created everything. SOURCE_STATES gains the partial 001 row after fresh. The rows are cited by name through constants and looked up by name, never by position, and a unit test checks every cited name is exactly one row, so reordering the table cannot silently change a refusal again. The pinned-data test, the 006 comment, the guide's table and the development-line note carry the new row. Tests (Postgres): a leftover 001 table, sequence or function alone, each created from the frozen release definition, is refused as partial 001 naming it, with no native table, no scratch schema and the leftover untouched; an empty database with only an operator's table still migrates as fresh and keeps the table; a truly empty database migrates as fresh. The real 0.1.2 -> 1.x -> 2.x history replays, with and without 002, still migrate. Both new gated tests are in the manifest. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019mWgeEnsyHLZSiGaAj8bZi
…ild migrated A database an earlier 3.x.x build brought to native schema 3, 4 or 5 went straight to 004, 005 and 006 without the drain check, and that build's v1-only predicate never counted a v2 row (`candidate ?& ...` is NULL for a NULL body). A pending v2 candidate could therefore be carried into version 6 and parked by the claim lane instead of refusing the cutover, leaving a possibly valid found block unsubmitted. `migrate_schema` now runs the column-aware inventory and `refuse_undrained_outbox` on a recorded version 3, 4 or 5 before 004, 005 and 006 run, so a refusal on that path is before any DDL as well. Native pending rows carry the native payout_revision, bundle and block_hash fields and are not counted; only a v2 body, a body_id, a storage_version other than 1, or a v1 body without those fields is refused. The refusal has its own wording: it names the native schema version, names the rows the same way as the 2.x.x refusal, and gives the remedy the guide backs, restoring the pre-migration 2.x.x backup and draining there with the pinned image. The 2.x.x release is not supported against a native schema (its revert script refuses one), so the message says not to point it at the database. Postgres tests build the earlier build's schema 5 faithfully: the frozen 001 (and 002), the current migration, then 006 undone, deleting the version 6 row and dropping qbit_prism_migration_source, and on a pre-#258 source also the storage_version column and the capability table 006 created. A pending v2 row on the #258 simulation is refused naming the row, with max(version) still 5 and no 006 object; a native pending candidate on either simulation migrates to 6 and is still claimable; an undrained 2.x.x v1 row on the pre-#258 simulation exercises the v1-only form of the predicate. The guide's drain text and the 006 comment describe the check; the gated-test manifest and its documented count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP
The release-schema fingerprint recorded a table by name and compared its columns, constraints and indexes, so a release table an operator had changed to UNLOGGED compared equal to the logged table the scratch apply creates, and the migration accepted a ledger or outbox whose rows PostgreSQL truncates after a crash. The fingerprint now records pg_class.relpersistence for every table and every sequence (PostgreSQL 15 and later have unlogged sequences, and a sequence owned by an unlogged table is unlogged with it). A mismatch is drift, named the way the other differences are: `table qbit_share_ledger differs: expected logged, found UNLOGGED`, and for a sequence the persistence joins its other properties. Extra objects are unaffected. A Postgres test makes qbit_payout_carry_forward UNLOGGED on a pre-#258 source: it holds the carried balances and has no foreign key in either direction, so SET UNLOGGED is accepted as it is, and the sequence behind its bigserial column follows the table. The migration is refused naming the table and its sequence, rolls back with the relations still unlogged and no native table, and accepts the same source once it is logged again. (qbit_audit_publication_sequence_seq is not used for this: 001's own guard already refuses that sequence when it is not logged.) A unit test covers the comparison for tables, sequences and a temporary table. Replays of the real 0.1.2 -> 1.x -> 2.x schema history, with and without 002, still migrate: no revision creates an unlogged relation. The guide's release-schema paragraph, its drifted 001 row and the comment in migration 006 name persistence; the gated-test manifest and its count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP
…schema On a database an earlier 3.x.x build migrated to native schema 3, 4 or 5, migrate_schema ran the drain check and then applied 004, 005 and 006 without reading the capability rows, so a database a newer release wrote (candidate_storage_version = 3, or a capability this binary does not know) was altered and recorded at 6, and only Ledger::connect refused it, after the commit. Every native path now takes the inventory first and refuses those rows before any DDL, on a database already at 6 too, before 009; the 006 record reuses the same rows instead of reading them again, and the recorded versions are read in order so the refusal names them deterministically. A pre-006 test on a #258 source covers both refusals and the migration once the row is gone; the migration guide and the 006 comment describe the order. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ect or column Codex P1 on #321: a source that already contains an object a native migration creates (a qbit_prism_cluster(singleton boolean PRIMARY KEY), for instance) passed the fresh and release checks as a harmless extra. 002's CREATE TABLE IF NOT EXISTS then kept it as it was, the migration recorded its versions, and only after commit did writable() fail on the missing fatal_error column, with every later migrate skipping the recorded version. A column a native migration adds with ADD COLUMN IF NOT EXISTS (002's claim columns on the outbox and the fanout artifacts, 003's canonical_audit_bytes and inactive_since, 006's storage_version on a pre-#258 outbox) is the same bug: a source release table that already has a column of that name keeps it whatever its type or default. The scratch apply release_fingerprint runs now continues, after the release SQL, with the native migrations in the order migrate_schema applies them (NATIVE_MIGRATIONS, pinned to REQUIRED_SCHEMA_VERSIONS by a unit test) and fingerprints the scratch schema again. The second reading minus the first is the reserved set (ReservedObjects): every table, sequence, index, trigger and function a native migration creates and the release does not, and, per release table, every column the native chain adds to it. qbit_prism_schema_migrations, the migrator's own, is never in it, and an object or column in both readings (the capability table on a #258 source, the outbox's storage_version there, which the release 002 added; on a pre-#258 source 006 adds it, so it is reserved) stays governed by the release checks. Reserved columns are kept in their own field: objects_present also serves the partial-001 check, where a present table already refuses and listing its columns would be noise, so only require_no_native_collision looks at them. On the 2.x.x path, before any DDL, the source is fingerprinted once, require_fresh_source (now synchronous, on that reading) runs on a fresh source, and a source that already has a reserved object or column is refused as the new "native collision" state, naming each (capped by named_objects; a column as column <table>.<column>), saying nothing was changed, and telling the operator to restore the backup or check and remove the objects; nothing is dropped and no DROP is suggested. release_objects_present is renamed objects_present. The migrator applies each native migration from NATIVE_MIGRATIONS, so the scratch apply and the real one cannot drift apart. SOURCE_STATES, its pinned-table test, the comment in 006 and the guide's table carry the new row; the guide shows the refusal and names the column case. Tests, against PostgreSQL 16: an empty database with a stray qbit_prism_cluster is refused naming it, with no migrator table and the stray table unaltered, and migrates as fresh once the table is removed; a pre-#258 and a #258 source with a stray native table, function and sequence are refused naming all three, unchanged, and migrate once they are removed; a pre-#258 and a #258 source with a stray claim_token integer on the outbox are refused naming column qbit_block_candidate_outbox.claim_token, unchanged (the column keeps its type), and migrate once it is dropped, after which 002 adds the text column it wanted. The unit test on the reserved set pins the column derivation, including storage_version reserved on a pre-#258 outbox and not on a #258 one. The api_database fixture, which hand-applies 001 to 003 and then lets connect bring the schema forward, now records versions 2 and 3 the way the migrator does: native objects with no record are the collision this commit refuses. The genuine 0.1.2 -> 1.x -> 2.x history replays (the 12 distinct 001 revisions reachable from the release tags, main, 2.x.x and 3.x.x, applied in order into one database and each on its own, then the frozen v2.0.2 001, with and without 002, then migrate: 26 runs) are all accepted, so no real history contains a native object or column. The new Postgres tests are registered in test/prism-gated-tests.txt, and the "N today" count in docs/prism-integration-test-gate.md, which had fallen behind the manifest at an earlier rebase, is set to the manifest's id count, 114. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The migrator accepted any database that had a share ledger, tested the outbox with a JSONB predicate that a #258 v2 row slips past, never read qbit_prism_schema_capabilities, and skipped the schema version entirely when PRISM_POSTGRES_INIT_SCHEMA=0, the native default. Its "frozen 2.x.x schema" in the upgrade tests was include_str! of the live 001, which #244 already edits. Freeze the 2.x.x release SQL as byte-exact fixtures taken from the release commits (001 from v2.0.2, identical at v2.0.1 and v2.0.0; 002 from v2.0.2), pin their digests, pin the live 001's digest, and compare the live 001 to the release statement for statement, since #244 changed only its comments. Editing either live file fails the test with the instruction the editor needs. Migration 006 pins the accepted source states as data: fresh, pre-#258 (001 only), #258 applied (candidate_storage_version = 2 and every 002 object), partial 002 (refused, naming the missing object) and newer (refused before any DDL). The inventory comes from the catalog, so the drain predicate is built only from outbox columns that exist: the storage_version and body_id clauses on a #258 source, the v1 form on a pre-#258 one, where a fixed predicate errored instead of refusing. The check reads rows, never the capability row, which only proves 002 ran. The refusal names the blocking rows and the 2.x.x drain: the pinned coordinator's submitter, or lab.prism.recover_pending_blocks from the 2.x.x image. Every start now reads qbit_prism_schema_migrations and the capability rows, with or without initialize, and refuses a schema other than version 6 or a capability the binary does not understand, naming the required version. A successful migration records the accepted source state, its 2.x.x release and commit, the declared capability value and the prior schema version in qbit_prism_migration_source; migrate prints it, every start logs it, and a repeated migrate never rewrites it. 006 also declares candidate_storage_version = 1 on sources that had no capability row and adds the outbox storage_version column so one claim statement serves every source; the chunk tables are not carried. The API database test hand-applies migrations up to 003 and then connected without initialize, which the gate now refuses; it initializes. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9
The claim lane returned the outbox row's candidate column alone. A #258 v2 row returns NULL with the claim token set, no CandidateClaim can be built, the submit loop logs "candidate polling failed", and the row re-enters the due lane at every lease expiry, forever. Return storage_version and an Option<Value> candidate. A version 1 row with a body is decoded as before. Any other row, a v2 body this server does not import or a version it does not know, is parked inside the claim transaction: the claim is released, last_error says why, and next_attempt_at becomes infinity, so no lease expiry offers it again and ordinary v1 work keeps flowing. The row stays pending with its body untouched; resetting next_attempt_at re-offers it, which is how an operator hands it back after draining it with the 2.x.x image. The edit is deliberately small, since #265 reshapes candidate storage. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9
The migration guide names the minimum supported 2.x.x release (v2.0.1, whose offline recovery command is part of the drain; v2.0.0 has the same schema), the newest (v2.0.2), #258's rollback floor, the source-state table the migrator pins, the drain requirement for v1 and v2 rows with the 2.x.x commands, what qbit_prism_migration_source records, the startup gate, and how a parked row is found and re-offered. The server README points at it. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9
The note listed how 002_candidate_bodies.sql is handled as frozen by a pending issue. It is now carried byte-identical to v2.0.2 and digest-pinned, never applied, and a #258 source is accepted after the drain check while a partial or newer source is refused before any DDL. The matching "not done yet" bullet is gone. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9
…transactionally A database with no 002 objects was accepted as the pre-#258 source on the strength of qbit_share_ledger existing. 001 is idempotent, but its IF NOT EXISTS leaves an existing table, column, index or named constraint as it is, so an older, partially applied or locally modified schema passed the pin, was recorded as v2.0.1, and its incompatible definitions survived a successful migration. The migrator now applies 001 to the source as before and then, before 002_multi_instance.sql or any later native DDL touches those tables, checks that what 001 left alone is the release definition. The expected definitions are not a stored fingerprint: under a savepoint in the migration transaction it creates a scratch schema, applies the same 001 there (plus 002_candidate_bodies.sql for a #258 source), reads every table, column, constraint, index, trigger and function that produced, and rolls the savepoint back, so the comparison is exact for the running PostgreSQL version and nothing from the scratch apply survives. Each object then needs an equivalent in the schema the migrator runs in: column type, NOT NULL, default, identity, generated status and collation; constraints per table by definition; index definitions and validity; trigger definitions and enabled state; function arguments, result, language, body, volatility and settings. Schema qualification, column order, comments, auto-generated constraint names and the NOT VALID mark 001 itself leaves on an upgraded table are ignored; extra objects are kept and logged; a missing or different one fails the migration, which rolls back whole, naming each object and what differs. A migrate role without CREATE on the database is refused with the grant it needs. The source-state table gains the "drifted 001" row in SOURCE_STATES, migration 006's comment and the migration guide; the migration record is unchanged. Tests: a pre-#258 source with a dropped foreign key, a dropped NOT NULL, a changed column type and a same-named index with a different definition is refused naming all four and left untouched; a #258 source with a replaced 002 function body and a disabled 002 trigger is refused; an extra table, column and index, a 001 column moved to a different physical position with its data, and a NOT VALID credit-policy CHECK still migrate; a role without CREATE on the database is told the grant. Replays of the real 0.1.2 -> 1.x -> 2.x history (every 001 revision in order, then the frozen v2.0.2 file, with and without 002) all migrate. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EVxRdWsnzBhrsgiEX2kvKR
The post-001 fingerprint read tables, columns, constraints, indexes, triggers and functions, but never the sequences behind 001's bigserial columns or its explicit qbit_audit_publication_sequence_seq. CREATE TABLE IF NOT EXISTS leaves an existing sequence exactly as it is, so a lowered MAXVALUE or a changed INCREMENT on qbit_share_ledger_share_seq_seq survived the idempotent apply, compared equal to the frozen release, and migrated; the next share inserts would then fail or take unexpected identifiers. The fingerprint now records every sequence of the schema from pg_sequence: data type, start, increment, minimum, maximum, cache and cycle. The value a sequence has reached (last_value, is_called) is the source's data and is not read, so an advanced ledger still migrates and keeps its position. A release sequence that is missing or whose structure differs is drift, named in the refusal the way columns and functions are, for example sequence qbit_share_ledger_share_seq_seq differs: maximum expected 9223372036854775807, found 1000000 and an extra sequence is logged with the other extras. Tests: the pre-#258 drift test also lowers the share sequence's maximum and doubles the payout entry sequence's increment, and the refusal names both and rolls back; the tolerated-differences test advances the share sequence with setval and the first native share takes the next value; a unit test covers the comparison. The real 0.1.2 -> 1.x -> 2.x histories (every 001 revision in order, then the frozen v2.0.2 001, with and without 002) all still migrate, and each leaves the same sequence structure as a fresh apply. The migration guide and the 006 comment list what is compared. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019mWgeEnsyHLZSiGaAj8bZi
A database without qbit_share_ledger and without any 002 object was classified as fresh on that evidence alone, and the post-001 comparison was skipped for it. A selective restore or a hand-installed piece of the schema, qbit_pool_blocks on its own for instance, therefore passed: 001's CREATE ... IF NOT EXISTS kept whatever those objects held, the migration recorded success, and the accounting code ran over a schema nobody had checked. The release definitions are now taken once, before any DDL touches the source: the frozen release SQL (001, plus 002 for a #258 source) is applied to a scratch schema under a savepoint and rolled back, and that one fingerprint serves both checks. A database without qbit_share_ledger is fresh only if it has no table, sequence, index, trigger or function the release 001 creates. Otherwise it is the new source state "partial 001", refused before any DDL and naming the objects present, capped as the drift report is: refusing to migrate a partial 001 source before any DDL: the database has no qbit_share_ledger but holds 4 object(s) that the 2.x.x release's 001_share_ledger.sql creates (table qbit_pool_blocks; index ...), so it is neither an empty database nor a 2.x.x ledger, and 001's IF NOT EXISTS would keep those objects whatever they hold. Nothing was changed. Restore the full pre-migration backup, or migrate into an empty database Objects the release does not create, an operator's own table, do not disqualify a fresh database and are logged as extras. The post-001 comparison now runs for every source state, fresh included, where it passes trivially: 001 has just created everything. SOURCE_STATES gains the partial 001 row after fresh. The rows are cited by name through constants and looked up by name, never by position, and a unit test checks every cited name is exactly one row, so reordering the table cannot silently change a refusal again. The pinned-data test, the 006 comment, the guide's table and the development-line note carry the new row. Tests (Postgres): a leftover 001 table, sequence or function alone, each created from the frozen release definition, is refused as partial 001 naming it, with no native table, no scratch schema and the leftover untouched; an empty database with only an operator's table still migrates as fresh and keeps the table; a truly empty database migrates as fresh. The real 0.1.2 -> 1.x -> 2.x history replays, with and without 002, still migrate. Both new gated tests are in the manifest. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019mWgeEnsyHLZSiGaAj8bZi
…ild migrated A database an earlier 3.x.x build brought to native schema 3, 4 or 5 went straight to 004, 005 and 006 without the drain check, and that build's v1-only predicate never counted a v2 row (`candidate ?& ...` is NULL for a NULL body). A pending v2 candidate could therefore be carried into version 6 and parked by the claim lane instead of refusing the cutover, leaving a possibly valid found block unsubmitted. `migrate_schema` now runs the column-aware inventory and `refuse_undrained_outbox` on a recorded version 3, 4 or 5 before 004, 005 and 006 run, so a refusal on that path is before any DDL as well. Native pending rows carry the native payout_revision, bundle and block_hash fields and are not counted; only a v2 body, a body_id, a storage_version other than 1, or a v1 body without those fields is refused. The refusal has its own wording: it names the native schema version, names the rows the same way as the 2.x.x refusal, and gives the remedy the guide backs, restoring the pre-migration 2.x.x backup and draining there with the pinned image. The 2.x.x release is not supported against a native schema (its revert script refuses one), so the message says not to point it at the database. Postgres tests build the earlier build's schema 5 faithfully: the frozen 001 (and 002), the current migration, then 006 undone, deleting the version 6 row and dropping qbit_prism_migration_source, and on a pre-#258 source also the storage_version column and the capability table 006 created. A pending v2 row on the #258 simulation is refused naming the row, with max(version) still 5 and no 006 object; a native pending candidate on either simulation migrates to 6 and is still claimable; an undrained 2.x.x v1 row on the pre-#258 simulation exercises the v1-only form of the predicate. The guide's drain text and the 006 comment describe the check; the gated-test manifest and its documented count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP
The release-schema fingerprint recorded a table by name and compared its columns, constraints and indexes, so a release table an operator had changed to UNLOGGED compared equal to the logged table the scratch apply creates, and the migration accepted a ledger or outbox whose rows PostgreSQL truncates after a crash. The fingerprint now records pg_class.relpersistence for every table and every sequence (PostgreSQL 15 and later have unlogged sequences, and a sequence owned by an unlogged table is unlogged with it). A mismatch is drift, named the way the other differences are: `table qbit_share_ledger differs: expected logged, found UNLOGGED`, and for a sequence the persistence joins its other properties. Extra objects are unaffected. A Postgres test makes qbit_payout_carry_forward UNLOGGED on a pre-#258 source: it holds the carried balances and has no foreign key in either direction, so SET UNLOGGED is accepted as it is, and the sequence behind its bigserial column follows the table. The migration is refused naming the table and its sequence, rolls back with the relations still unlogged and no native table, and accepts the same source once it is logged again. (qbit_audit_publication_sequence_seq is not used for this: 001's own guard already refuses that sequence when it is not logged.) A unit test covers the comparison for tables, sequences and a temporary table. Replays of the real 0.1.2 -> 1.x -> 2.x schema history, with and without 002, still migrate: no revision creates an unlogged relation. The guide's release-schema paragraph, its drifted 001 row and the comment in migration 006 name persistence; the gated-test manifest and its count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP
…schema On a database an earlier 3.x.x build migrated to native schema 3, 4 or 5, migrate_schema ran the drain check and then applied 004, 005 and 006 without reading the capability rows, so a database a newer release wrote (candidate_storage_version = 3, or a capability this binary does not know) was altered and recorded at 6, and only Ledger::connect refused it, after the commit. Every native path now takes the inventory first and refuses those rows before any DDL, on a database already at 6 too, before 009; the 006 record reuses the same rows instead of reading them again, and the recorded versions are read in order so the refusal names them deterministically. A pre-006 test on a #258 source covers both refusals and the migration once the row is gone; the migration guide and the 006 comment describe the order. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ect or column Codex P1 on #321: a source that already contains an object a native migration creates (a qbit_prism_cluster(singleton boolean PRIMARY KEY), for instance) passed the fresh and release checks as a harmless extra. 002's CREATE TABLE IF NOT EXISTS then kept it as it was, the migration recorded its versions, and only after commit did writable() fail on the missing fatal_error column, with every later migrate skipping the recorded version. A column a native migration adds with ADD COLUMN IF NOT EXISTS (002's claim columns on the outbox and the fanout artifacts, 003's canonical_audit_bytes and inactive_since, 006's storage_version on a pre-#258 outbox) is the same bug: a source release table that already has a column of that name keeps it whatever its type or default. The scratch apply release_fingerprint runs now continues, after the release SQL, with the native migrations in the order migrate_schema applies them (NATIVE_MIGRATIONS, pinned to REQUIRED_SCHEMA_VERSIONS by a unit test) and fingerprints the scratch schema again. The second reading minus the first is the reserved set (ReservedObjects): every table, sequence, index, trigger and function a native migration creates and the release does not, and, per release table, every column the native chain adds to it. qbit_prism_schema_migrations, the migrator's own, is never in it, and an object or column in both readings (the capability table on a #258 source, the outbox's storage_version there, which the release 002 added; on a pre-#258 source 006 adds it, so it is reserved) stays governed by the release checks. Reserved columns are kept in their own field: objects_present also serves the partial-001 check, where a present table already refuses and listing its columns would be noise, so only require_no_native_collision looks at them. On the 2.x.x path, before any DDL, the source is fingerprinted once, require_fresh_source (now synchronous, on that reading) runs on a fresh source, and a source that already has a reserved object or column is refused as the new "native collision" state, naming each (capped by named_objects; a column as column <table>.<column>), saying nothing was changed, and telling the operator to restore the backup or check and remove the objects; nothing is dropped and no DROP is suggested. release_objects_present is renamed objects_present. The migrator applies each native migration from NATIVE_MIGRATIONS, so the scratch apply and the real one cannot drift apart. SOURCE_STATES, its pinned-table test, the comment in 006 and the guide's table carry the new row; the guide shows the refusal and names the column case. Tests, against PostgreSQL 16: an empty database with a stray qbit_prism_cluster is refused naming it, with no migrator table and the stray table unaltered, and migrates as fresh once the table is removed; a pre-#258 and a #258 source with a stray native table, function and sequence are refused naming all three, unchanged, and migrate once they are removed; a pre-#258 and a #258 source with a stray claim_token integer on the outbox are refused naming column qbit_block_candidate_outbox.claim_token, unchanged (the column keeps its type), and migrate once it is dropped, after which 002 adds the text column it wanted. The unit test on the reserved set pins the column derivation, including storage_version reserved on a pre-#258 outbox and not on a #258 one. The api_database fixture, which hand-applies 001 to 003 and then lets connect bring the schema forward, now records versions 2 and 3 the way the migrator does: native objects with no record are the collision this commit refuses. The genuine 0.1.2 -> 1.x -> 2.x history replays (the 12 distinct 001 revisions reachable from the release tags, main, 2.x.x and 3.x.x, applied in order into one database and each on its own, then the frozen v2.0.2 001, with and without 002, then migrate: 26 runs) are all accepted, so no real history contains a native object or column. The new Postgres tests are registered in test/prism-gated-tests.txt, and the "N today" count in docs/prism-integration-test-gate.md, which had fallen behind the manifest at an earlier rebase, is set to the manifest's id count, 114. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The release-schema check classified a user trigger the release does not create on a release table as a tolerated extra, so require_release_schema logged it and migrated over it. Such a trigger can be valid for the legacy writer and incompatible with the native one: a guard that rejects writer_epoch = 0 lets the 2.x.x writer's leased epochs through and fails every native share insert, which writes epoch 0, and a trigger can just as well rewrite what the migrator and the native writers put in the accounting tables. Report a found user trigger on a release table whose (table, name) the release lacks as drift, naming the trigger, its table and its definition, and whether the release has no trigger on that table or simply does not create this one, so the migration refuses transactionally and the database is unchanged. Triggers on tables the release does not create stay the operator's own; the expected-trigger definition and enabled-state comparison and the enforcement-trigger check of release constraints are unchanged. Regression: a comparator unit test for both reasons, a missing release trigger and an operator table's trigger; and a two_x PostgreSQL test on the frozen pre-#258 and #258 sources that shows the guard accepting a legacy epoch and refusing epoch 0, the refusal naming the trigger and rolling back with the trigger, the legacy rows and no native table or version in place, then the same source migrating once the operator drops the guard, with the operator table's trigger kept and firing and the native writers inserting their epoch-0 shares. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01N2if7arQVKaZ1yMupJiprr
…ns, gate startup (#321) * 3.x.x: pin the migration source schema and gate startup on it The migrator accepted any database that had a share ledger, tested the outbox with a JSONB predicate that a #258 v2 row slips past, never read qbit_prism_schema_capabilities, and skipped the schema version entirely when PRISM_POSTGRES_INIT_SCHEMA=0, the native default. Its "frozen 2.x.x schema" in the upgrade tests was include_str! of the live 001, which #244 already edits. Freeze the 2.x.x release SQL as byte-exact fixtures taken from the release commits (001 from v2.0.2, identical at v2.0.1 and v2.0.0; 002 from v2.0.2), pin their digests, pin the live 001's digest, and compare the live 001 to the release statement for statement, since #244 changed only its comments. Editing either live file fails the test with the instruction the editor needs. Migration 006 pins the accepted source states as data: fresh, pre-#258 (001 only), #258 applied (candidate_storage_version = 2 and every 002 object), partial 002 (refused, naming the missing object) and newer (refused before any DDL). The inventory comes from the catalog, so the drain predicate is built only from outbox columns that exist: the storage_version and body_id clauses on a #258 source, the v1 form on a pre-#258 one, where a fixed predicate errored instead of refusing. The check reads rows, never the capability row, which only proves 002 ran. The refusal names the blocking rows and the 2.x.x drain: the pinned coordinator's submitter, or lab.prism.recover_pending_blocks from the 2.x.x image. Every start now reads qbit_prism_schema_migrations and the capability rows, with or without initialize, and refuses a schema other than version 6 or a capability the binary does not understand, naming the required version. A successful migration records the accepted source state, its 2.x.x release and commit, the declared capability value and the prior schema version in qbit_prism_migration_source; migrate prints it, every start logs it, and a repeated migrate never rewrites it. 006 also declares candidate_storage_version = 1 on sources that had no capability row and adds the outbox storage_version column so one claim statement serves every source; the chunk tables are not carried. The API database test hand-applies migrations up to 003 and then connected without initialize, which the gate now refuses; it initializes. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9 * 3.x.x: park candidates the claim lane cannot decode The claim lane returned the outbox row's candidate column alone. A #258 v2 row returns NULL with the claim token set, no CandidateClaim can be built, the submit loop logs "candidate polling failed", and the row re-enters the due lane at every lease expiry, forever. Return storage_version and an Option<Value> candidate. A version 1 row with a body is decoded as before. Any other row, a v2 body this server does not import or a version it does not know, is parked inside the claim transaction: the claim is released, last_error says why, and next_attempt_at becomes infinity, so no lease expiry offers it again and ordinary v1 work keeps flowing. The row stays pending with its body untouched; resetting next_attempt_at re-offers it, which is how an operator hands it back after draining it with the 2.x.x image. The edit is deliberately small, since #265 reshapes candidate storage. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9 * Document the supported 2.x.x source schemas and the drain requirement The migration guide names the minimum supported 2.x.x release (v2.0.1, whose offline recovery command is part of the drain; v2.0.0 has the same schema), the newest (v2.0.2), #258's rollback floor, the source-state table the migrator pins, the drain requirement for v1 and v2 rows with the 2.x.x commands, what qbit_prism_migration_source records, the startup gate, and how a parked row is found and re-offered. The server README points at it. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9 * 3.x.x: accept a newer schema at start and let capabilities fence formats The startup gate refused any schema version other than the one this binary migrates to. That silently withdrew the rollout the guide promises, where compatible Rust releases drain and replace one frontend at a time, because a release that adds a migration would have kept every frontend on the previous release from starting once its migrate ran. Refuse only a schema below the required version, as the issue asks. A newer schema is accepted with a warning that names both versions: native migrations are additive, and a release whose format an older binary must not touch declares a capability, which require_known_capabilities still refuses exactly as before. The guide's rollout paragraph is restored with the order that makes it hold: the new release's migrate runs first, frontends on the previous release keep starting while its migrations are additive and it declares no capability they do not understand, and a release that declares a new capability needs every frontend stopped first. The startup-gate test now asserts that a start on the next schema version succeeds and rewrites nothing. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9 * Record the migrator and schema freeze in the 3.x.x development-line note The note listed how 002_candidate_bodies.sql is handled as frozen by a pending issue. It is now carried byte-identical to v2.0.2 and digest-pinned, never applied, and a #258 source is accepted after the drain check while a partial or newer source is refused before any DDL. The matching "not done yet" bullet is gone. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01AauTYgQEqxzDE13xLjYTR9 * 3.x.x: verify the frozen 001 schema after it has run, refusing drift transactionally A database with no 002 objects was accepted as the pre-#258 source on the strength of qbit_share_ledger existing. 001 is idempotent, but its IF NOT EXISTS leaves an existing table, column, index or named constraint as it is, so an older, partially applied or locally modified schema passed the pin, was recorded as v2.0.1, and its incompatible definitions survived a successful migration. The migrator now applies 001 to the source as before and then, before 002_multi_instance.sql or any later native DDL touches those tables, checks that what 001 left alone is the release definition. The expected definitions are not a stored fingerprint: under a savepoint in the migration transaction it creates a scratch schema, applies the same 001 there (plus 002_candidate_bodies.sql for a #258 source), reads every table, column, constraint, index, trigger and function that produced, and rolls the savepoint back, so the comparison is exact for the running PostgreSQL version and nothing from the scratch apply survives. Each object then needs an equivalent in the schema the migrator runs in: column type, NOT NULL, default, identity, generated status and collation; constraints per table by definition; index definitions and validity; trigger definitions and enabled state; function arguments, result, language, body, volatility and settings. Schema qualification, column order, comments, auto-generated constraint names and the NOT VALID mark 001 itself leaves on an upgraded table are ignored; extra objects are kept and logged; a missing or different one fails the migration, which rolls back whole, naming each object and what differs. A migrate role without CREATE on the database is refused with the grant it needs. The source-state table gains the "drifted 001" row in SOURCE_STATES, migration 006's comment and the migration guide; the migration record is unchanged. Tests: a pre-#258 source with a dropped foreign key, a dropped NOT NULL, a changed column type and a same-named index with a different definition is refused naming all four and left untouched; a #258 source with a replaced 002 function body and a disabled 002 trigger is refused; an extra table, column and index, a 001 column moved to a different physical position with its data, and a NOT VALID credit-policy CHECK still migrate; a role without CREATE on the database is told the grant. Replays of the real 0.1.2 -> 1.x -> 2.x history (every 001 revision in order, then the frozen v2.0.2 file, with and without 002) all migrate. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EVxRdWsnzBhrsgiEX2kvKR * 3.x.x: register the source-schema gated tests in the gate manifest The branch was rebased onto #322, which fails the prism-native-postgres job for any gated test that executes without being listed in test/prism-gated-tests.txt. None of the ten Postgres tests this PR adds in tests/support/ledger_2x.rs were listed, so the job would have failed on its manifest check. List them, sorted, and update the count the gate guide quotes. The other #322 checks (formatting, clippy with -D warnings, the gate env-read lint, the toolchain pin, version skew) already pass on this branch and need no change. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019mWgeEnsyHLZSiGaAj8bZi * 3.x.x: compare release sequences in the source-schema check The post-001 fingerprint read tables, columns, constraints, indexes, triggers and functions, but never the sequences behind 001's bigserial columns or its explicit qbit_audit_publication_sequence_seq. CREATE TABLE IF NOT EXISTS leaves an existing sequence exactly as it is, so a lowered MAXVALUE or a changed INCREMENT on qbit_share_ledger_share_seq_seq survived the idempotent apply, compared equal to the frozen release, and migrated; the next share inserts would then fail or take unexpected identifiers. The fingerprint now records every sequence of the schema from pg_sequence: data type, start, increment, minimum, maximum, cache and cycle. The value a sequence has reached (last_value, is_called) is the source's data and is not read, so an advanced ledger still migrates and keeps its position. A release sequence that is missing or whose structure differs is drift, named in the refusal the way columns and functions are, for example sequence qbit_share_ledger_share_seq_seq differs: maximum expected 9223372036854775807, found 1000000 and an extra sequence is logged with the other extras. Tests: the pre-#258 drift test also lowers the share sequence's maximum and doubles the payout entry sequence's increment, and the refusal names both and rolls back; the tolerated-differences test advances the share sequence with setval and the first native share takes the next value; a unit test covers the comparison. The real 0.1.2 -> 1.x -> 2.x histories (every 001 revision in order, then the frozen v2.0.2 001, with and without 002) all still migrate, and each leaves the same sequence structure as a fresh apply. The migration guide and the 006 comment list what is compared. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019mWgeEnsyHLZSiGaAj8bZi * 3.x.x: treat a database as fresh only when no release object exists A database without qbit_share_ledger and without any 002 object was classified as fresh on that evidence alone, and the post-001 comparison was skipped for it. A selective restore or a hand-installed piece of the schema, qbit_pool_blocks on its own for instance, therefore passed: 001's CREATE ... IF NOT EXISTS kept whatever those objects held, the migration recorded success, and the accounting code ran over a schema nobody had checked. The release definitions are now taken once, before any DDL touches the source: the frozen release SQL (001, plus 002 for a #258 source) is applied to a scratch schema under a savepoint and rolled back, and that one fingerprint serves both checks. A database without qbit_share_ledger is fresh only if it has no table, sequence, index, trigger or function the release 001 creates. Otherwise it is the new source state "partial 001", refused before any DDL and naming the objects present, capped as the drift report is: refusing to migrate a partial 001 source before any DDL: the database has no qbit_share_ledger but holds 4 object(s) that the 2.x.x release's 001_share_ledger.sql creates (table qbit_pool_blocks; index ...), so it is neither an empty database nor a 2.x.x ledger, and 001's IF NOT EXISTS would keep those objects whatever they hold. Nothing was changed. Restore the full pre-migration backup, or migrate into an empty database Objects the release does not create, an operator's own table, do not disqualify a fresh database and are logged as extras. The post-001 comparison now runs for every source state, fresh included, where it passes trivially: 001 has just created everything. SOURCE_STATES gains the partial 001 row after fresh. The rows are cited by name through constants and looked up by name, never by position, and a unit test checks every cited name is exactly one row, so reordering the table cannot silently change a refusal again. The pinned-data test, the 006 comment, the guide's table and the development-line note carry the new row. Tests (Postgres): a leftover 001 table, sequence or function alone, each created from the frozen release definition, is refused as partial 001 naming it, with no native table, no scratch schema and the leftover untouched; an empty database with only an operator's table still migrates as fresh and keeps the table; a truly empty database migrates as fresh. The real 0.1.2 -> 1.x -> 2.x history replays, with and without 002, still migrate. Both new gated tests are in the manifest. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019mWgeEnsyHLZSiGaAj8bZi * 3.x.x: recheck the outbox before 006 on a native schema an earlier build migrated A database an earlier 3.x.x build brought to native schema 3, 4 or 5 went straight to 004, 005 and 006 without the drain check, and that build's v1-only predicate never counted a v2 row (`candidate ?& ...` is NULL for a NULL body). A pending v2 candidate could therefore be carried into version 6 and parked by the claim lane instead of refusing the cutover, leaving a possibly valid found block unsubmitted. `migrate_schema` now runs the column-aware inventory and `refuse_undrained_outbox` on a recorded version 3, 4 or 5 before 004, 005 and 006 run, so a refusal on that path is before any DDL as well. Native pending rows carry the native payout_revision, bundle and block_hash fields and are not counted; only a v2 body, a body_id, a storage_version other than 1, or a v1 body without those fields is refused. The refusal has its own wording: it names the native schema version, names the rows the same way as the 2.x.x refusal, and gives the remedy the guide backs, restoring the pre-migration 2.x.x backup and draining there with the pinned image. The 2.x.x release is not supported against a native schema (its revert script refuses one), so the message says not to point it at the database. Postgres tests build the earlier build's schema 5 faithfully: the frozen 001 (and 002), the current migration, then 006 undone, deleting the version 6 row and dropping qbit_prism_migration_source, and on a pre-#258 source also the storage_version column and the capability table 006 created. A pending v2 row on the #258 simulation is refused naming the row, with max(version) still 5 and no 006 object; a native pending candidate on either simulation migrates to 6 and is still claimable; an undrained 2.x.x v1 row on the pre-#258 simulation exercises the v1-only form of the predicate. The guide's drain text and the 006 comment describe the check; the gated-test manifest and its documented count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP * 3.x.x: compare table and sequence persistence in the source-schema check The release-schema fingerprint recorded a table by name and compared its columns, constraints and indexes, so a release table an operator had changed to UNLOGGED compared equal to the logged table the scratch apply creates, and the migration accepted a ledger or outbox whose rows PostgreSQL truncates after a crash. The fingerprint now records pg_class.relpersistence for every table and every sequence (PostgreSQL 15 and later have unlogged sequences, and a sequence owned by an unlogged table is unlogged with it). A mismatch is drift, named the way the other differences are: `table qbit_share_ledger differs: expected logged, found UNLOGGED`, and for a sequence the persistence joins its other properties. Extra objects are unaffected. A Postgres test makes qbit_payout_carry_forward UNLOGGED on a pre-#258 source: it holds the carried balances and has no foreign key in either direction, so SET UNLOGGED is accepted as it is, and the sequence behind its bigserial column follows the table. The migration is refused naming the table and its sequence, rolls back with the relations still unlogged and no native table, and accepts the same source once it is logged again. (qbit_audit_publication_sequence_seq is not used for this: 001's own guard already refuses that sequence when it is not logged.) A unit test covers the comparison for tables, sequences and a temporary table. Replays of the real 0.1.2 -> 1.x -> 2.x schema history, with and without 002, still migrate: no revision creates an unlogged relation. The guide's release-schema paragraph, its drifted 001 row and the comment in migration 006 name persistence; the gated-test manifest and its count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP * 3.x.x: compare constraint validation, exempting only the release's own NOT VALID check The source-schema check stripped NOT VALID from every constraint definition before comparing, so a foreign key or CHECK an operator had dropped and re-added NOT VALID compared equal to the validated release constraint, and a source whose rows were never checked against it, orphaned outbox rows or invalid accounting rows for instance, still migrated. The blanket strip is replaced by a pinned exemption list, NOT_VALID_EXEMPT: the constraints the frozen release 001 itself adds NOT VALID on an upgraded table and never validates. Today that is qbit_share_ledger_credit_policy_check alone (001 adds it NOT VALID to a qbit_share_ledger upgraded from before the column existed; a fresh apply creates it validated inside CREATE TABLE). An exempt constraint is accepted in either state on either side. Every other constraint is compared by pg_constraint.convalidated as well as by definition: a release constraint that is NOT VALID in the source is drift, `constraint qbit_block_candidate_outbox_share_id_fkey on qbit_block_candidate_outbox is NOT VALID; the release validates it`. The definition without its NOT VALID suffix is still the lookup key, so an unvalidated constraint finds its release counterpart and is named. A test parses the frozen 001 and 002 fixtures for constraints added NOT VALID and not validated later in the same file (plain statements and the format() form alike) and asserts the set equals NOT_VALID_EXEMPT, so the list cannot drift from the release. A Postgres test drops and re-adds the outbox share_id foreign key and a carry-forward CHECK NOT VALID: the migration is refused naming both, rolls back with nothing validated, and accepts the source once they are validated. The existing tolerated- differences case, with the credit-policy check NOT VALID, still migrates. Unit tests cover the comparison and the exemption. Replays of the real 0.1.2 -> 1.x -> 2.x schema history, with and without 002, still migrate: the only constraint a genuine history leaves NOT VALID is the exempt one. The guide's release-schema paragraph, its drifted 001 row and the comment in migration 006 describe the rule; the gated-test manifest and its count are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01QuEYH8xHQRo7C4SnexM3cP * 3.x.x: require every schema migration at start, 009 included and may land after 009, and the rebase moved its 009 step into migrate_schema with the rest of the chain. The startup gate still compared max(version) with 6, which a database at 2, 3, 4, 5 and 9 passes without 006, and its "newer than required" warning would have fired on every start once 009 was in the chain. REQUIRED_SCHEMA_VERSIONS names 2, 3, 4, 5, 6 and 9. A start refuses a database missing any of them, naming the gap, and warns only about migrations this binary does not know. The pre-006 outbox refusal names the applied set instead of a high-water mark; prior_schema_version in the source record stays the highest migration recorded. Tests: a database at 2, 3, 4, 5 and 9 applies 006 on the next migrate and leaves 009 as it found it; a start without PRISM_POSTGRES_INIT_SCHEMA on that database is refused naming 6; the newest-migration case now undoes 009. #319's read-only pre-009 connect test is removed, since the gate refuses that database by design, and the gate manifest follows. Co-Authored-By: Claude Fable 5.1 <[email protected]> * 3.x.x: refuse unknown capabilities before 004 to 006 run on a native schema On a database an earlier 3.x.x build migrated to native schema 3, 4 or 5, migrate_schema ran the drain check and then applied 004, 005 and 006 without reading the capability rows, so a database a newer release wrote (candidate_storage_version = 3, or a capability this binary does not know) was altered and recorded at 6, and only Ledger::connect refused it, after the commit. Every native path now takes the inventory first and refuses those rows before any DDL, on a database already at 6 too, before 009; the 006 record reuses the same rows instead of reading them again, and the recorded versions are read in order so the refusal names them deterministically. A pre-006 test on a #258 source covers both refusals and the migration once the row is gone; the migration guide and the 006 comment describe the order. Co-Authored-By: Claude Fable 5.1 <[email protected]> * 3.x.x: compare row-level security and policies in the source-schema check The release-schema fingerprint read a table's name, persistence and columns only, so a release table with row-level security enabled or forced, or a policy on it, compared equal to the frozen release. For a migrate role that does not bypass row-level security, a policy hiding pending rows (or forced security with no policy) makes the drain check see an empty outbox, so the migration commits with legacy candidates stranded where the native claim lane never sees them. The fingerprint now reads relrowsecurity and relforcerowsecurity from pg_class and every policy from pg_policy (command, permissive or restrictive, roles, USING and WITH CHECK, rendered without schema qualification), both for the scratch release apply and the source, and the comparison refuses a release table whose flags differ or that carries a policy the release does not have, naming the table, the flags found and each policy. Policies on tables the release does not create are not reported. A Postgres test migrates as a non-superuser owner role and shows the row hidden, the refusal, the rollback, and the migration once security is off and the row drained; the docs and the 006 header say what is compared and why. Co-Authored-By: Claude Fable 5.1 <[email protected]> * Quote the pre-006 outbox refusal as the migrator words it since 009 joined the chain The guide's example still read "a native schema 5 database", the wording from before the applied migrations were tracked as a set; the migrator names the recorded set ("a native database at schema migrations 2, 3, 4, 5, 9") since the startup gate stopped comparing a high-water mark. Co-Authored-By: Claude Fable 5.1 <[email protected]> * 3.x.x: refuse a 2.x.x or empty source that already holds a native object or column Codex P1 on #321: a source that already contains an object a native migration creates (a qbit_prism_cluster(singleton boolean PRIMARY KEY), for instance) passed the fresh and release checks as a harmless extra. 002's CREATE TABLE IF NOT EXISTS then kept it as it was, the migration recorded its versions, and only after commit did writable() fail on the missing fatal_error column, with every later migrate skipping the recorded version. A column a native migration adds with ADD COLUMN IF NOT EXISTS (002's claim columns on the outbox and the fanout artifacts, 003's canonical_audit_bytes and inactive_since, 006's storage_version on a pre-#258 outbox) is the same bug: a source release table that already has a column of that name keeps it whatever its type or default. The scratch apply release_fingerprint runs now continues, after the release SQL, with the native migrations in the order migrate_schema applies them (NATIVE_MIGRATIONS, pinned to REQUIRED_SCHEMA_VERSIONS by a unit test) and fingerprints the scratch schema again. The second reading minus the first is the reserved set (ReservedObjects): every table, sequence, index, trigger and function a native migration creates and the release does not, and, per release table, every column the native chain adds to it. qbit_prism_schema_migrations, the migrator's own, is never in it, and an object or column in both readings (the capability table on a #258 source, the outbox's storage_version there, which the release 002 added; on a pre-#258 source 006 adds it, so it is reserved) stays governed by the release checks. Reserved columns are kept in their own field: objects_present also serves the partial-001 check, where a present table already refuses and listing its columns would be noise, so only require_no_native_collision looks at them. On the 2.x.x path, before any DDL, the source is fingerprinted once, require_fresh_source (now synchronous, on that reading) runs on a fresh source, and a source that already has a reserved object or column is refused as the new "native collision" state, naming each (capped by named_objects; a column as column <table>.<column>), saying nothing was changed, and telling the operator to restore the backup or check and remove the objects; nothing is dropped and no DROP is suggested. release_objects_present is renamed objects_present. The migrator applies each native migration from NATIVE_MIGRATIONS, so the scratch apply and the real one cannot drift apart. SOURCE_STATES, its pinned-table test, the comment in 006 and the guide's table carry the new row; the guide shows the refusal and names the column case. Tests, against PostgreSQL 16: an empty database with a stray qbit_prism_cluster is refused naming it, with no migrator table and the stray table unaltered, and migrates as fresh once the table is removed; a pre-#258 and a #258 source with a stray native table, function and sequence are refused naming all three, unchanged, and migrate once they are removed; a pre-#258 and a #258 source with a stray claim_token integer on the outbox are refused naming column qbit_block_candidate_outbox.claim_token, unchanged (the column keeps its type), and migrate once it is dropped, after which 002 adds the text column it wanted. The unit test on the reserved set pins the column derivation, including storage_version reserved on a pre-#258 outbox and not on a #258 one. The api_database fixture, which hand-applies 001 to 003 and then lets connect bring the schema forward, now records versions 2 and 3 the way the migrator does: native objects with no record are the collision this commit refuses. The genuine 0.1.2 -> 1.x -> 2.x history replays (the 12 distinct 001 revisions reachable from the release tags, main, 2.x.x and 3.x.x, applied in order into one database and each on its own, then the frozen v2.0.2 001, with and without 002, then migrate: 26 runs) are all accepted, so no real history contains a native object or column. The new Postgres tests are registered in test/prism-gated-tests.txt, and the "N today" count in docs/prism-integration-test-gate.md, which had fallen behind the manifest at an earlier rebase, is set to the manifest's id count, 114. Co-Authored-By: Claude Fable 5.1 <[email protected]> * 3.x.x: fold migration 008 into the native chain after rebasing on 3.x.x #327 added 008_prepared_window_reference.sql to the runner in connect.rs, which this branch had moved into migrate_schema. Put 008 in NATIVE_MIGRATIONS, so the scratch apply reserves what it creates, and in REQUIRED_SCHEMA_VERSIONS, so the startup gate requires it; apply it after 006 and before 009. 007 is the only reserved number now. The pre-006 fixtures the tests undo from the current chain therefore model the database today's 3.x.x leaves, at 2, 3, 4, 5, 8 and 9, and the messages and docs name that set. * 3.x.x: refuse a native record with 3 and not 2 before any DDL Every native build has recorded 2 and 3 in the one transaction that applied them, so a record with 3 and not 2 was edited or restored selectively. migrate_schema's native path applied the rest of the chain above it and only the startup gate then refused the gap, at every start, and no later migrate could repair it: 002 is not re-run on a database at 3, and recording it unseen would vouch for objects the run never checked. Refuse the record before any DDL, naming the remedy; a start without initialize keeps refusing the gap. * 3.x.x: require the capability declaration once migration 006 is recorded require_known_capabilities accepted a database at 6 whose capability table or candidate_storage_version row was gone, as if absence were the legacy state it was before 006; after a selective restore or a deletion the database could no longer say which release wrote it and the connect gate let it through. 006 created both and nothing native removes them, so require them at connect once require_schema_version has established 6, naming the remedy, and refuse the same database on the migrate path before 008 or 009 run above the missing declaration. * 3.x.x: compare the enforcement triggers of release constraints The trigger reading skipped every internal trigger and the constraint comparison looked at the definition and convalidated only, so a release foreign key whose referential triggers a superuser had disabled (ALTER TABLE ... DISABLE TRIGGER ALL during a bulk load, say) compared equal: no new row was checked against it, 001 never re-enables a trigger it did not create, and the native ledger could go on accumulating orphaned rows. Read the enabled state of each internal trigger that enforces a constraint into its definition, on both tables of a foreign key, and refuse a release constraint whose states differ from the scratch apply, naming them. * 3.x.x: refuse inheritance involving a release table The table reading never looked at pg_inherits, so a child created with INHERITS (qbit_share_ledger) was an extra ordinary table, accepted with a warning, while PostgreSQL includes its rows in every query of the ledger, the unqualified share reads included, without the release constraints ever checking them. Read each table's parents and children into its definition and refuse a release table that has either, naming them; a release table attached as a partition of or inheriting from another table is drift the same way, and inheritance among the operator's own tables stays theirs. * 3.x.x: count a reserved name held by a relation of any kind as a collision The index reading left every index backing a primary, unique or exclusion constraint to the constraint comparison, and the collision check looked up reserved index names in that reading only, so an operator table whose unique constraint was named qbit_prism_candidate_claim_idx owned that name unseen: 002's CREATE INDEX IF NOT EXISTS would skip the outbox index it meant to create, record the migration anyway, and leave candidate polling to scan the outbox. IF NOT EXISTS looks at the name alone, for a view or a composite type as much as for such an index, so read every relation of the kinds no other map models into the fingerprint, reserve the native ones the release lacks, and count a reserved table, sequence or index name held by any of them, naming what holds it. An index backing a constraint of an expected table goes with that table and is not named twice. * 3.x.x: refuse extra user triggers on release tables The release-schema check classified a user trigger the release does not create on a release table as a tolerated extra, so require_release_schema logged it and migrated over it. Such a trigger can be valid for the legacy writer and incompatible with the native one: a guard that rejects writer_epoch = 0 lets the 2.x.x writer's leased epochs through and fails every native share insert, which writes epoch 0, and a trigger can just as well rewrite what the migrator and the native writers put in the accounting tables. Report a found user trigger on a release table whose (table, name) the release lacks as drift, naming the trigger, its table and its definition, and whether the release has no trigger on that table or simply does not create this one, so the migration refuses transactionally and the database is unchanged. Triggers on tables the release does not create stay the operator's own; the expected-trigger definition and enabled-state comparison and the enforcement-trigger check of release constraints are unchanged. Regression: a comparator unit test for both reasons, a missing release trigger and an operator table's trigger; and a two_x PostgreSQL test on the frozen pre-#258 and #258 sources that shows the guard accepting a legacy epoch and refusing epoch 0, the refusal naming the trigger and rolling back with the trigger, the legacy rows and no native table or version in place, then the same source migrating once the operator drops the guard, with the operator table's trigger kept and firing and the native writers inserting their epoch-0 shares. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01N2if7arQVKaZ1yMupJiprr * fix: reject extra constraints on migration source tables * fix: reject unsatisfied extra migration source columns * fix: reject extra indexes that affect native writes * fix: update rustls to address RUSTSEC-2026-0285 * fix: reject executable expressions on extra source columns * fix: fingerprint table rewrite rules before migration * fix: reject incoming foreign keys from extra source tables * fix: validate storage version before native migration 006 * fix: reject domain-typed extra migration columns * fix: reject migration sources resolved outside the current schema * fix: reject all extra indexes on release tables * fix: validate source metadata before later native migrations * fix: reject preexisting source metadata before migration 006 * fix: reject row security on capability metadata * fix: separate legacy source versions from native capabilities * fix: reject outbox row security before native migration drain * fix: validate migration history before trusting version records * fix: require an ordinary table for capability declarations * fix: bind the capability declaration to the current schema The connect-time gate probed qbit_prism_schema_capabilities with an unqualified to_regclass, which follows search_path. When the migrated schema had lost its capability table, the probe could resolve a later schema's table, and its version-1 row cleared a database whose own declaration was gone, while require_migration_history had bound the history to current_schema(). Migrate was already safe through require_source_schema_resolution; connect was not. read_capabilities now looks the visible relation up in the catalog and refuses one outside current_schema(), naming both schemas, before any row is read. Both callers share the path: the connect gate drops its separate probe and the migrate inventory reads through the same function. A new gated test drops the migrated schema's declaration, declares version 1 in a later schema on search_path, and asserts that connect and migrate both refuse it, that the loss is still named as a loss without the later schema, and that the restored declaration is read with the later schema still present. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix: bind migration provenance to the verified schema * fix: reject object collisions in native migration gaps --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
#268 closes with this change, so the links that name it as the future home of the unfinished recover work would become dead ends. Row 84's "not covered" clause and every plan-level case in the per-case table now link #418 instead. Row 84 stays partial, and the #285 and #270 links are untouched. The per-case table also says which revision it enumerates. The file has seventeen cases at 504846c, the `origin/2.x.x` commit this document pins throughout; three of them arrived with #258, so a reader who checks v2.0.1 instead sees fourteen and none of those three. Saying so stops the next reader concluding the extra rows are invented. Co-Authored-By: Claude Opus 5 <[email protected]>
home of the unfinished recover work would become dead ends. Row 84's "not covered" clause and every plan-level case in the per-case table now link #418 instead. Row 84 stays partial, and the #285 and #270 links are untouched. The per-case table also says which revision it enumerates. The file has seventeen cases at 504846c, the `origin/2.x.x` commit this document pins throughout; three of them arrived with #258, so a reader who checks v2.0.1 instead sees fourteen and none of those three. Saying so stops the next reader concluding the extra rows are invented. Co-Authored-By: Claude Opus 5 <[email protected]>
home of the unfinished recover work would become dead ends. Row 84's "not covered" clause and every plan-level case in the per-case table now link #418 instead. Row 84 stays partial, and the #285 and #270 links are untouched. The per-case table also says which revision it enumerates. The file has seventeen cases at 504846c, the `origin/2.x.x` commit this document pins throughout; three of them arrived with #258, so a reader who checks v2.0.1 instead sees fourteen and none of those three. Saying so stops the next reader concluding the extra rows are invented. Co-Authored-By: Claude Opus 5 <[email protected]>
…blocks (#439) * 3.x.x: Add the candidates list and abandon operator commands `qbit-prism-server` had no way to see or finish a block candidate: a native-era row that keeps failing was retried forever, and the only way to inspect or stop it was editing rows by hand. `candidates list` is an inventory. It opens the read-only pool shape `fatal-state show` uses, so "takes no claim" is enforced by PostgreSQL rather than by review, and it keeps working while the cluster is halted. Neither payload column is projected: the height is extracted to a scalar server-side, guarded by a digit pattern so a row an unknown writer left behind reports an unknown height instead of failing the inventory. Rows print in the oldest-due claim lane's own ordering, so the row a server works next comes first and parked rows sort last. An empty inventory is a success, because that is what a cutover runbook waits for. `candidates abandon` applies to `pending` only, which is the one unfinished state from which no `submitblock` can yet have been made. The whole safety property is the statement's `WHERE`: `pending`, no live claim, and no landed block. It is a predicate and never a preceding `SELECT`, because a row can move between a check and a write; the diagnosis that produces the operator's message runs read-only after it, and gates nothing. The column set is the epoch-supersession path's, verbatim, with the operator's reason taking `last_error`'s place, and `next_attempt_at` deliberately untouched so a parked row keeps that evidence. Each refusal has its own exit status, so a runbook can tell a row that was never there from one already abandoned, and both from the two refusals that protect the invariant: a block that may already have been offered, and a block whose accounting has landed. Both commands read PRISM_DATABASE_URL and nothing else. Neither builds a node client, reads a signing key, loads `Config` or starts a listener, so "never calls submitblock" holds structurally. Co-Authored-By: Claude Opus 5 <[email protected]> * 3.x.x: Cover the candidate operator commands in the PostgreSQL gate Six gated tests drive the real binary against a recorder in front of the fake node and assert it made no RPC call at all, `submitblock` included, and registered no instance. The child is given a database URL and a node URL and nothing else, so a command that loaded `Config` or started a listener could not have succeeded. `list` is asserted not to claim three ways: it runs to completion while the cluster is halted, which every write path refuses; every row is byte-identical afterwards, with `claim_token`, `claim_instance_id`, `claim_expires_at`, `attempt_count` and the dispatch sequence compared explicitly; and the statement it issues is described by PostgreSQL, so the assertion that neither payload column is projected reads the result columns rather than the SQL text. `abandon` is asserted to leave an `offer_reserved`, `offered` or `reconciliation` row byte-identical, to refuse a live foreign claim and then succeed once that claim has expired, to refuse an already-terminal row and a pending row whose block has landed, and to refuse while the cluster is halted or a legacy writer lease is live. On the one row it does take, the resulting row is compared field by field with a row the epoch-supersession statement abandoned. Co-Authored-By: Claude Opus 5 <[email protected]> * 3.x.x: Document the candidate commands and the two cutover drains `prism-ledger-ops.md` gains a `Candidate commands` subsection three lines below the state table it explains: the two command lines, a real `list` output block, what each column means, the parked-versus-retrying distinction, the refusal table with its exit codes, and the two fences `abandon` inherits from the ordinary ledger write path — a halted cluster and a live legacy Python writer lease, which is what stops an operator abandon racing the 2.x.x writer during a cutover. `prism-rust-migration.md` gains the native counterpart to the legacy drain, and says plainly that they are not the same drain. The legacy instruction is unchanged: every 2.x.x candidate is still drained with the pinned legacy image before migrating, and the migrator still refuses while any remains. The native commands act on native-era rows only, and running them neither satisfies nor bypasses that check. `prism-deleted-test-map.md` keeps the pending-block-recovery row partial and its open-gap link intact, adds the six new tests where they genuinely cover a case, and fills in the per-case mapping the row promised. The recovery command's plan ordering, fail-closed selection across a plan and apply idempotence stay open; the cooperative-JSON codec cases stay retired. Co-Authored-By: Claude Opus 5 <[email protected]> * 3.x.x: Assert a second candidate abandon cannot overwrite the first The state predicate is the abandon statement's version guard, so two operator abandons completing out of order are safe without any lock on top. Prove it end to end: after the successful abandon, a second one with a different reason exits 4, says the row is already abandoned, and leaves it byte-identical, so the reason the first operator recorded survives. Co-Authored-By: Claude Opus 5 <[email protected]> * 3.x.x: Connect candidates abandon as a one-shot tool `abandon` writes an ordinary ledger row, so it belongs in the same bucket as `import-audits`, `backfill-ctv`, `broadcast-ctv` and `self-check`, not with recovery and migration: `Registration::Tool` refuses a halted cluster at connect, exactly as a frontend would, instead of getting as far as the write guard. The write guard call stays, because it is what refuses a live legacy Python writer lease, which the connection does not cover. `list` keeps the read-only pool. It opens no ledger and writes nothing, `default_transaction_read_only=on` is a stronger guarantee than a tool connection would give, and a tool connection would refuse a halted cluster — which is exactly when an operator needs to inspect candidates. A new gated test gives `abandon` the four properties a one-shot tool owes: a generated instance ID leaves no row on success or on a refusal, a live frontend's row and session-owner token are untouched when the command runs under that frontend's ID, the halt guard holds and the halted run changes nothing, and once the real frontend stops no row is left that the recovery command's instance gate would refuse. Substituting the registering connection for the tool connection fails all five abandon tests. Co-Authored-By: Claude Opus 5 <[email protected]> * 3.x.x: Point the deleted-test map's open recover work at #418 home of the unfinished recover work would become dead ends. Row 84's "not covered" clause and every plan-level case in the per-case table now link #418 instead. Row 84 stays partial, and the #285 and #270 links are untouched. The per-case table also says which revision it enumerates. The file has seventeen cases at 504846c, the `origin/2.x.x` commit this document pins throughout; three of them arrived with #258, so a reader who checks v2.0.1 instead sees fourteen and none of those three. Saying so stops the next reader concluding the extra rows are invented. Co-Authored-By: Claude Opus 5 <[email protected]> * 3.x.x: Name #418 in the deleted-test map's issue-link list The per-case retarget moved every recover link from #268 to #418, but the header still named #268 as one of the issues those links point at. No link points there now, so the sentence described the document's previous state. * 3.x.x: Refuse abandoning unsupported candidate storage versions * 3.x.x: Serialize candidate abandon with in-flight landing * Preserve legacy candidate evidence during operator abandon * Report truncated candidate inventories in text and JSON output * Reserve live regtest ports until each child starts * Use one claim timestamp for abandon refusal diagnosis * 3.x.x: Add the candidates recover operator command Land already-accepted blocks for an explicit allowlist of at most 32 candidates (#418), plan-only by default and never calling submitblock. The plan reads the listed rows on the inventory's read-only pool, loads no payload column and proves each block active on the node; --apply takes a token-fenced claim by hash through the existing claim mechanism, adopts a pending row before anything lands, and drives the coordinator's own post-offer landing and finish under one operator deadline, releasing the claim with the reason on any stop. The refusal taxonomy extends the abandon exit codes (9 not active, 10 selection refused, 11 deadline, 12 landing refused). Co-Authored-By: Claude Fable 5.1 <[email protected]> * 3.x.x: Cover candidates recover in the PostgreSQL gate Five gated tests drive the real binary against a scripted fake node that records every RPC method and has no submitblock arm: plan ordering without a claim or a payload, fail-closed selection for every refusal, a real apply that lands a pending and a reconciliation candidate and verifies them idempotently on rerun, a live foreign claim refused and an unauthenticated row released, and a landing paused inside the database past the deadline. The seeding helpers of the list and abandon tests are shared with the new module. Co-Authored-By: Claude Fable 5.1 <[email protected]> * 3.x.x: Document candidates recover and update the deleted-test map The ledger-ops guide gains the third candidate command beside list and abandon, with the configuration asymmetry, the plan, the apply steps, the deadline, the exit table and a native runbook; the migration guide names it in the two-drains section; and the deleted-test map's pending-block-recovery row drops its #418 clause, staying partial only for #285. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix: adapt recovery to typed chain observations * fix: distinguish recovery RPC failures from missing blocks * fix: release recovery claims after claim-phase timeouts * fix: classify recovery blocks above the active tip as inactive * fix: treat orphaned candidates as terminal during recovery * fix: report orphaned candidates as terminal on abandon * fix: preserve allowlist order for recovery parent refusals * fix: report unconfirmed recovery claim cleanup * fix: exit recovery after cleanup failure without waiting for rebuilds * fix: revalidate completed candidates before skipping recovery --------- Co-authored-by: Alex <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
Summary
Large candidate windows previously crossed whole-document JSON boundaries during validation, persistence, replay and audit finalization. This change streams canonical candidate bytes into immutable 256 KiB chunks, publishes a sealed body reference with share credit in one fenced transaction, and replays bounded metadata pages into owned disk spools. Candidate hashes, timestamp normalization, exact append retry semantics and mining/payout rules remain unchanged.
002_candidate_bodies.sqlmigration, chunk/index integrity checks, atomic publication, bounded orphan cleanup, and compatible reading of legacy JSONB candidates. The offline accepted-pending recovery command understands both storage formats.docs/prism-candidate-storage.md; includes 2.0.2 release notes.Validation
All local checks ran in Docker with the final combined implementation:
Performance and rollout limits
The native pipeline probe exercised 375,000 synthetic shares and 232,787,365 bytes per candidate, with a real writer-session proof actor. Three-candidate runs with GC disabled/enabled passed with maximum observer delays of 28.0/5.9 ms and process high-water RSS of 103/101 MiB. A single-candidate control and 20 repeated ownership generations also passed; no proof errors occurred and spool reservations returned to zero after close. Detailed controls and older aggregate comparisons are in the guide.
These ARM64 codec/storage experiments are separate from the actual mined-block fixture. They do not establish production-equivalent x86_64 performance or prove the instruction responsible for the reported exits. PostgreSQL and exceptional helpers still require capacity proportional to their input within documented resource limits.
Apply both schema migrations before starting this release, whichever storage version it writes; the coordinator and the offline recovery command refuse an unmigrated database. Rollback must retain a reader that understands chunked bodies; set
PRISM_CANDIDATE_STORAGE_VERSION=1to stop new-format writes without dropping the additive schema. Production deployment is not included. Coordinate with #254 and complete its minimum two-hour observation and raw lease-counter/ownership criteria before production acceptance.Refs #255, #254. Production qualification remains open.