Skip to content

v3.0.0 feat: offer found blocks before audit rebuild and landing - #391

Merged
kiwidream merged 4 commits into
3.x.xfrom
offer-block-before-audit-landing
Sep 15, 2026
Merged

kiwidream merged 4 commits into
3.x.xfrom
offer-block-before-audit-landing

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Found blocks can wait behind saturated builders and audit landing before reaching the node. Reserve one durable offer per candidate, check the live claim immediately before submitblock, and send the block before rebuilding and landing its audit. Recovery reconciles accepted, rejected and unknown outcomes without submitting the block again.

Post-offer landing preserves issued balances, audit, payout manifest and coinbase when another block changes current balances. Canonical balances account for active blocks additively, with immutable-evidence checks. Migration 011 adds the lifecycle, preserves known legacy formats and unrelated CHECKs, and refuses unsupported lifecycle constraints transactionally.

Review fixes require the lifecycle declaration at startup and before migration DDL, make the due-work index cover all four unfinished states, and move candidate construction and whole-set balance preparation off the runtime before transaction locks. The same canonical snapshot bytes are reused without weakening immutable-snapshot checks. Recovery exports retain durable offer authority, outcomes and balance evidence for every unfinished state; operator drain checks use the unfinished count.

Older frontends must stop before 011; previously attempted candidates are quarantined without another offer. A crash after reservation can lose delivery. Submission remains serial, and ordinary payout-revision screening can reject work that becomes stale while queued. Claim-to-offer measurements exclude that queue time.

Validation:

  • All 19 required CI checks pass on f9d4593, including all four PostgreSQL / real-node shards and proof that all 319 gated tests executed. PR checks.
  • The final constructor fix passes all 327 library tests and six qualification cases. The offer-latency test passes with eight samples spanning 4.6–8.5 ms, each with one RPC and landing held for three seconds. Its 300,000-recipient regression fails with the blocking handoff removed and yields in 8.2/7.7 microseconds with the fix, preserving exact issued content for both submission paths. The merged base also passes 44 affected contract tests and all nine real-node cases.
  • Docker Rust 1.98.1 formatting and workspace/all-target Clippy with warnings denied pass. Docker shellcheck and 156 Python recovery/runbook tests passed for the unchanged shell and recovery changes.
  • Local full-package evidence is 709 passes, five timing failures and 20 explicitly ignored tests. All three required ignored checks passed, and all 319 gate IDs executed. The same five cases passed in required CI integration mode; all five cases also passed locally on the refreshed base. No timeout bounds were relaxed. The cause of the local timing failures remains unproven.

All four review threads are addressed and resolved. The operations and migration guides document recovery, rollout, first-offer metrics and serial-queue limitations.

Closes #266
Closes #358

Reserve one offer per candidate and reconcile post-offer work without
resubmitting after a crash. Preserve issued audit and payout evidence when
current balances change, with additive active-block accounting.

Add migration 011, lifecycle and upgrade regressions, offer latency checks,
and operational guidance for recovery and the serial submission queue.

Refs #266, #358.
Merge #372, #373 and #380 while preserving the reviewed offer lifecycle
and issued accounting changes.

Keep qualification load running through post-offer rebuild and settlement.
A fast offer can end the old measurement before its minimum sample count;
retain the latency bounds and require successful post-offer bystander shares.

Refs #266, #358.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T19:29:08.376759Z f9d4593 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf0992c65e

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

Require the lifecycle declaration at startup and before migration DDL,
and index every unfinished candidate state for due-work selection.
Prepare as-issued balance snapshots off the runtime before opening the
write transaction, preserving canonical encoding and immutable evidence.

Integrate the current 3.x.x audit, cleanup, recovery and pool metrics
changes. Preserve durable offer authority and all unfinished balance
evidence in recovery exports, and update the restore fixtures and
operator drain checks for migration 011.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df65a76fb1

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

Move candidate construction and the issued-balance clone into blocking work, with a 300,000-recipient regression covering both submission paths. Preserve the proof timestamp and publication lease fence while integrating the current 3.x.x base.
@kiwidream
kiwidream merged commit 049bbf7 into 3.x.x Sep 15, 2026
20 checks passed
kiwidream added a commit that referenced this pull request Sep 15, 2026
Issue #387, stacked on the offer-before-landing work (#391). A claim commits before it decodes the row, so a supported row whose
persisted document, digest, window columns, block bytes or lifecycle
columns fail validation used to return an error and become claimable
again at lease expiry, with no durable reason.

The decode now marks exactly those checks with a closed validation kind,
as typed anyhow context over the original diagnosis. The claim keeps the
row's database hash, its token and the state it selected, and after the
blocking decode reports a marked failure it parks the row in a follow-up
writable transaction through the existing helper. The helper is now fenced
on hash, token and the exact selected state, so a replacement owner or a
row that has since advanced is never touched. The reason is
"candidate <hash>: validation <kind>: <diagnosis>", bounded to 1024 bytes.
The returned error keeps the diagnosis and reports whether the row was
parked, not parked, or unknown after a failed commit. Column extraction,
serialization, executor and database failures are never classified and
never park.

No schema, state, metric, wire response or coordinator change. The ledger
operations guide documents the reason, inspection query, and explicit
operator recovery; no binary unparks a row automatically.

Co-Authored-By: Claude Opus 5 <[email protected]>
Anatolie added a commit that referenced this pull request Sep 15, 2026
PR #391 (offer found blocks before audit landing) landed on 3.x.x first
and took migration 011 for the offer lifecycle: it added 11 to
REQUIRED_SCHEMA_VERSIONS, to the required_versions array of
scripts/prism-recovery-evidence.sql, and to the tests that spell that
constant out. Rebasing this branch onto it renumbered the share ledger
index trim to 012 on the Rust side (the migration file,
NATIVE_MIGRATIONS, ONLINE_MIGRATIONS, REQUIRED_SCHEMA_VERSIONS, and the
gated fixtures the branch had already updated), but three places kept
the old number.

scripts/prism-recovery-evidence.sql still required 2 through 11. The
commit meant to add the trim to it ("require migration 011 in the
recovery evidence export") was written while the trim was 011; after
the rebase 3.x.x had already added 11 for the lifecycle, so that
commit's change to the array disappeared in the conflict resolution
and only its comment survived. Startup refuses a native database
missing 12 (012 is recorded only once its concurrent index builds have
finished), so the export accepted a database startup refuses. The unit
test recovery_evidence_requires_the_migrations_startup_requires reports
exactly that, and the gated regression assert_native_metadata_required
would report "missing required migration 12 was accepted". Add 12.

the_pre_ddl_declaration_fence_runs_whenever_6_or_11_is_recorded, from
#391, hard-coded "2, 3, 4, 5, 6, 7, 8, 9, 10, 11" as the rendering of
REQUIRED_SCHEMA_VERSIONS in the refusal it expects. The fence itself is
right: a record carrying 11 without the candidate_offer_lifecycle row is
refused before any DDL whether or not 12 is recorded, because 012
declares no capability; only the recorded set the refusal names grew.
Derive the expected prefix from schema_version_list(REQUIRED_SCHEMA_VERSIONS)
so the next migration does not stale it again.

tests/offer_lifecycle.rs, also from #391 and PostgreSQL-gated, compared
the record after Ledger::connect(initialize=true) with 2 through 11 and
expected refusals naming that set. connect applies 012 online and
records it before returning, so the record there is now 2 through 12,
as the branch already made candidate_window_migration.rs, ledger_2x.rs,
session_sequence.rs and window_reference.rs expect. Update ALL_VERSIONS
and the three refusal prefixes; this file could not be run here
without PostgreSQL.

The six [2..11] assertions in tests/support/index_trim.rs are
deliberate: undo_012 puts a database back to 11, and the others assert
that a refused online run left 12 unrecorded. The
[2, 3, 4, 5, 7, 8, 9, 10, 11] inputs in migration.rs model a
selectively restored record with 11 and not 6; the fence looks only at
6 and 11, so they stay as they are.

cargo fmt --all also reflows index_trim.rs and ledger_2x.rs, where this
branch's own assertions exceeded rustfmt's default width.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
kiwidream added a commit that referenced this pull request Sep 15, 2026
Issue #387, stacked on the offer-before-landing work (#391). A claim commits before it decodes the row, so a supported row whose
persisted document, digest, window columns, block bytes or lifecycle
columns fail validation used to return an error and become claimable
again at lease expiry, with no durable reason.

The decode now marks exactly those checks with a closed validation kind,
as typed anyhow context over the original diagnosis. The claim keeps the
row's database hash, its token and the state it selected, and after the
blocking decode reports a marked failure it parks the row in a follow-up
writable transaction through the existing helper. The helper is now fenced
on hash, token and the exact selected state, so a replacement owner or a
row that has since advanced is never touched. The reason is
"candidate <hash>: validation <kind>: <diagnosis>", bounded to 1024 bytes.
The returned error keeps the diagnosis and reports whether the row was
parked, not parked, or unknown after a failed commit. Column extraction,
serialization, executor and database failures are never classified and
never park.

No schema, state, metric, wire response or coordinator change. The ledger
operations guide documents the reason, inspection query, and explicit
operator recovery; no binary unparks a row automatically.

Co-Authored-By: Claude Opus 5 <[email protected]>
Anatolie added a commit that referenced this pull request Sep 15, 2026
PR #391 (offer found blocks before audit landing) landed on 3.x.x first
and took migration 011 for the offer lifecycle: it added 11 to
REQUIRED_SCHEMA_VERSIONS, to the required_versions array of
scripts/prism-recovery-evidence.sql, and to the tests that spell that
constant out. Rebasing this branch onto it renumbered the share ledger
index trim to 012 on the Rust side (the migration file,
NATIVE_MIGRATIONS, ONLINE_MIGRATIONS, REQUIRED_SCHEMA_VERSIONS, and the
gated fixtures the branch had already updated), but three places kept
the old number.

scripts/prism-recovery-evidence.sql still required 2 through 11. The
commit meant to add the trim to it ("require migration 011 in the
recovery evidence export") was written while the trim was 011; after
the rebase 3.x.x had already added 11 for the lifecycle, so that
commit's change to the array disappeared in the conflict resolution
and only its comment survived. Startup refuses a native database
missing 12 (012 is recorded only once its concurrent index builds have
finished), so the export accepted a database startup refuses. The unit
test recovery_evidence_requires_the_migrations_startup_requires reports
exactly that, and the gated regression assert_native_metadata_required
would report "missing required migration 12 was accepted". Add 12.

the_pre_ddl_declaration_fence_runs_whenever_6_or_11_is_recorded, from
REQUIRED_SCHEMA_VERSIONS in the refusal it expects. The fence itself is
right: a record carrying 11 without the candidate_offer_lifecycle row is
refused before any DDL whether or not 12 is recorded, because 012
declares no capability; only the recorded set the refusal names grew.
Derive the expected prefix from schema_version_list(REQUIRED_SCHEMA_VERSIONS)
so the next migration does not stale it again.

tests/offer_lifecycle.rs, also from #391 and PostgreSQL-gated, compared
the record after Ledger::connect(initialize=true) with 2 through 11 and
expected refusals naming that set. connect applies 012 online and
records it before returning, so the record there is now 2 through 12,
as the branch already made candidate_window_migration.rs, ledger_2x.rs,
session_sequence.rs and window_reference.rs expect. Update ALL_VERSIONS
and the three refusal prefixes; this file could not be run here
without PostgreSQL.

The six [2..11] assertions in tests/support/index_trim.rs are
deliberate: undo_012 puts a database back to 11, and the others assert
that a refused online run left 12 unrecorded. The
[2, 3, 4, 5, 7, 8, 9, 10, 11] inputs in migration.rs model a
selectively restored record with 11 and not 6; the fence looks only at
6 and 11, so they stay as they are.

cargo fmt --all also reflows index_trim.rs and ledger_2x.rs, where this
branch's own assertions exceeded rustfmt's default width.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Anatolie added a commit that referenced this pull request Sep 15, 2026
* 3.x.x: Trim the share ledger indexes online (migration 011)

Map the six secondary indexes of qbit_share_ledger to the native readers
and trim them to what those readers use (#153): replace the seven-column
share_seq covering index, which no native read ever used index-only, with
a three-column one that makes the frozen qbit_prism_window page walk and
the landing durable-range count index-only; drop payout_order_key from the
miner index, which nothing reads; drop the job_issued_at and
template_height indexes, which have no native consumer. WHERE accepted
stays: the readers exclude rejected rows by contract (the window and
rollup tests write them), and the predicate keeps the frozen 001 walk
index-only without carrying the column.

CREATE INDEX CONCURRENTLY cannot run in the migrator's transaction, so 011
is the first ONLINE_MIGRATIONS entry: its file is replayed in the scratch
schema to derive the index definitions, applied inside the transaction on
an empty ledger, and otherwise applied after the commit on a dedicated
connection with CONCURRENTLY, under a schema-keyed session lock, recorded
last. The runner inspects every reserved name before any DDL, rebuilds an
invalid leftover, keeps an identical earlier build and refuses anything
else by name.

Four gated tests cover the empty-ledger path, a frozen 2.x.x source with
rows, a build with a writer transaction held open, and resume/keep/refuse.
The ops doc gains the index inventory and the production measurement
runbook the issue's gate asks for; the migration guide the online apply.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix: run native ledger index migrations concurrently

Always defer online migrations for existing native schemas, including ledgers whose first share is still uncommitted. Keep fresh and empty legacy cutovers transactional under their writer locks. Poll the online advisory lock without holding a waiting statement snapshot, so simultaneous frontend upgrades cannot deadlock concurrent index builds. Scope the first-share regression observer to its own ledger.

* fix: refuse foreign invalid online migration indexes

* test: update migration fixtures for schema version 11

* fix: verify old index definitions before online removal

* ci: replace stale test artifacts on job retries

* fix: recheck online index drop targets after concurrent builds

The online runner decides its plan before any DDL: every index the
migration creates and drops is looked up once, and each Rebuild and Drop
step then runs DROP INDEX CONCURRENTLY by name. Between that look-up and
the drops sit the CREATE INDEX CONCURRENTLY builds, which take hours on
a large ledger, and nothing in that window stops an operator's DDL under
a reserved name: the advisory lock orders only runners, and ALTER INDEX
RENAME locks the index alone, so a release index can be moved aside and
another created under its name (on any table) while a build holds the
ledger. The stale plan then dropped an index the migration did not own,
after the preflight had promised it would not.

Each destructive step now looks its target up again as it is reached and
drops only if the name still holds what the plan saw: the same table and
definition, and for a rebuild still the invalid index an interrupted
build left. Step::Drop carries the IndexDefinition for that instead of
the table name. Anything else refuses the run, naming the index, what it
reads as now and what the plan held, and, unlike the preflight refusals,
what the run had already built and dropped by then, since that is no
longer nothing; the next start plans afresh and keeps those.

The recheck and the drop remain two statements, because CONCURRENTLY
refuses a transaction block and PostgreSQL drops by name, so a change
that lands in the round trip between them is still not caught. That
window is milliseconds rather than the hours of a build and cannot be
closed in SQL; the code says so.

The new gated test holds the first build behind an open writer, swaps a
drop target (and, in a second phase, the invalid index a rebuild would
replace) for an operator's index on another table while it waits, and
asserts the refusal, its account of what ran, the untouched operator
index, and that the next start finishes the migration keeping the built
indexes. Against the previous runner the same test fails because the
operator's index is dropped. It is listed in test/prism-gated-tests.txt,
which the proof job checks every executed gated test against.

* fix: require migration 011 in the recovery evidence export

Adding 011 to REQUIRED_SCHEMA_VERSIONS left the PL/pgSQL gate in
scripts/prism-recovery-evidence.sql at 2 through 10, so a native
database that startup refuses for lacking 011 still exported evidence,
against the script's stated requirement to mirror startup. The gated
regression that removes each declared version in turn caught it in CI
("missing required migration 11 was accepted").

Add 11 to the script's required_versions, and add a migration unit test
that reads the declaration back from the script and compares it with
REQUIRED_SCHEMA_VERSIONS, so the next drift fails in the fast unit job
rather than only under the PostgreSQL gate. Point the constant's doc at
the script.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix: verify the whole online index set before recording migration 11

The online runner rechecks only the names it is about to drop. A
replacement that was already valid at preflight is planned as Keep and
never looked at again, and a build checks its own index only as it
finishes; the other replacement's CREATE INDEX CONCURRENTLY then runs
for hours on a large ledger, in which an operator can rename or replace
either just as they can a drop target: the advisory lock orders only
runners, and ALTER INDEX RENAME locks the index alone. The run still
recorded 11 afterwards, so every later start trusted the record and
accepted a database with a required replacement missing or altered.

Every name the migration declares is now looked up once more inside the
transaction that records the version, after MIGRATION_LOCK and before
the INSERT: each created index must be valid on its table with exactly
the declared definition, and each dropped name absent. Anything else
refuses the run before the commit, naming the index, what it reads as
now, what the migration declares, and what the run had already built
and dropped; the version stays unrecorded and the next start plans
afresh. The preflight, the drop rechecks and the post-build check stay;
the phrasing of what a name holds now is shared with drop_planned. What
remains open is the round trip between the look-up and the INSERT, since
nothing here can lock an index against another session's DDL, not the
hours of a build.

The new gated test pre-builds one replacement so the run keeps it, holds
the other build behind an open writer, renames the kept index and puts
an operator's index under its name while the build waits, and asserts
the refusal, that 11 is not recorded, that the operator's index and the
renamed one are untouched, and that once the name is restored the next
start records 11 keeping both indexes. Without the check the same test
fails because the run records 11 over the swapped index. It is listed
in test/prism-gated-tests.txt.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix: finish renumbering the index trim to 012 in the gate and tests

PR #391 (offer found blocks before audit landing) landed on 3.x.x first
and took migration 011 for the offer lifecycle: it added 11 to
REQUIRED_SCHEMA_VERSIONS, to the required_versions array of
scripts/prism-recovery-evidence.sql, and to the tests that spell that
constant out. Rebasing this branch onto it renumbered the share ledger
index trim to 012 on the Rust side (the migration file,
NATIVE_MIGRATIONS, ONLINE_MIGRATIONS, REQUIRED_SCHEMA_VERSIONS, and the
gated fixtures the branch had already updated), but three places kept
the old number.

scripts/prism-recovery-evidence.sql still required 2 through 11. The
commit meant to add the trim to it ("require migration 011 in the
recovery evidence export") was written while the trim was 011; after
the rebase 3.x.x had already added 11 for the lifecycle, so that
commit's change to the array disappeared in the conflict resolution
and only its comment survived. Startup refuses a native database
missing 12 (012 is recorded only once its concurrent index builds have
finished), so the export accepted a database startup refuses. The unit
test recovery_evidence_requires_the_migrations_startup_requires reports
exactly that, and the gated regression assert_native_metadata_required
would report "missing required migration 12 was accepted". Add 12.

the_pre_ddl_declaration_fence_runs_whenever_6_or_11_is_recorded, from
REQUIRED_SCHEMA_VERSIONS in the refusal it expects. The fence itself is
right: a record carrying 11 without the candidate_offer_lifecycle row is
refused before any DDL whether or not 12 is recorded, because 012
declares no capability; only the recorded set the refusal names grew.
Derive the expected prefix from schema_version_list(REQUIRED_SCHEMA_VERSIONS)
so the next migration does not stale it again.

tests/offer_lifecycle.rs, also from #391 and PostgreSQL-gated, compared
the record after Ledger::connect(initialize=true) with 2 through 11 and
expected refusals naming that set. connect applies 012 online and
records it before returning, so the record there is now 2 through 12,
as the branch already made candidate_window_migration.rs, ledger_2x.rs,
session_sequence.rs and window_reference.rs expect. Update ALL_VERSIONS
and the three refusal prefixes; this file could not be run here
without PostgreSQL.

The six [2..11] assertions in tests/support/index_trim.rs are
deliberate: undo_012 puts a database back to 11, and the others assert
that a refused online run left 12 unrecorded. The
[2, 3, 4, 5, 7, 8, 9, 10, 11] inputs in migration.rs model a
selectively restored record with 11 and not 6; the fence looks only at
6 and 11, so they stay as they are.

cargo fmt --all also reflows index_trim.rs and ledger_2x.rs, where this
branch's own assertions exceeded rustfmt's default width.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix: name migration 012 in the index trim's expected refusals and docs

Shard 3 of the PostgreSQL job fails in
migration_012_refuses_a_drop_target_swapped_while_it_built and
migration_012_refuses_to_record_when_a_kept_index_moved_while_it_built,
both at the `error.contains(refusal)` assertion of swap_during_build. It
is the same incomplete 011 -> 012 renumber as the previous commit, this
time in string literals. The online runner (ledger/migration/online.rs)
formats "refusing to continue migration {version}" and "refusing to
record migration {version}" from the version ONLINE_MIGRATIONS carries,
which is 12, and the text CI prints says 12, while the three expected
refusals handed to swap_during_build still said 11. Both tests failed
the same way on 4d57301, before the previous commit.

The literals stay literals rather than being derived. This file is
about migration 012 by name: its module doc, every test name, undo_012
and its DELETE ... WHERE version=12. ONLINE_MIGRATIONS is not public,
and the one public number, the last of REQUIRED_SCHEMA_VERSIONS, would
follow a future transactional 013 while the migration under test stayed
12, so deriving from it would break in exactly the case it is meant to
survive.

The same sweep found two comments in the file saying the run "records
11", and three lines in the "Migration 012" section of
docs/prism-rust-migration.md, written on this branch, that say the
runner records 11 and quote its refusal as "migration 11". Renumbered
too. Everything else in the crate, scripts and docs that still says 11
or 011 belongs to the offer lifecycle, or is a deliberate pre-012 state:
"back to 11", "a database at 11", and the [2..11] record assertions
after a refused run.

The two tests need PostgreSQL and did not run here. cargo fmt --all
--check and cargo clippy -p qbit-prism-server --all-targets -- -D
warnings pass.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix: move online share-ledger index trim to migration 013

Preserve upstream migration 012's startup fence and use 013 for the online index trim. Align the migration include, recovery gate, fixtures, expected refusals, integration gate names, and operator docs.

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
kiwidream added a commit that referenced this pull request Sep 16, 2026
* v3.0.0 test: keep the pg_restore session off the fixture pool

support::recovery::restore ran the SQL that pg_restore emits on a
connection borrowed from the fixture pool. That SQL opens with session
SET statements that survive COMMIT: PostgreSQL 16 emits
statement_timeout = 0, lock_timeout = 0 and
idle_in_transaction_session_timeout = 0 besides the search_path reset,
and sqlx 0.8.6 returns a pooled connection through a spawned task with
no session reset, so a later pooled query inherited whichever of them
landed on the same connection.

Run the restore on a dedicated PgConnection instead: one transaction,
commit, then close. The restore result is evaluated before the close
result so a failed close cannot hide the restore error. The session is
built from the fixture URL, which pins search_path to the target
schema, and the helper checks current_schema() against the target
before restoring into it.

Drop #391's in-transaction search_path reset. It returned the pooled
session to the fixture schema before reuse; the dedicated session is
closed and never reused, so the mechanism that produced the
intermittent "relation does not exist" failure is gone rather than
patched over. The new test pins search_path along with the timeouts.

The new gated test opens its target with the ledger's operator
timeouts on the URL, because the fixture's plain pool defaults every
setting pg_restore touches to 0 and would not observe the leak. It
waits for sqlx to return every connection and then reads all of them,
so the check does not depend on release scheduling. Before this change
it fails on every run with "pooled lock_timeout is "0", expected "5s"".

Closes #411.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* v3.0.0 test: pin the restore-over-close error precedence

The pg_restore session helper evaluated the restore result before the
close result so a failed close could not hide why the restore failed,
but nothing tested that order: swapping the two lines left every
migration_rollback test green, because no test injects a failing close
against a live connection.

Move the precedence into a pure helper, restore_outcome, and unit-test
all four combinations directly. When both fail, the restore error is
returned with the close failure appended to its message, so the
operator reads the restore error first and the close failure is not
lost either. The session is still closed on both paths; only which
error is reported is pinned. Swapping the precedence in the helper now
fails restore_outcome_prefers_the_restore_error_when_both_fail.

Follow-up to #411.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
kiwidream added a commit that referenced this pull request Sep 18, 2026
The migration narrative still said proof-to-first-offer waits were declared
with a rule deferred, and that advisory-lock waits had no rule written. Both
are now wrong: the first-offer histogram is instrumented as
qbit_prism_block_submit_seconds under #391, and the advisory-lock rules land
in this branch.

Say what is actually true. First-offer carries no firing rule because it is
observed at most once per found block, which is too sparse for a rate or a
percentile, not because a rule is pending. Name the two advisory-lock rules
and record that lock="migration" is deliberately outside them. The same
correction applies to the retired-name reasons, so the generated migration
tables and the review-only deployment patch are regenerated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
kiwidream added a commit that referenced this pull request Sep 22, 2026
The migration narrative still said proof-to-first-offer waits were declared
with a rule deferred, and that advisory-lock waits had no rule written. Both
are now wrong: the first-offer histogram is instrumented as
qbit_prism_block_submit_seconds under #391, and the advisory-lock rules land
in this branch.

Say what is actually true. First-offer carries no firing rule because it is
observed at most once per found block, which is too sparse for a rate or a
percentile, not because a rule is pending. Name the two advisory-lock rules
and record that lock="migration" is deliberately outside them. The same
correction applies to the retired-name reasons, so the generated migration
tables and the review-only deployment patch are regenerated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
kiwidream added a commit that referenced this pull request Sep 22, 2026
…463)

* Alert on order and settlement advisory-lock waits

qbit_prism_database_advisory_lock_wait_seconds has been recorded since #328
with no rule attached, so a coordinator can sit behind the order or settlement
advisory lock indefinitely without anyone being paged.

Add two native rules. PrismDatabaseAdvisoryLockWaitHigh watches the per-lock
p99 over five minutes, and PrismDatabaseAdvisoryLockFailuresCritical pages on
the per-lock failure ratio, where failure also covers a wait abandoned by
cancellation. Both exclude lock="migration": that lock is taken only at schema
initialization, where waiting out an online migration window is expected
rather than a fault.

The family is rendered from the cached snapshot body rather than read live at
scrape time, so both rules carry the snapshot-fresh gate the other cached-body
rules use. A stale or unpublished body suppresses them instead of repeating an
old percentile, and the failure ratio stays absent rather than zero until a
first failure is observed, which is why no-data remains OK.

Fixture scenarios cover per-lock discrimination, the per-lock sample minimum,
migration-only waits, stale and missing snapshot series, and both sides of the
five-percent failure boundary. The inventory prohibition on this family is
narrowed to these two rule UIDs so no other rule can reach for it, and the
first-offer prohibition is untouched.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* Correct the stale first-offer and lock-wait rule prose

The migration narrative still said proof-to-first-offer waits were declared
with a rule deferred, and that advisory-lock waits had no rule written. Both
are now wrong: the first-offer histogram is instrumented as
qbit_prism_block_submit_seconds under #391, and the advisory-lock rules land
in this branch.

Say what is actually true. First-offer carries no firing rule because it is
observed at most once per found block, which is too sparse for a rate or a
percentile, not because a rule is pending. Name the two advisory-lock rules
and record that lock="migration" is deliberately outside them. The same
correction applies to the retired-name reasons, so the generated migration
tables and the review-only deployment patch are regenerated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* Exercise the critical rule's per-lock sample minimum

Every sample-minimum scenario so far carried only result="success" series, so
PrismDatabaseAdvisoryLockFailuresCritical's ratio was absent and its >=10 gate
was never evaluated. Collapsing that gate to a shared minimum across both
locks therefore passed the suite untouched.

Add a scenario where a busy clean lock records 100 waits with no failures
while the other lock records two waits, one of them a failure. The ratio is
0.5 but the sample is two, so the per-lock gate drops it and the contract
value stays zero; a shared minimum would lend the clean lock's hundred waits
to the failing one and page. Add a second scenario where both locks breach on
their own samples, pinning the value at two for the percentile and the ratio
alike so neither rule may silently collapse two locks into one series.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant