Skip to content

3.x.x: map 002's legacy share hashes after the migration transaction, in bounded batches with a durable cursor, and record 2 last (#582) - #663

Merged
RobertClarke merged 3 commits into
3.x.xfrom
prism-582-batched-share-hash-backfill
Oct 5, 2026
Merged

RobertClarke merged 3 commits into
3.x.xfrom
prism-582-batched-share-hash-backfill

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #582.

Migration 002's share-hash backfill was one INSERT ... SELECT DISTINCT ON over every accepted share, inside migrate's transaction and under its statement timeout, so migrate could not complete on a production-sized ledger (about 65.5M shares) at any allowed setting. This makes the backfill an online, batched, resumable step that records 2 last, as the issue's option (a) and the recommendation in its comments propose.

Design

  • 002's file loses its backfill statement. Everything else in 002 is unchanged and still applied in the migration transaction.
  • A fresh or empty 2.x.x source has nothing to map, so 2 is recorded in the transaction, as before.
  • A 2.x.x source with rows: the transaction creates a one-row cursor, qbit_prism_share_hash_backfill (start_seq, next_seq, end_seq, started_at, updated_at), covering every share_seq the ledger holds. It does not record 2.
  • After the commit, before 013 and 017, the runner (ledger/migration/share_hashes.rs, through the existing online-migration entry point and runner lock) maps the legacy shares in batches of consecutive share_seq:
    • each batch is 002's statement restricted to [next_seq, upper): one statement, in a transaction that also advances the cursor;
    • the first batch covers 10,000 share_seq; later ones double or halve toward 500 ms, between 1,000 and 50,000;
    • every statement runs under the server's own statement timeout (15 s by default), which nothing raises;
    • a batch that times out all the same, after a gap or a run of rejected shares on a slow disk, is rolled back and retried at half its size.
  • Recording. The last transaction waits for the migration lock, as 013's and 017's records do, and checks that the cursor has passed every row the ledger holds. It then drops the cursor table and records 2.
  • Same result, row for row. Batches run in ascending share_seq and each uses the original DISTINCT ON ... ORDER BY header, share_seq. So the earliest share of a repeated legacy header is mapped by the batch that holds it, and later copies meet ON CONFLICT DO NOTHING. A unit test pins the batch statement to the old single statement, less its range.
  • No foreign-key checks during the batches. 016 has already dropped the mapping's foreign key onto the ledger by the time they run, so the per-row RI check the single statement paid is gone.
  • Resumable.
    • An interrupted run, whether killed, disconnected, cancelled or timed out, loses only the batch in flight.
    • migrate again finds 3 recorded without 2 and the cursor table present. It applies nothing in the transaction and resumes at next_seq; 013 and 017 follow.
    • A record with 3 and not 2 and no cursor table is still refused as an edited record, with the remedy now naming the mapping too.
    • A 2.x.x source that already holds a relation named qbit_prism_share_hash_backfill is refused before any DDL.
  • Readiness: the server does not serve during the backfill.
    • Until 2 is recorded, every start refuses the database. That covers this release and every earlier native build, since each requires 2.
    • The 2.x.x writer is fenced by 002's lease trigger, which commits with the transaction. So no share is appended while legacy headers are unmapped, and the issue's duplicate-detection question doesn't arise. No change to the append path.
    • require_schema_version names the cursor in its refusal: "migration 2's share-hash backfill has not finished ... below share_seq X of the Y ...". It refuses the same way even if someone records 2 by hand while the table exists.
    • Starts, self-check and import-audits all go through that gate.
    • The recovery evidence export (scripts/prism-recovery-evidence.sql) refuses a pending cursor too.
  • Progress.
    • migrate logs the start, a progress line every 10 s (next_seq, end_seq, rows mapped, share_seq/s, estimated seconds left) and completion.
    • The cursor row is queryable from any session.
    • There is no Prometheus series: no frontend runs during the backfill, and adding a postgres-exporter query would pull in the alert pipeline and the qbit-tools patch.
  • ACK boundary. No native share can be acknowledged before 2 is recorded, so the whole backfill is pre-ACK. An interrupted cutover can be resumed with migrate or rolled back by restoring the pre-migration backup.

Tests

All local runs used PostgreSQL 16.15 with fsync on.

New integration tests (ledger_postgres::share_hash_backfill, registered in test/prism-gated-tests.txt):

  • migration_002_maps_a_populated_2x_ledger_in_batches_as_its_single_statement_did:
    • The ledger has about 59k rows. Every 97th row repeats, in upper case, the header of the share 9,001 share_seq below or above it, so the pairs straddle batch boundaries and the earlier copy wins on either side. There are gaps in share_seq, rejected rows, non-hex IDs and bare 64-digit IDs.
    • The mapping equals the single statement's exactly.
    • 2 is recorded after the transaction's migrations and before 013 and 017, and the cursor table is gone.
    • A native share repeating a legacy header is refused, and a second start maps nothing.
  • migration_002_backfill_resumes_from_its_last_committed_batch_after_an_interrupt:
    • The test holds the runner lock so the transaction commits. It then checks the pending state: the recorded versions, the cursor, an empty mapping, and starts refused with the cursor in the message.
    • An open insert of a late header blocks a mid-run batch. The committed prefix equals the single statement's over exactly that prefix.
    • The test kills the batch's backend with pg_terminate_backend. Nothing of the killed batch survives, and starts still refuse, even with 2 recorded by hand.
    • migrate resumes at the cursor, finishes with the exact full mapping, and records 2 before 013 and 017.
  • migration_002_maps_a_row_past_its_planned_end_before_recording_2: the runner re-reads the ledger's end under the migration lock and maps a row that landed past it.
  • migration_002_refuses_a_2x_source_holding_the_backfill_progress_name_before_any_ddl.
  • migration_rollback's metadata regression: the evidence export refuses a pending cursor even with 2 recorded.

Unit tests (share_hashes.rs): the batch sizing bounds; the batch statement equals 002's single statement less its range; the refusal text.

Existing suites:

  • cargo test -p qbit-prism-server --test ledger_postgres: 193 passed. That covers the 2.x.x upgrade, the 013 and 017 online-runner and legacy-duplicate tests, and the new ones.
  • cargo test -p qbit-prism-server --lib: 639 passed.
  • Other integration binaries:
    • 32 binaries run locally before I paused for the benchmark: 922 passed, 1 failed.
    • The failure was candidate_window_qualification::order_lock_hold_on_a_solve_does_not_grow_with_the_window, a timing threshold, on a debug build under heavy host load. It passes in isolation (hold growth −2.8 ms against 15 ms of slack). It uses a native ledger and never reaches 002.
    • CI runs the rest.
  • cargo clippy --locked --workspace --all-targets -- -D warnings and cargo fmt --check: clean.
  • scripts/check_prism_pool_acquires.py: clean. The runner's two connection.begin() sites are registered as borrowed transactions, like partition.rs.
  • check_gate_env_reads.py, and the gate-manifest, acquire and docs-reference Python tests: clean.

Measurements

Setup:

  • Mainnet-shaped 2.x.x ledgers from the repository's generator (make prism-cutover-rehearsal-dump SCALE=1 DENSITY=…), each with all 13,566 blocks and 257 addresses.
  • PostgreSQL 16.15 with fsync on.
  • A shared 16-core / 62 GB host, with 1-minute load average 3–24 from other work during the runs.
  • This PR's release build, at the server's default 15 s statement timeout throughout.

Official measured rehearsal on 8.25M shares (DENSITY=0.125; make prism-cutover-rehearsal, private cluster at PostgreSQL defaults): PASS, every check. That covers recovery evidence, sums over 16 tables, 257 balances by SQL and by API, the 45,168-share payout window, frontend readiness, first job, self-check and audit completeness.

Step Wall time Longest lock
migrate: transaction (001, 002–021 less the backfill) 4.2 s (016's statement 3.3 s) ACCESS EXCLUSIVE, the cutover locks, 4.1 s
migrate: 002 share-hash backfill 320.9 s ROW EXCLUSIVE on qbit_prism_share_hashes; ACCESS EXCLUSIVE only on the cursor table, 11 ms
migrate: 013 concurrent indexes 28.4 s SHARE UPDATE EXCLUSIVE
migrate: 017 prepare / validate / swap 0.01 / 1.3 / 0.2 s ACCESS EXCLUSIVE 103 ms (swap)
migrate (total) 355.0 s
import-audits 76.1 s

For comparison, #582's 4.13M rehearsal held ACCESS EXCLUSIVE on qbit_share_ledger for 346 s, with 002 alone at 321 s under a 600 s timeout.

Before and after, same dump, same host. The unmodified 3.x.x migrate, at the maximum allowed 600 s timeout, failed after 609 s in 002's single statement (canceling statement due to statement timeout), and its transaction rolled back. This PR completes the same ledger at the default 15 s.

Backfill rate by size and settings. Each run is qbit-prism-server migrate on a fresh pg_restore, with the cursor sampled once a second; the reruns reset the database to "backfill pending".

Shares PostgreSQL settings Backfill Rate by position WAL
8.25M defaults (128 MB shared_buffers, 1 GB max_wal_size) 348 s, 413 s (two runs) ~40k share_seq/s up to ~5M, ~13k/s after 16 GB
8.25M shared_buffers=4GB, max_wal_size=32GB, checkpoint_timeout=30min 251 s flat 30–40k/s 5.8 GB
8.25M the same plus work_mem=64MB 255 s unchanged: the batch sort is not the cost 5.8 GB
16.5M defaults 959 s (whole migrate 1,042 s, exit 0) ~45k/s up to ~5M, then a flat ~12.6k/s average to 16.5M not sampled
16.5M the bulk-load settings above 386 s flat 43–52k/s (one dip) 11 GB
  • Defaults. The rate falls once the mapping's two indexes outgrow the cache. Checkpoints then come every few seconds (29 forced in one 8.25M run) and turn most inserts into full-page writes.
  • Bulk-load settings. The rate holds even after the indexes pass shared_buffers (4.9 GB at 16.5M): checkpoints stop, and the OS cache serves the evicted pages.
  • No batch timed out in any run, and none was retried.
  • Size. The mapping takes about 494 bytes per share with its indexes: 8.0 GB at 16.26M.

Extrapolation to 65.5M shares:

  • Backfill: about 25–35 min with bulk-load settings (43k/s measured at 16.5M, 33k/s under heavier host load at 8.25M), and about 80–85 min at PostgreSQL defaults (5M at ~45k/s, then ~12.6k/s).
  • Rest of migrate: about 5 min for 013's builds; seconds for the transaction and 017.
  • Storage: the mapping grows to about 32 GB. The backfill writes about 45 GB of WAL with bulk-load settings and about 130 GB at the defaults; it is recycled unless archiving or a replication slot holds it.
  • Assumption behind the bulk-load figure: the production host's page cache can hold most of the mapping's ~20 GB of indexes. With much less memory, expect the default-settings rate.

The one statement left in the transaction that can matter (#672, not changed here). 016's solver attribution makes one random index probe per block (13,566). It took about 0.1 s with its pages cached, and 29.7 s when every page came from a disk saturated by another bulk load. An earlier rehearsal on this host, run while I was generating another dump on the same disk, refused there at the 15 s default. So its cost scales with blocks, not shares, but a cold cache on a slow or busy disk can approach the default timeout. #672 proposes bounding it per statement. Until then, a production-host rehearsal that refuses in 016 can give migrate 60000 ms.

Follow-ups

Docs

  • docs/prism-rust-migration.md:
    • a new section, "Migration 002's share-hash backfill, applied online": design, cursor columns, readiness (the server does not serve during it), progress query, interrupt and resume, the point of no return, refusals, and sizing;
    • the "Drain and migrate" paragraph, the rehearsal report's step split, the ACK-boundary note, and the weekly scenario's description.
  • doc/release-notes-3.x.x-development-line.md: a 3.x.x: migration 002's share-hash backfill cannot complete on a production-sized ledger (statement timeout) #582 entry.
  • test/e2e-scenarios.toml and .github/workflows/prism-load-nightly.yml: the weekly scenario's density and timeout notes.

Downstream (SwapLabsInc/qbit-tools, testnet, PR #1143)

Once the play's bootstrap pin includes this change:

  • Gate 6b (share-backfill ceiling) can be retired.
    • No share count makes migrate hit a statement timeout any more, so the 259,000 and 3,861,015 ceilings no longer describe anything.
    • qbit_mining_pool_prism_3xx_backfill_ack_shares is no longer needed.
    • If you want to keep the probe, keep it as information: report the count and a time estimate (see "Measurements" above), never a refusal.
  • qbit_mining_pool_prism_3xx_migrate_statement_timeout_ms: leave it unset by default.
  • Size qbit_mining_pool_prism_3xx_migrate_timeout_seconds (3600) for the whole command.
    • On a populated ledger, migrate now runs 002's backfill, 013's builds and 017's validation after the commit, all inside the same command.
    • At 65.5M shares, expect about 30–40 min with bulk-load PostgreSQL settings and about 90 min at the defaults (see "Measurements").
    • So 3600 s is enough only with the bulk-load settings. Either set them for the window, or raise the timeout to about 2 h.
    • A kill is resumable anyway (next point).
  • A killed migrate is resumable, not UNKNOWN.
    • Once the transaction has committed, a timeout kill during the backfill, 013 or 017 leaves a state that migrate resumes.
    • The backfill is pending exactly while qbit_prism_share_hash_backfill exists (3 recorded, 2 not). 013 or 017 is pending when its version is missing.
    • The play can re-run migrate instead of stopping the lane as UNKNOWN. Starts keep refusing the database until it has finished, so a re-run is safe.
  • Progress.
    • With RUST_LOG=qbit_prism_server=info, migrate logs a backfill line every 10 s with next_seq, end_seq, share_seq/s and the seconds left.
    • A read-only SELECT next_seq, end_seq FROM qbit_prism_share_hash_backfill shows the same, and the play could poll it.
  • PRISM_REHEARSAL_291.md §8.1a: the decision table becomes "nothing to set at any size; budget the backfill time". 3.x.x: Cutover qualification — migration rehearsal, failover drill, soak, go/no-go #291's production-size rehearsal can run at the default timeout.

🤖 Generated with Claude Code

… in bounded batches with a durable cursor, and record 2 last (#582)

Migration 002 backfilled qbit_prism_share_hashes with one INSERT ...
SELECT DISTINCT ON over every accepted share, inside migrate's transaction
and under its statement timeout. At the default 15 s it failed from about a
million shares. At 4.13M it took 321 s of the 600 s cap, with a per-share
cost that kept rising, so the production ledger (65.5M shares) could not be
migrated with any allowed setting.

002's file now ends at the table. A fresh or empty source records 2 in the
transaction as before. A populated 2.x.x source gets a one-row cursor,
qbit_prism_share_hash_backfill (next_seq, end_seq), in the transaction,
and 2 is not recorded there. After the commit, before 013 and 017, the
runner in ledger/migration/share_hashes.rs maps the legacy shares in
batches of consecutive share_seq, under the online runner lock. Each batch
is 002's statement restricted to its range: one statement, in a
transaction that also advances the cursor, sized toward 500 ms under the
server's own statement timeout. The last transaction checks, under the
migration lock, that the cursor has passed every row, then drops the
cursor and records 2. The mapping is the single statement's, row for row:
batches run in ascending order with DISTINCT ON inside each, and ON
CONFLICT DO NOTHING applies across them.

Until 2 is recorded, every start refuses the database, this build's and
every earlier one's. The 2.x.x writer is fenced by 002's lease trigger. So
nothing is appended while legacy headers are unmapped, and the append path
is unchanged. require_schema_version names the cursor in its refusal, even
if 2 was recorded by hand. An interrupted migrate resumes at the cursor:
the native path accepts 3 without 2 when the cursor table exists, and still
refuses it otherwise. A 2.x.x source that already holds the cursor's name
is refused before any DDL.

Tests:
- The batched mapping equals the single statement's on a ledger that
  repeats headers across batch boundaries in upper case, with gaps,
  rejected rows, non-hex IDs and bare 64-digit IDs.
- A run killed mid-batch leaves the last committed cursor; starts refuse
  the database; migrate then resumes to the exact mapping.
- A held cursor name is refused before any DDL.
- The weekly mainnet-shaped scenario drops its 600 s override and its #582
  expected-failure check, returns to 1/16 density, and requires the
  backfill step.
- The cutover rehearsal reports the backfill as its own step.

Measured on a mainnet-shaped ledger of 8.25M shares at the default 15 s
timeout, migrate completes in 462 s. The backfill takes 348-413 s at
PostgreSQL's default memory settings, and 251 s with shared_buffers 4GB
and max_wal_size 32GB. docs/prism-rust-migration.md has the section, the
readiness rule and the sizing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 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-10-05T19:21:42.120579Z a086010 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.

RobertClarke and others added 2 commits October 5, 2026 14:59
…update the weekly job's #582 note (#582)

The runner re-reads the ledger's end under the migration lock before it
records 2. A row past the end the cursor was planned to is mapped by
another pass, not left unmapped. Nothing appends before 2 is recorded, so
only a writer that went around every gate could put one there; the new
test inserts one while the backfill waits on the runner lock, and checks
that it is mapped and the cursor is dropped.

The weekly live-regtest job's comment now describes the scenario as it
runs after #582: 1/16 of mainnet's rows, about 4.1M, cut over at the
server's default statement timeout. No job, step or setting changes. The
first push of this PR left the comment out: the token then lacked the
workflow scope (#665).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…its locks, and refuse a pending cursor in the evidence export (#582)

From /code-review high on the backfill:

- Batch size counts share_seq values, not rows. After a gap or a run of
  rejected shares, batches are cheap and grew to 200,000, and the next
  dense range could outlast the statement timeout. BATCH_MAX is now
  50,000, under 4 s at the slowest measured rate. A batch that times out
  all the same is rolled back and retried at half the size; an operator's
  cancel request (same SQLSTATE, another message) still stops the run.
- The recording transaction ran under the pool's 5 s lock timeout after
  all the mapping was done. Like 013's and 017's records, it now waits
  for the migration lock and for readers of the cursor table.
- The recovery evidence export refuses while qbit_prism_share_hash_backfill
  exists, as startup does, so a hand-recorded 2 cannot export a partial
  mapping. The metadata regression checks it.
- A start that takes no lock could find the cursor table, then lose it to
  the recording transaction's DROP. progress() reads that as complete
  rather than failing with 42P01. A non-table under the cursor's name is
  refused by name. One catalog probe serves both checks.
- The cursor records start_seq. The refusal and the documented percent
  query state the mapped and unmapped share_seq ranges instead of reading
  end_seq as a count.
- Each batch checks the cursor with a conditional UPDATE after the
  insert, instead of a separate SELECT ... FOR UPDATE.
- The interrupt test terminates the waiting batch first and asserts the
  durable state afterwards, so the batch's own lock timeout cannot race
  it on a slow runner.
- The docs warn against running an earlier 3.x.x build while the backfill
  is pending: its remedy for 3 without 2 is to record 2 by hand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

/code-review high round (10 candidates), addressed in a086010:

  • Batch sizing after sparse or cheap ranges. Fixed: BATCH_MAX 200,000 → 50,000, and a batch that hits the statement timeout is rolled back and retried at half the size. An operator's cancel still stops the run.
  • Recording step on the pool's 5 s lock timeout. Fixed: it now waits for the migration lock and for readers of the cursor table, as 013's and 017's records do.
  • Evidence export accepted a pending cursor when 2 had been recorded by hand. Fixed: prism-recovery-evidence.sql refuses while qbit_prism_share_hash_backfill exists, and migration_rollback's metadata regression covers it.
  • progress() raced the final DROP for a start that takes no lock. Fixed: a vanished table reads as complete. A non-table under the name is refused by name, and one catalog probe now serves both checks.
  • end_seq read as a count. Fixed: the cursor stores start_seq, and the refusal and the documented percent query give the mapped and unmapped ranges.
  • Redundant SELECT ... FOR UPDATE per batch. Replaced by a conditional cursor UPDATE.
  • The interrupt test could race the waiting batch's lock timeout. Fixed: it terminates first and asserts the durable state after.
  • An earlier build's "record 2 by hand" remedy could let it serve mid-backfill.
  • Rehearsal step attribution: the runner-lock probe and the cursor read count toward the neighbouring step. That's a sub-second skew with the same carry-forward rule 013 and 017 already have, so I left it.
  • One catalog probe for the held-name check and the cursor read: done with the fix above.

Earlier in the PR, 31396e9 added a test for the runner's "rows past the planned end" pass and restored the weekly job's comment, which needed workflow scope; #665 is closed.

@RobertClarke
RobertClarke merged commit bd1ddeb into 3.x.x Oct 5, 2026
34 checks passed
@RobertClarke
RobertClarke deleted the prism-582-batched-share-hash-backfill branch October 5, 2026 19:40
RobertClarke added a commit that referenced this pull request Oct 5, 2026
…runners' lock, so an earlier runner cannot leave one behind (#669)

Codex (P1) and /code-review high on #681: a resume declared the fence in
its migration transaction, which does not take the runners' lock. A runner
of a #663-era build that was still mapping could then finish, drop the
cursor and record 2 without knowing the fence. This release's runner,
queued behind it, found 2 recorded and returned, and the orphaned fence
would have locked out a fully mapped ledger.

- The migration transaction now declares the fence only for a cursor it
  creates itself.
- A runner that resumes the backfill declares it again before its first
  batch, after acquiring the runners' lock. An earlier runner holding that
  lock has finished by then, and no fence is declared that it would leave.
- The native path reads the fence from the validated capability inventory
  (inspect_source_schema). This replaces a second, weaker lookup, and its
  own cursor probe gives way to a flag set where the cursor is created.
- The orphaned-fence refusal now offers a verified way out besides the
  full restore: remove the declaration once qbit_prism_share_hashes is
  shown to map every legacy header. The docs give the query.
- The docs and release notes say precisely how earlier builds react: a
  pre-#582 build's first migrate still suggests recording 2, which changes
  nothing.

Tests:
- A new test plays the earlier runner: it holds the runners' lock while a
  resume's transaction commits, then finishes the backfill without
  touching capabilities. The resume declares no fence meanwhile, and the
  database starts afterwards.
- The lifecycle test watches the resume's runner declare the fence again
  while a batch waits on an open insert, before removing it with the
  cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
…e share_hash_backfill_pending capability, so recording 2 by hand cannot let one serve (#669) (#681)

* 3.x.x: fence earlier builds off a pending share-hash backfill with the share_hash_backfill_pending capability, so recording 2 by hand cannot let one serve (#669)

#582 records migration 2 only after 002's share-hash backfill. Every start
refuses the database until then, because every build requires 2. But an
earlier build that meets 3 without 2 tells the operator to record 2 by
hand once 002's objects are present, and then it would serve with legacy
headers unmapped. The docs said never to do that; nothing enforced it.

While the backfill is pending, the database now declares the capability
share_hash_backfill_pending = 1, using the standard capability mechanism:

- The migration transaction that creates the cursor declares it, once 006
  has created the capability table.
- Every resume declares it again (ON CONFLICT DO NOTHING). So a backfill a
  #663-era build started, or one whose row was deleted, is fenced by the
  next migrate before its batches start.
- The transaction that drops the cursor and records 2 removes it. It is
  the one capability native code removes, because it describes a state,
  not a format.

Every build before #669 refuses it at connect and at migrate, whatever the
migration record says. This release refuses the cursor itself, and so does
the evidence export, so recording 2 by hand unlocks nothing.

A declaration whose cursor is gone can only be left by dropping the cursor
by hand. Every migrate refuses it before any DDL, with that cause instead
of the "3 without 2, record it by hand" remedy. The connect gate and the
recovery evidence export refuse it too.

Tests:
- An earlier build's capability list refuses the fence; this build's
  accepts it.
- The evidence export's list of understood capabilities is pinned to
  NATIVE_CAPABILITIES.
- Fence lifecycle: declared with the cursor; kept when 2 is recorded by
  hand, with starts still refused; declared again by a resume after a
  hand deletion; removed with the cursor when 2 is recorded.
- A hand-dropped cursor leaves the fence, which migrate refuses; with 2
  also recorded, migrate still refuses and the start finds 13 and 17
  missing.
- A fence on a fully migrated database is refused by every start and
  migrate.
- The evidence export refuses a fence without its cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: declare a resumed backfill's fence from its runner, under the runners' lock, so an earlier runner cannot leave one behind (#669)

Codex (P1) and /code-review high on #681: a resume declared the fence in
its migration transaction, which does not take the runners' lock. A runner
of a #663-era build that was still mapping could then finish, drop the
cursor and record 2 without knowing the fence. This release's runner,
queued behind it, found 2 recorded and returned, and the orphaned fence
would have locked out a fully mapped ledger.

- The migration transaction now declares the fence only for a cursor it
  creates itself.
- A runner that resumes the backfill declares it again before its first
  batch, after acquiring the runners' lock. An earlier runner holding that
  lock has finished by then, and no fence is declared that it would leave.
- The native path reads the fence from the validated capability inventory
  (inspect_source_schema). This replaces a second, weaker lookup, and its
  own cursor probe gives way to a flag set where the cursor is created.
- The orphaned-fence refusal now offers a verified way out besides the
  full restore: remove the declaration once qbit_prism_share_hashes is
  shown to map every legacy header. The docs give the query.
- The docs and release notes say precisely how earlier builds react: a
  pre-#582 build's first migrate still suggests recording 2, which changes
  nothing.

Tests:
- A new test plays the earlier runner: it holds the runners' lock while a
  resume's transaction commits, then finishes the backfill without
  touching capabilities. The resume declares no fence meanwhile, and the
  database starts afterwards.
- The lifecycle test watches the resume's runner declare the fence again
  while a batch waits on an open insert, before removing it with the
  cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: declare the backfill fence only with its cursor, never on a resume, so it cannot meet an earlier build's runner (#669)

Codex (P1) on 4f0f004: moving a resume's declaration into the runner,
after the runners' lock, still left a race. An earlier build's migrate that
passed its capability check before the fence existed can queue for the
lock. If this release's runner declares the fence and then stops on an
error, a cancel or a restart, the queued earlier runner finishes the
backfill, drops the cursor and records 2 without removing a fence it does
not know. Every later start and migrate would then refuse the database.

The fence is now declared only by the migration transaction that creates
the cursor, never on a resume. Migrations serialize on the migration lock,
and no earlier build's migrate passes its capability check once the fence
has committed. So a fence never coexists with an earlier build's runner:
any runner an earlier build started belongs to a cursor an earlier build
created, which carries no fence. The price is that a backfill a #582 build
started stays unfenced to its end; the docs say so.

Tests:
- New: a resume of an unfenced backfill crashes mid-batch without
  declaring a fence. The test then plays the earlier runner finishing the
  backfill, and migrate and starts succeed afterwards.
- The lifecycle test sees the creation-time fence held through a resume's
  batches and removed with the cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: drop an unneeded mut from the fence lifecycle test (#669)

7671768's rewrite left the blocker transaction mutable, but it only
rolls back, and clippy -D warnings refuses that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: say the backfill fence covers only backfills started from #669 on (#669)

Codex (P2) on 7671768: the release note read as if every pending
backfill were fenced. A backfill that a #582 build started before #669
carries no declaration, and a resume does not add one, so recording 2 by
hand could still let a pre-#582 build start with legacy headers unmapped.
The note now says so, and the guide's list of how earlier builds react
says it describes a fenced backfill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: bring the fence's comments in line with its creation-only declaration (#669)

One test's doc still said a resume declares the fence from its runner,
which 7671768 removed, and the migrator's comments said a resumed
backfill is never fenced "again", which is wrong for a cursor an earlier
build created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: refuse a newer release's share_hash_backfill_pending as newer, never as an orphaned fence to delete (#669)

Codex (P2) on c20fdf2: on migrate's native path, the orphaned-fence
check matched the capability by name and ran before
refuse_newer_native_database. A newer release that declares
share_hash_backfill_pending at another value, with no cursor, was told
its declaration was an orphaned fence = 1. The remedy offered was to
delete it after checking only the old share mapping, which could remove
that release's own safety declaration instead of saying "upgrade the
server".

The native path now validates capability rows before it reads the
record, as connect does. Then the orphan check, and the 3-without-2
check after it, only ever see values this release understands. The
orphan check also matches value 1 exactly, here and at connect, where
refuse_unknown_capabilities already ran first. The evidence export
already raised on any other value inside its loop, before its own
orphan check.

Tests: both cursorless-fence tests now also raise the fence to 2. The
migrated database is refused at start and at migrate as a newer
release's. In the 3-without-2 state, migrate refuses it the same way,
naming neither the orphan nor the record. Both fail on c20fdf2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: qualify the guide's capability narrative for backfills a #582 build started (#669)

The narrative said every earlier build is refused for as long as legacy
headers are unmapped. That holds only for a backfill this release started:
one a #582 build started carries no declaration, as the backfill section
and the release note (37b56cc) already say.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: keep migrate's capability checks in their order, matching only value 1 as an orphaned fence (#669)

e05038c moved refuse_newer_native_database ahead of
refuse_undeclared_native_database and the record check, so the fence's
name at a newer release's value would be refused as newer. That broke
offer_lifecycle's
migrated_database_without_its_offer_lifecycle_declaration_is_refused_at_connect_and_at_migrate
(CI shard 2). An edited candidate_offer_lifecycle = 0 must be refused as
an edited declaration, before the newer check, as connect refuses it, and
it was refused as "a newer PRISM release wrote this database".

The order is back as it was. The orphaned-fence check still matches
value 1 only, which is Codex's other remedy: at another value the name is
a newer release's declaration, refused as any newer capability is and
never offered for deletion. A migrated database gets "upgrade the
server". With 3 recorded and not 2, the record's refusal comes first, as
it does for any newer capability, and the next migrate after 2 is
recorded refuses the value as newer.

The cursorless-fence test now probes value 2 in both record states;
set_fence replaces the inline updates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: leave a newer release's backfill fence, cursor and record to it, reading the fence again before recording 2 (#669)

Codex (P2) on 1d3843b: the runner maps between holds of the migration
lock, so a newer release's migrate can commit meanwhile. If that release
declares share_hash_backfill_pending at its own value, the final
transaction deleted the declaration by name, dropped the cursor and
recorded 2, defeating that release's fence.

The final transaction now reads the fence again under the migration
lock. Absent (a cursor an earlier build created) or 1, it records 2 as
before. At any other value it refuses, naming the value, and leaves the
cursor, the declaration and the record to the newer release; this
release's next migrate refuses the value as newer.

Test: a_runner_leaves_a_newer_releases_fence_with_its_cursor_and_record
holds a resume's batch on an open insert, declares the fence at 2 as a
newer release would, and then requires the runner to refuse with the
cursor, the value and the record untouched. It fails on 1d3843b. The
guide's fence section and its refusals table describe the check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: rewrap a fence test comment after 024 (#669)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
#551, #553, #554, #582)

The file is 3.x.x's copy byte for byte again, as of 3.x.x c95febb; the
last change to it there is bd1ddeb (#663). Since 1932cb3 (#597), five
3.x.x changes landed in it:

- #552 (#613): the `bridging` job runs the short plan on the fake and
  the real node on one runner, nightly, on the run-load label and on a
  dispatch with the new `bridging` input.
- #551 (#606): every preset job builds a trend row; on a schedule the
  `evidence` job (the one job with `contents: write`) appends the rows to
  the orphan `ci-evidence` branch, applies the report-only regression
  rule, promotes the soak's and flagged runs' bundles to the rolling
  `ci-evidence/YYYY-MM` pre-release, and keeps one
  `prism-load-regression` issue. PR and dispatch runs get the read-only
  `evidence-preview` instead.
- #553 (#618): the live nightly and weekly lists gain the chain-event
  scenarios under 2,000 sessions; the workflow's comments say so.
- #554 (#635): the run job installs fuse2fs and fuse3 for a preset whose
  faults fill the WAL volume (faults-long-real-node, Saturday).
- #582 (#663): comment only.

Without this, main's scheduled copy (#595) still has no qbitd install
step, so every `--node qbitd` preset fails with "--node qbitd needs
--qbitd-bin or QBITD_BIN" (scheduled runs 37188928798 and 37287515779).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Anatolie added a commit that referenced this pull request Oct 16, 2026
 (#590, #596, #588, #597, #552, #551, #553, #554) (#601)

* main: sync the PRISM load-harness nightly workflow from 3.x.x (#590, #596)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* main: sync the PRISM load-harness nightly workflow from 3.x.x (#590, #596, #588, #597)

Adds #588's Saturday 5.5 h soak schedule and its live-nightly step that runs every listed test binary, so qbit-prism-load::soak_smoke runs beside the live_regtest variants, and #597's L6 shipped-images lane on the Sunday schedule. Byte-identical to 3.x.x at 1932cb3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* main: re-sync the PRISM load-harness nightly workflow from 3.x.x (#552, #551, #553, #554, #582)

The file is 3.x.x's copy byte for byte again, as of 3.x.x c95febb; the
last change to it there is bd1ddeb (#663). Since 1932cb3 (#597), five
3.x.x changes landed in it:

- #552 (#613): the `bridging` job runs the short plan on the fake and
  the real node on one runner, nightly, on the run-load label and on a
  dispatch with the new `bridging` input.
- #551 (#606): every preset job builds a trend row; on a schedule the
  `evidence` job (the one job with `contents: write`) appends the rows to
  the orphan `ci-evidence` branch, applies the report-only regression
  rule, promotes the soak's and flagged runs' bundles to the rolling
  `ci-evidence/YYYY-MM` pre-release, and keeps one
  `prism-load-regression` issue. PR and dispatch runs get the read-only
  `evidence-preview` instead.
- #553 (#618): the live nightly and weekly lists gain the chain-event
  scenarios under 2,000 sessions; the workflow's comments say so.
- #554 (#635): the run job installs fuse2fs and fuse3 for a preset whose
  faults fill the WAL volume (faults-long-real-node, Saturday).
- #582 (#663): comment only.

Without this, main's scheduled copy (#595) still has no qbitd install
step, so every `--node qbitd` preset fails with "--node qbitd needs
--qbitd-bin or QBITD_BIN" (scheduled runs 37188928798 and 37287515779).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Robert Clarke <[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