Repository navigation
3.x.x: Native candidate recover --apply for already-accepted pending blocks - #439
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f3bba5577
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2f3bba5 to
20ddc7c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20ddc7c1cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`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]>
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]>
`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]>
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]>
`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]>
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]>
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]>
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]>
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]>
20ddc7c to
3b10f52
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b10f526c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6eb19a6c37
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28144eee6c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Closes #418. Stacked on #425 (
candidates list/abandon, the subcommand group,refusal taxonomy and test module this extends): this branch is #425's head plus the
commits below, so the diff collapses to them once #425 merges.
Adds
qbit-prism-server candidates recover --block-hash <hash>... [--apply] [--timeout-seconds N], the third candidate command: the operator path for anative-era candidate whose block the node already accepted and which the claim lane
cannot finish (the row
abandoncorrectly refuses). Plan-only by default;--applylands the listed blocks at the proven chain revision through the coordinator's own
post-offer landing, and never calls
submitblock.What it does
Plan (default). Reads the listed rows on the same read-only one-connection pool
listuses (default_transaction_read_only=on, so a claim is impossible byconstruction), loads no payload column (a
describe()test proves the projection),asks the node
getblockheader/getblockhashfor each hash, and prints the selectionordered by height, parent before child. Fail-closed on every listed hash: missing row,
abandoned,submittedwithout proven accounting, not on the active chain, anunfinished parent that is not listed, a stored height that disagrees with the node,
unsupported storage version, legacy document. Every problem is printed; the first
one's status is the exit status.
--apply. Runs the plan, connects as a one-shot tool (Coordinator::new_tool, noheartbeat, every startup gate), then per block in height order:
mechanism (
Ledger::claim_candidate_for_recovery: the lane's ownRETURNINGcolumns and decode; the statement's
WHEREis the safety property: unfinishedstate, no live claim,
storage_version = 1, the migrator's document-shape test);a parked row is claimable, its schedule untouched;
the candidate's;
previousblockhashequals the parent in the block bytes);pendingrow is adopted intoreconciliationfirst, exactly as the pre-offerprobe adopts an active pending block, so from that commit no frontend can offer it;
land_offered(builder admission, rebuild from the as-issued snapshot,verification,
land_candidate_at_revision) under the ordinary lease heartbeat,with the rebuild deadline set to the operator's budget instead of the lane's 60 s;
finish_candidate_at_revision.Already-complete
submittedblocks are verified (confirmed pool block, audit row,active on the node) and skipped, so rerunning the same allowlist is a resume.
Deadline.
--timeout-seconds(1..3600, default 600, #259's) is onetokio::time::Instantcarried through the plan, the connection, and each claim,rebuild and landing. On expiry the in-flight claim is released with a bounded write
(
FOR NO KEY UPDATE, compatible with the landing transaction'sKEY SHARE), therow keeps its state, evidence and schedule, and the command exits 11. Any other
stop releases the claim the same way and records the reason in
last_error.Exit statuses
Extends #268's table; shared codes keep their meaning.
abandoned, orsubmittedwithout proven accountingCodes 3 and 6 do not occur: every unfinished state is recoverable, and a landed audit
is what an idempotent landing reuses.
Configuration
listandabandonstill takePRISM_DATABASE_URLand nothing else.recoveris theone command that reads the node: the plan needs the database URL and the
QBIT_RPC_*settings;
--applyneeds the frontend's full configuration (it rebuilds and signs theaudit and verifies genesis/chain and the cluster fingerprint). Frontends do not need to
be stopped: the claim is the fence.
docs/prism-ledger-ops.mddocuments the asymmetry.Code
ledger/candidates.rs:RecoveryReader(read-only plan reads;sql()public forthe projection test),
Ledger::claim_candidate_for_recovery,Ledger::release_recovery_claim,RecoveryClaim,RecoveryRow; the abandondiagnosis and the new one share
RefusalFacts; the lane'sRETURNINGlist is ashared constant;
read_only_poolis shared withlist.coordinator.rs:process_candidate_with_leaseis split intowith_candidate_heartbeat(claim, lease, work)+process_candidate_inner(nobehaviour change);
recover_candidatedrives the post-offer phase for a named rowunder the operator's deadline;
RecoveryStopnames the three stops.rpc.rs: JSON-RPC error replies are now a downcastableRpcReplyErrorwith thesame message, so "no such block" can be told from "node unreachable".
tools.rs: theRecoversubcommand, plan/apply, reporting;render_tableandclaim_textare factored out of thelisttable.Tests
Five gated PostgreSQL tests in
tests/support/candidates_recover.rs(
ledger_postgres::candidates_recover, added totest/prism-gated-tests.txt), eachrunning the real binary against a scripted fake node that records every RPC method and
has no
submitblockarm, and asserting no instance row was registered:recover_plan_orders_parent_before_child_without_claiming_or_loading_payloadsrecover_plan_fails_closed_on_missing_terminal_inactive_legacy_and_unlisted_parents--applylands a real pending (adopted first) and a real reconciliation candidate through the real rebuild; second run verifies and skips; unlisted row untouchedrecover_apply_lands_the_listed_blocks_and_verifies_completed_ones_idempotentlyrecover_apply_refuses_a_live_foreign_claim_and_leaves_the_row_untouchedrecover_apply_enforces_the_deadline_and_leaves_the_candidate_recoverablePlus a CLI parsing unit test (
tools::configuration_tests::recover_arguments_are_bounded_at_the_entry).Docs
docs/prism-ledger-ops.md:recoverbesidelistandabandonin "Candidatecommands" (purpose, configuration asymmetry, plan, apply, deadline, exit table, a
four-step runbook), and the parked-candidates paragraph no longer says there is no
recovery command.
docs/prism-deleted-test-map.md: thetest_prism_pending_block_recovery.pyrowgains the five tests and drops the 3.x.x: Native candidate recover --apply for already-accepted pending blocks #418 clause; it stays
partialonly for 3.x.x: Pin the migration source schema, refuse unknown storage versions, gate startup #285'sstorage-version/legacy-schema refusal, which this issue does not own. Every per-case
row that pointed at 3.x.x: Native candidate recover --apply for already-accepted pending blocks #418 is now
full.docs/prism-rust-migration.md: the third command in the two-drains section.Validation
Run on this Mac against a disposable Homebrew PostgreSQL 16 cluster (
fsync=on,full_page_writes=on):cargo fmt --all --checkandcargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings: clean.cargo test --locked -p qbit-prism-server --all-targets --no-fail-fast -- --test-threads=4with
PRISM_TEST_GATE_MANIFESTandGITHUB_JOB=prism-native-postgresset: 362distinct gated tests executed and
scripts/check_gate_manifest.pyconfirms the fivenew
candidates_recoverentries. The only failures were the ones this machine cannotrun (9
live_regtesttests withoutQBITD_BIN; the 2postgres_failovertests andthe
migration_rollbackrestore withoutPRISM_TEST_PG_BIN_DIR) and threelock-timeout/deadline flakes under parallel load
(
park_tests::unknown_persisted_offer_outcome_parks_as_lifecycle,job_tests::postgres_job_checkouts_start_on_first_poll_and_recover,window_switch_tests::the_rebuild_and_landing_never_wait_for_the_order_lock), whichpass when rerun in isolation.
candidates_clitests from 3.x.x: Candidate list and abandon operator commands, and the legacy-drain runbook step #425 pass together(
--test ledger_postgres candidates_).scripts/check_gate_env_reads.py,scripts/check_prism_settings.pyandtests/test_docs_lab_prism_references.pypass.live_regtest(needs a realqbitd), and workspace-wide clippy for theuntouched crates.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.