Skip to content

3.x.x: Add the qbit-prism-load Stratum-to-PostgreSQL load harness and dense-cadence scenario - #342

Merged
kiwidream merged 92 commits into
3.x.xfrom
stratum-load-harness
Sep 16, 2026
Merged

kiwidream merged 92 commits into
3.x.xfrom
stratum-load-harness

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Part of #271.

Summary

Nothing on 3.x.x drives the native server over real Stratum sockets, and nothing produces the qbit-prism-capacity-evidence/v2 artifact that qbit-prism-server capacity-evidence validates (#303). This PR adds crates/qbit-prism-load, a separate binary. It needs no subcommand in tools.rs and changes no production code.

It:

  • launches real qbit-prism-server run children, 1, 2 or 4 frontends, against a PostgreSQL 16 primary and one standby that it manages;
    • the standby is asynchronous by default, following decision D3, or synchronous through the primary-side flip;
  • serves a fake node:
    • fixed bits 1e7fffff, so ordinary shares never meet the network target;
    • strictly increasing chainwork and a real height-to-hash map;
    • submitblock and waitfornewblock;
  • drives up to 2,000 Stratum sessions that build headers with the server's own codec;
    • they discard unscheduled block solutions;
    • they submit own blocks only when the harness schedules one;
  • measures, per phase:
    • client ACK p50, p99 and max;
    • advisory-lock waits sampled from pg_locks: both ORDER_LOCK, which every share append takes, and SETTLEMENT_LOCK, which the rebuild after a landing takes first. Each is attributed to a frontend by application_name, reports foreign waiters and holders separately, and is cross-checked against pg_stat_statements;
    • per-frontend CPU and RSS;
    • reconnects;
    • time to usable work after a new tip;
    • rejections by (code, reason_id, message);
  • reconciles every offered, acknowledged and committed share ID against PostgreSQL, exactly, with canonical digests;
  • writes the capacity-evidence artifact, a versioned side report and a database profile, validates the artifact against the options it ran with, and prints the equivalent capacity-evidence command.

Honest values in the artifact

  • coordinator_image_digest is sha256: followed by the sha256 of the server binary that ran. The side report labels it as a binary digest, not an OCI image digest.
  • database_profile_sha256 is the sha256 of the shipped database-profile.json. That file holds the SHOW ALL output, the replication rows, the proxy settings, the host and the redacted frontend environments.
  • Three configuration keys are unread. capacity-evidence requires PRISM_SHARE_COMMIT_BATCH_SIZE, …_LINGER_MILLISECONDS and PRISM_STRATUM_VARDIFF_IDLE_SWEEP_SECONDS, but the native runtime doesn't read them (3.x.x: Close the configuration plumbing gaps and harden the container posture #288). The artifact records the true behaviour (batch 1, linger 0, which means one share per transaction), and the side report flags all three.

Exit codes

Code Meaning
0 Completed, reconciliation exact.
3 Blocked: a frontend refused the window size. The refusal text is recorded.
4 An acknowledged share is missing from PostgreSQL: a durability loss.
5 ACK/commit divergence: a share the server rejected with ledger-confirmation-failed is in the ledger (#324).
7 Harness-bug rejections.

What it found (one 8-vCPU Haswell VM, PostgreSQL 16.15, release builds; numbers are host-specific)

All on one 8-vCPU Haswell VM, 22.9 GiB, no swap, PostgreSQL 16.15 managed by the harness, release builds on Rust 1.98.1. Rates vary about tenfold between hosts, so these numbers belong to this one.

Run Frontends Sessions Window Standby Result
A 2 200 20k async Exit 5. Steady state 50/s at ACK p50 3.6 ms, p99 11.8 ms. Under a 10 ms database delay the lane fell to 5.6/s of 41/s offered, ACK p99 23.9 s, 31 backends queued on ORDER_LOCK, and two #324 divergences appeared.
B 1 200 20k async Exit 0, reconciliation exact, no divergence.
C 4 200 20k sync Exit 0, reconciliation exact. sync_state='sync' confirmed at every phase boundary. Time to usable work rose to 4.9–5.6 s, with four frontends each rebuilding a 20k-share bundle.
D 2 20 2k async Exit 0 and the artifact validates: 3.98 shares/s against a forecast of 1, ACK p50 4.4 ms, p99 464 ms, 717 committed.
K 2 50 2k async Mid-flight kill. 25 submits were outstanding at the SIGKILL; all 25 were re-offered, all refused as stale, and none reached the ledger. Nothing was lost.
S 2 50 2k async One scheduled own block, accepted by the node. 18 unscheduled block solutions were found and discarded, never submitted.

Across every run, missing_acknowledged_share_ids was 0 and the only unexpected rows were the #324 divergences.

  • 3.x.x: A share-commit timeout can reject a share the ledger then credits #324. Under a 10 ms one-way database delay, the 15 s commit timeout at coordinator.rs:1754 rejected shares that PostgreSQL then committed. It reproduced twice, and nothing was lost.
  • Stale readiness. Under the same delay, frontends refused shares with current chain state is unavailable, because the readiness poll went stale behind the blocked refresh loop. Those shares count as offered and not acknowledged.
  • The 2× gate. capacity-evidence requires every phase, including slow_database, to sustain twice the forecast. The native path serializes every share on ORDER_LOCK, so an artifact validates only at very low forecasts. A 1 share/s forecast validated at 3.98 shares/s, which is the demonstration. At D1's 2,000 shares/s, the verdict is a refusal, recorded with its reason.

Dense cadence

--cadence dense lands own blocks on #224's shape: 9 s single gaps and 18–20 s pairs, by default 9,19,9,18,20. For each landing it records the payout-revision bumps, sampled from the database every 25 ms, and per frontend how long and how many shares were rejected while the frontend rebuilt.

new payout work is pending never fires. Across 88 landings in eight runs, every rebuild-pending rejection was new tip work is pending: the coordinator checks the tip before the revision, and a landing moves both in one rebuild. So the budget #291 needs is the combined rebuild-pending window:

Frontends Combined window p50 / p99 Rejections per landing, p50 / p99 Lost valid work
1 1,441 / 2,219 ms 73 / 112 1,150 shares
2 2,399 / 3,437 ms 62 / 87 1,719 shares
4 4,720 / 7,120 ms 64 / 90 2,941 shares

None of those shares reached PostgreSQL, so they are lost miner work rather than a durability problem. At four frontends one landing in fifteen was refused outright, because the previous rebuild outlasted a 9 s gap: on this host, #224's cadence is at the edge with four frontends.

With no landings the section reports zeros, null percentiles with a reason, and no windows.

Sampling both locks matters: in a four-frontend dense run, SETTLEMENT_LOCK carried 268 waiter-seconds against ORDER_LOCK's 504 from the same polls, so about a third of the queueing behind these windows is on the lock the rebuild itself takes.

Blocked sizes

The harness records such a run as blocked, exit 3, with the refusal text. The full-size measurements follow in the results PR.

Testing

On the 8-vCPU VM, with an independent adversarial review of each half:

  • cargo +1.98.1 fmt --all -- --check, clippy --locked -p qbit-prism-load --all-targets --no-deps -- -D warnings and test --locked -p qbit-prism-load are clean, with 47 database-free tests.
  • cargo test --locked --workspace --all-targets --no-run, scripts/check_version_skew.py and scripts/check_gate_env_reads.py pass. Cargo.lock gains one package and no version changes.
  • The artifact validates, then fails once any required field, any phase, reconnect_events, a configuration key or a subject key is removed, each refusal naming what is missing.
  • Counts and digests were recomputed independently from PostgreSQL by the reviewer and matched, including all 25 mid-flight-kill shares.
  • A foreign process holding ORDER_LOCK is reported separately, not billed to the frontends.
  • Interrupts and failed start-ups leave no cluster, frontend or temporary directory behind.
  • Two independent adversarial reviews, one per half, drove twelve fixes. The first found a profile digest that never matched the file it named, an invisible foreign lock holder, a leaked temporary directory, an unchecked --pg-bin-dir and a README with the wrong exit code. The second found that the dense phase measured only one of the two locks involved, that lost work was verified against the database only for attributed rejections, and five labelling faults: partial blindness reported as "not blind", counts labelled in milliseconds, a summary that dropped its approximation label, and bumps not meaning what its own definition said.

On an Apple M5 Max, with the pinned toolchain: format, clippy with -D warnings and the 47 tests are clean on an independent machine and toolchain install.

Not in this PR

  • The measurement matrix and the results document; those follow as their own PR.
  • Any change to production code or metrics.

The metric gaps found along the way go to #278 and #279:

  • the lock-wait family has no producer;
  • there is no CPU series;
  • the ACK histogram's buckets are coarse.

🤖 Generated with Claude Code


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

kiwidream and others added 29 commits September 14, 2026 10:31
Adds a new workspace crate that drives real Stratum sockets against real
`qbit-prism-server run` child processes and produces the
`qbit-prism-capacity-evidence/v2` artifact nothing produced before (#303),
plus a side report carrying everything the artifact's schema cannot say.

The crate owns:

- a fake qbit node with a real height-to-hash map, a hash-to-parent map,
  strictly increasing chainwork, `submitblock` and `waitfornewblock`, and
  an in-process way to mint an external tip. It serves `1e7fffff` template
  bits: the stock `207fffff` makes every valid share a block, because the
  codec caps the share target at the network target;
- window arithmetic that solves for the diff-1 share difficulty whose
  scaled weight makes the payout window exactly the requested length, and
  asserts the result rather than assuming it;
- a production-shaped window seed adapted from the #264 gate fixture,
  parameterised by the network difficulty and the live share difficulty;
- managed PostgreSQL: a primary plus one streaming standby, with the
  physical slot, an explicit `application_name`, the D3 synchronous flip
  and a teardown that runs on every exit path;
- an in-harness TCP delay proxy between the frontends and PostgreSQL;
- Stratum client sessions whose header recipe reproduces the server's
  `codec::Job::assemble_submission` byte for byte, so a share identifier
  computed before the submit is the identifier the ledger stores;
- measurement: client ACK percentiles, server histogram bucket deltas,
  ORDER_LOCK wait sampling from `pg_locks.waitstart`, per-frontend CPU and
  RSS, reconnect statistics, time to usable work and a rejection census;
- exact reconciliation with a documented canonical share-identifier digest.

Unknown, stale and failed measurements stay distinct from zero, and the
three configuration keys the native runtime does not read (#288) are
recorded as unread rather than presented as tuning controls.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
Adds the crate README: prerequisites, every flag, the D1 plan, the outputs
and their schemas, how to validate the artifact, the honest-value notes,
measurement hygiene, and the sizes that are blocked until #273 and #265.

Two fixes a first end-to-end run found:

- the run now quiesces every session and waits for outstanding submits to
  settle before it closes the sockets. Stopping with submits in flight
  manufactured indeterminate shares, two of which had already committed,
  and the run then reported a durability finding it had created itself.
  Offers a paused session will never send release their outstanding slot,
  so the drain cannot wait for work that is not coming;
- the side report now carries the ACK p99 the artifact phases actually
  reached and the limit that would admit it, beside the forecast that
  would admit the slowest phase's rate.

The ORDER_LOCK sampling predicate is derived from the hex key rather than
typed in decimal, and the report prints the derivation: the high half of
0x505249534d000002 is 0x50524953, which is 1347570003.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The first two-frontend run at a 20,000-share window showed what a 10 ms
one-way database delay does: the refresh loop blocks, each frontend's
readiness poll goes stale behind it, and 1,873 submits come back with
`current chain state is unavailable`, with another 167 hitting the
share-commit timeout.

Those refusals were being excluded from `offered_valid_shares` alongside
the races the server is entitled to lose, which let the slow_database
phase report offered == acknowledged == 399 and look clean while 2,040
submits had failed. Only the transient classes are excluded now — a stale
job after a tip change or a payout-revision bump, an unknown or retired
job, a closed pool — and each of those is a share PostgreSQL never saw, so
reconciliation is untouched.

A backend refusal is a capacity result, not a harness defect, so it still
does not make the run exit non-zero; it simply makes the artifact honestly
invalid for that phase. The side report now carries the rejected-valid and
harness-bug counts per phase, and the README says which gates bind under
delay and what each would need.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
A drained frontend restart pauses that frontend's sessions, and any offer
the scheduler had already placed on a paused session is discarded rather
than sent. The two-frontend run showed the gap as one dispatched share
that appears in no phase's offered set. The sessions now report each
discarded offer, and the side report carries the count, so `dispatched`
reconciles against `offered` without a reader having to guess.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
Two back-to-back two-frontend runs at a 20,000-share window found the same
thing under a 10 ms one-way database delay: two shares per run that
PostgreSQL holds and that the server had already refused with
`ledger-confirmation-failed`. Nothing acknowledged was ever lost -
`missing_acknowledged_share_ids` was 0 in every phase of both runs - so the
gap runs the other way.

The mechanism is in the coordinator: the append is wrapped in
`tokio::time::timeout(share_commit_timeout, save)`, and when that deadline
fires the sqlx future is dropped mid-COMMIT, which PostgreSQL may still
complete. The share is then credited in the payout window while its miner
is told it was not confirmed.

That is not the same failure as credited work disappearing, so the harness
no longer reports them as one thing:

- an acknowledged share PostgreSQL does not hold, or a committed share
  nothing explains, stays a durability loss and exits 4;
- a share PostgreSQL holds that the server refused with
  `ledger-confirmation-failed` is an ACK/commit divergence and exits 5,
  listed under `ack_commit_divergence` with its phase, frontend, session,
  send-to-response time and the commit deadline it crossed;
- harness-bug rejections move to exit 7.

Divergent shares stay counted in `unexpected_committed_share_ids` and in
`rejected_valid_shares`, so the artifact is honestly invalid for the phase
and cannot hide them.

Also from the coordinator's review of the ORDER_LOCK sampler: the lock is
database-wide, so each frontend now connects with
`application_name=load-fe-<i>` and the sampler attributes waiters by it,
verifying against `pg_stat_activity` that the driver really carried the
name rather than assuming it. Waiters that are not this run's frontends
are reported separately as foreign, and the sampling intervals are bounded
above as well as below.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
`SHOW server_version` returns `16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)` on
Ubuntu, and the harness printed it unquoted, so pasting the command it told
the reader to run produced a bash syntax error rather than a verdict. Every
value in the printed command is now quoted when it needs to be, and a test
parses the rendered command with `bash -n` to prove a shell accepts it.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
A scheduled block and a re-offer both insert a pending submit, and both
responses go through the path that releases an outstanding slot, but
neither took a slot first. The counter is unsigned, so the first such
response would have wrapped it and left that session looking permanently
full to the scheduler. Both now take a slot and give it back on a write
failure, and a re-offer whose write fails no longer leaves a pending entry
behind that a later response id could match.

Found by review, before either code path had run under load.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
`--external-tips` mints during warm-up, so `--warmup-seconds 0` leaves the
time-to-usable-work section empty rather than zero, and a scheduled block
is followed by a burst of payout-revision rejections on every frontend.
Both are now in the flag table.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The decision that separates an ACK/commit divergence from a durability
loss, and the decision about what belongs in a phase's offered set, were
only exercised end to end by a live run. Both are now pure functions with
their own tests: only `ledger-confirmation-failed` makes a committed share
a divergence, a committed row the harness never offered is a loss, and the
offered set keeps every backend refusal, harness bug and lost response
while excluding only the races the server was entitled to lose.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The shared test-gate variables belong to the gate crate, and
`scripts/check_gate_env_reads.py` fails on a second reader of one, so the
harness takes its own `QBIT_PRISM_LOAD_PG_BIN_DIR` before falling back to
`pg_config --bindir`. A test pins the name and asserts it is none of the
shared ones.

The crate manifest now matches the others: `rust-version.workspace = true`
alongside `version.workspace = true`, with edition 2021, MIT and
`publish = false` unchanged. The base predates #322, which is what adds
`rust-version` to `[workspace.package]`, so this branch adds it there too
at the pinned 1.98.1; #322 already carries that line on 3.x.x and the
integration should keep its own.

Toolchain 1.98.1 found one new lint in this crate, `chunks_exact_to_as_chunks`
on the word swap, now written as `as_chunks_mut::<4>().0`.

The operator's decision is recorded where a reader will meet it: the
README's ACK/commit divergence section, its exit-code table and the side
report's own section all cite #324, and so does the evidence note.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The first mid-flight-kill run reported zero indeterminate shares, because
with no database delay an acknowledgement takes about four milliseconds:
at twenty shares a second across fifty sessions, almost nothing is in
flight at any instant and the SIGKILL tore down an idle socket.

The phase now runs under the same one-way proxy delay as `slow_database`,
which holds submits open long enough for the kill to mean something, and
the kill waits for the target frontend to actually be holding work before
it fires. The report carries `submits_outstanding_at_kill` so a reader can
see whether the scenario exercised at all rather than reading an empty
list as a clean result.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
#271's sixth acceptance criterion asks what a payout-revision bump costs
every frontend when own blocks land on #224's shape: about 9 s apart, and
in 18-20 s pairs. `--cadence dense` adds a side phase that lands them on
that pattern and measures the cost three ways, per landing and per
frontend.

The authoritative list of bumps comes from the database, not from a
rejection: the harness samples `payout_revision` and `clock_timestamp()`
out of the singleton `qbit_prism_cluster` row every 25 ms on its side
pool, outside the frontends' path and outside the delay proxy, and records
every change on both clocks. One landing can cause more than one bump --
the chainwork increase at the new tip in `ledger/window.rs`, then
candidate confirmation in `ledger/blocks.rs` -- so the report counts them
rather than assuming.

`coordinator.rs` checks the observed tip before the payout revision, which
is why W2's one scheduled block produced `new tip work is pending` and not
`new payout work is pending`. The two windows are therefore reported
apart, with a combined window beside them, and it is the combined one that
#291 should budget against.

Time to new-tip work is the run's existing definition restricted to one
frontend's sessions. Time to new-revision work cannot be exact: the wire
carries no payout revision, so the first `clean_jobs=true` notify at or
after the bump stands in for the first job built at the new revision, and
every field that uses it says so.

Attribution is total. A landing's span runs from its own pool tip change
to the next landing's, so every rebuild-pending rejection and every bump
belongs to exactly one landing or to `unattributed`, and both counts are
reconciled in the report. A landing the session could not produce, one the
frontend rejected and one the node rejected each get their own entry. A
run with no landing reports `landings: 0` and `bumps: 0` with the reason
and no windows, and the budget proposal is null rather than zero.

The blocks are matched to the node by hash, not by time: the part of a
share identifier after the colon is the header's display hash, which is
exactly what the fake node records for `submitblock`.

The gap pattern and the phase length are checked against each other at the
entry boundary, because a pattern that cannot hold ten landings measures
nothing. With `--cadence dense`, `--scheduled-blocks` becomes the dense
phase's landing budget and `steady_state` schedules none, so the budget is
not spent before the phase that measures it; without it, nothing about a
run changes, and the capacity-evidence artifact is untouched either way.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The report builder is a pure function over already-collected records, so
the parts that decide what a number means are testable without a database.

Three tests cover them: the gap generator repeats cyclically, starts at the
lead-in and reserves the measurement tail, and its entry validation refuses
a gap below the floor, a non-finite one, an empty field and a phase too
short for ten landings; synthetic rejections and bumps land on the right
landing, with the ones before the first landing counted as unattributed
rather than dropped, and a landing the session never produced keeping its
error text; and a run with no landing reports zeros, a reason and no
percentile.

A fourth asserts the wiring: the dense phase is a side phase with no proxy
delay after `slow_database`, a run without `--cadence dense` does not grow
one, and the artifact's phases are the same either way.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The flag table, the phase list and the outputs section gain the new phase
and its four flags, and a section of its own says where the bumps come
from, why the tip and payout windows are reported apart, which of the two
times is an approximation and why, what "lost valid work" counts, and what
the report says when nothing landed.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
`subject.database_profile_sha256` was taken over the canonical JSON string
while the file was written with a trailing newline appended, so the two
never agreed and `sha256sum database-profile.json` disagreed with the
artifact in every bundle the harness has produced. A mismatched digest in
an evidence bundle honestly reads as corruption or tampering, and nothing
inside the harness could catch it: the self-check and
`--expect-database-profile-sha256` both compare the in-memory digest with
itself.

The document is now written through `profile::write_document`, which writes
exactly the bytes that were digested and says why nothing may be appended.
Digesting the file's bytes instead would have made the digest a function of
the serializer, which that module exists to avoid.

The regression test writes the profile, reads the file back and asserts
that the SHA-256 of its bytes is the digest the artifact names, that the
last byte is not a newline, and that the file still parses. The README's
claim now says the digest is over the file's exact bytes and that
`sha256sum` is the value the artifact names.

Found by the adversarial review of W2 (F1).

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The honest-values section still said the harness-bug classes exit 5, which
was true before the ACK/commit divergence was split into its own class and
took that code. The exit-code table and `run.rs` both say 7.

Found by the adversarial review of W2 (F4).

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
Every other input was range-checked in `Args::validate`; `--pg-bin-dir` was
not, so a typo surfaced as `running initdb: No such file or directory` long
after the output directory and the temporary cluster root had been created,
and named neither the flag that was wrong nor what was missing.

`cluster::verify_bin_dir` checks that the resolved directory exists and
holds `initdb`, `pg_ctl` and `pg_basebackup`, and `run::execute` resolves
and checks it immediately after `Args::validate`, before it creates
anything. A `--database-url` run needs none of those binaries and is not
asked for them, which is also why the check is not in `Args::validate`
itself: it would make the crate's own unit tests depend on a PostgreSQL
installation, and they stay database-free.

The test covers the four answers: a directory that does not exist, one with
no binaries, one with all three, and one missing a single binary.

Found by the adversarial review of W2 (F5).

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
`create_dir_all` ran before the `ManagedPostgres` whose `Drop` removes the
root existed, so every `?` in between -- reading the current user,
`initdb`, allocating a port, starting the primary -- returned with
`/tmp/prism-load-<uuid>` still on disk. An operator iterating on flags
accumulated empty directories, and a failure after `initdb` succeeded left
a whole data directory behind.

`TempRoot` is created the instant the directory is, honours
`--keep-artifacts` and is moved into `ManagedPostgres`, which no longer
removes the root itself: the guard drops after `stop` returns, so the data
directory is never removed under a live server. The whole window is closed
without a second copy of the cleanup.

The test writes a file into the root and asserts nothing survives the
guard, and that `--keep-artifacts` keeps it.

Found by the adversarial review of W2 (F3).

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The sampler selected only ungranted rows, so a process that *held*
ORDER_LOCK was invisible to every number in the section. That is exactly
what a foreign stall looks like: the holder blocks every frontend, the
frontends queue up as waiters and are correctly recognised as this run's
own, and the report then billed the whole stall to them while asserting
`foreign_waiter_samples: 0`. The adversarial review held the lock for 3.02 s
from a separate `psql` and watched `waiter_seconds_estimate` inflate 19x
with nothing foreign reported anywhere.

The query now selects `l.granted` and keeps granted rows, and
`split_lock_rows` splits one sample four ways: this run's waiters, this
run's holders, foreign waiters and foreign holders. Every existing waiter
number -- `max_waiters`, `mean_waiters`, `waiter_seconds_estimate`, the
episode count and the longest observed wait -- still comes from this run's
ungranted rows alone, so nothing changes meaning; the granted rows are new
information beside them. A frontend holding the lock is the normal case and
is in no foreign counter.

Beside the waiter fields there are now `foreign_holder_samples`,
`foreign_holder_application_names` and `foreign_holder_seconds_estimate`,
and one `foreign_contention_observed` so a reader does not have to notice a
zero in the right field. It is `null`, not `false`, when the sampler could
not attribute rows at all: unknown is not the absence of a problem.

The split is a pure function and has its own test, including the
no-attribution case where nothing can be called foreign. The README now
describes holders and waiters as the different events they are.

Found by the adversarial review of W2 (F2).

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
The default gap pattern needs a 150 s phase to place ten landings, not the
170 s the README said. The number the code computes is the one in the
refusal message, which a reader is more likely to meet than this sentence,
so the sentence now points at it.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
…dum)

Two ways the ORDER_LOCK sampler could still be wrong about what it saw.

The inner join to `pg_stat_activity` dropped any lock row whose backend the
sampler's role cannot read, so such a row was invisible rather than
foreign. It is now a left join, and a row with no readable activity counts
as foreign: nothing about it can be shown to belong to this run, and
counting it as one of this run's frontends is the direction that hides a
stall. That holds even with no attribution at all, where every other row
counts as ours. In the foreign name lists it appears as
`(activity row not visible to the sampler's role)` rather than as an empty
`application_name`.

The server timestamp was read out of the first returned row, so a poll that
found no lock had no server clock and fell back to the harness's own
`Utc::now()` -- one sample, two clocks. `clock_timestamp()` now comes from a
one-row outer source left-joined to the locks, so every poll carries it,
including a poll that finds nothing. If it is ever missing the sampler
records a failure instead of substituting its own clock.

Rows that are this run's own and ungranted are unchanged, so every waiter
figure keeps its meaning. The split's test covers the unreadable row in
both the attributed and the unattributed case.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
…pend takes (F1)

The dense-cadence phase exists to measure the rebuild after a landing, and the
rebuild path takes SETTLEMENT_LOCK (0x505249534d000003) first and ORDER_LOCK
second -- observe_chain_view, the job build and candidate confirmation or
abandonment all do. The sampler watched ORDER_LOCK alone, so in an adversarial
run 37.3% of this run's ungranted PRISM advisory-lock samples in the dense
phase were invisible to every reported number, and a reader sizing #291's soak
budget off waiter_seconds_estimate was reading part of the queueing with no way
to tell which part.

The sampler now selects both locks in one poll, tags each row with its objid,
and summarizes them apart: each phase carries a settlement_lock block beside
order_lock with the same shape and the same own/foreign split. Because one poll
carries both, the two blocks cover exactly the same instants and share a
samples count and a sampler cost, which the definitions say. Every existing
order_lock key keeps its name and its meaning; the blocks gain taken_by, which
names the server path that takes the lock, so a block says what it measures
rather than leaving it to be inferred from the name.

The dense section's definitions gain advisory_locks_sampled: which locks are
sampled, which path takes each, which are not sampled and why, and where the
blocks live. MIGRATION_LOCK and CPFP_FUNDING_LOCK stay unsampled -- neither is
on the append or rebuild path this phase measures.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
…s (F2)

lost_total and lost_in_postgres were accumulated inside the per-landing,
per-frontend loop, so they covered exactly the rejections a landing's span
owns. A rebuild-pending rejection that fell inside no span was reported in
rejection_attribution.unattributed and then silently left the lost-work census
-- and was never looked up in this run's committed share identifiers.

That is the one case the cross-check exists for. A landing whose pool tip
change is missing -- accepted_without_node_submission, a tip record lost to a
frontend restart, a block the node recorded late -- leaves its rejections
unattributed, so a lost share that really is in qbit_share_ledger would have
been reported as shares_found_in_postgres: 0. The check read as a clean pass in
exactly the situation that would make it fail.

lost_valid_work now counts every rebuild-pending rejection in the phase and
publishes the split -- shares, shares_attributed, shares_unattributed -- with
shares_found_in_postgres checked over all of them. The per-landing,
per-frontend lost_valid_shares tables are untouched and still sum to
shares_attributed.

The attribution test is extended to arm the case: its unattributed rejection,
and only it, is placed in the committed set, so the test asserts shares == 5,
shares_unattributed == 1 and shares_found_in_postgres == 1 naming the share.
Before this change that last number was 0.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
blind() was `baseline.is_none()`, so it could only fire for a sampler that
never read anything. A sampler whose first read succeeded and whose next
thousand failed -- the side pool loses its connection, the primary restarts,
the pool is exhausted -- reported blind: false, blind_reason: null and
changes_observed: 0 beside an error count in the thousands. The one boolean a
reader is invited to trust to tell "observed zero" from "observed nothing" said
"observed zero", which is the misreading the flag exists to prevent.

blind() is now also true when no change was observed and errors occurred, and
blind_reason names which of the two cases it is rather than repeating one
sentence for both. Errors beside observed changes stay non-blind: the sampler
did see the revision move.

Beside samples and errors the section now reports coverage -- samples over
samples plus errors, null rather than 0 when the sampler never ticked -- so a
sampler that watched 3% of the phase is visible as such whatever blind says
(EP-OBSERVABILITY).

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
Time to new-revision work is an approximation -- mining.notify carries no
payout revision, so the first clean_jobs notify at or after the bump stands in
for it -- and it was labelled in two of the three places it appears. The
per-landing, per-frontend tables carry new_revision_work_approximation beside
the number, and definitions carries it under time_to_new_revision_work. The
four summaries.overall and summaries.per_frontend[] fields carried nothing.

Those are the numbers people quote: the headline tables in the run reports
carry a "time to new-revision work ms" column and it comes from the summaries.
Quoted from there, an approximation built on a clean_jobs proxy reads as a
measured time to the first job at the new payout revision, which is the one
thing the Stratum wire cannot tell you.

The label is carried into the summarised objects rather than adding definitions
entries keyed on the summary names. Both fixes were acceptable; this one puts
the label beside the number, so it survives a reader copying the object out,
while a definitions entry only helps a reader who goes looking -- and the
finding was that readers quote the summary and do not go looking.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
measure::summarize hard-coded unit: "milliseconds", and five of the dense
section's distributions are counts of shares. They shipped as

  "combined_rebuild_pending_rejections_per_landing": {
    "clock": "counts, not milliseconds; one sample per landing",
    "unit": "milliseconds", "p50": 61.0, "p99": 85.0, "max": 85.0 }

with the clock string apologising for the unit rather than the unit being
right. A consumer generic over the summary shape -- a dashboard, a diff of two
runs -- reads `unit` and renders 85 discarded shares as "85 ms"; it does not
look at a clock field. EP-OBSERVABILITY asks that every number carry its unit,
and here one was carried and was wrong, which is worse than absent.

summarize now takes the unit. measure::MILLISECONDS and measure::COUNT name the
two in use; the five count call sites pass COUNT through a count_summary helper
and everything else passes MILLISECONDS. COUNT_CLOCK drops the apology and
names the clock again: one sample per landing and frontend, counting rejections
stamped on the harness monotonic clock.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
definitions.bump is "an observed change of qbit_prism_cluster.payout_revision",
and the top-level bumps key published attributed_bumps -- the subset a landing's
span owns. The crate's own test made the divergence concrete: bumps 3 while
bump_records held 4 and bump_attribution.unattributed was 1.

The failure is a no-landing run in which the revision moves anyway -- an
operator touching the cluster, a migration, a second harness. It reported
landings: 0 and bumps: 0, which the README presents as the honest no-landing
output, while changes_observed and bump_attribution.unattributed both said
otherwise two keys away. Nothing was hidden, but the headline number meant
something other than the word next to it.

bumps is now revisions.changes.len(), equal to revision_sampler.changes_observed,
and bump_attribution carries the split -- it gains observed so the three
reconcile in one place. definitions.bump says which key is which, and
unknown_is_not_zero no longer claims a no-landing run reports bumps 0.

The test that pinned the old meaning now asserts bumps == 4 ==
changes_observed with attributed 3 / unattributed 1, and the no-landing test
gains the case the finding named: nothing landed, the revision moved twice,
bumps 2, both unattributed.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
…d (F7)

landings and windows_available were derived from the `landed` tally, while
resolve grants a landing its attribution span whenever its own pool tip change
is present -- regardless of outcome. A landing whose tip moved but whose
submitblock record is missing falls to AcceptedWithoutNodeSubmission and still
receives a span, and therefore a full per-frontend window table and a
contribution to summaries. If that were the only such landing the section would
have reported landings: 0, windows_available: false and a reason saying every
attempt failed, while landing_records[].frontends and summaries.overall carried
real windows and proposed_budget_for_issue_291 carried a real p99.

Both now count the spans that were actually created, and the no-landing reason
keys on the same number, so "a window exists" and "a window is reported as
existing" cannot disagree. landing_outcomes.landed is unchanged and still
reported one key away, so the two can be read against each other, and
definitions.landings says which is which.

Part of #271

Co-Authored-By: Claude Opus 5 <[email protected]>
Brings the load harness onto the current 3.x.x, which carries #322 (the
shared integration gate and the required fmt, clippy and cargo-deny jobs) and
#316. The only conflict was the root Cargo.toml: 3.x.x's file is kept,
including its commented rust-version pin, and the qbit-prism-load member is
added beside qbit-prism-test-gate.

Part of #271
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 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-15T21:00:22.050676Z ef35434 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.

kiwidream and others added 7 commits September 14, 2026 19:57
…ling it (W10, K6)

mid_flight_kill was awaited inside the 1 ms scheduling loop: across the wait
for work, the kill, the relaunch, the readiness wait, a three second settle,
the re-offers and another three seconds no other frontend was offered
anything, and the next tick turned the gap into a burst plus a shortfall.
The drained restart had been fixed for exactly this twice; the earlier
worker reported this site as the one left over and it was not acted on.

It is now a KillDriver the loop polls, with the same stages in the same
order and the same limits, and the readiness wait is one ReadyWait shared
with RestartDriver so both relaunches wait the same way. A kill still in
flight at the phase boundary is seen through like a restart. A relaunch
that exits or never answers now aborts the phase (exit 6, report written)
where it used to error the whole run; the README says so. Two tests: the
scheduler is never stalled across a whole kill, and an unready relaunch is
reported within its limit.

Part of #271

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…as documented (W10, sweep 1)

Sweep of everything that serialises an error, a URL or an environment into
a report, a log or a summary. Three sinks took free text unredacted: the
failure side report's failed.error, the error the harness prints on stderr,
and every pg_settings value in database-profile.json (primary_conninfo on a
promoted standby is a libpq string with password=, unmasked for a
superuser). Each now goes through redact_secrets_in_text, which redacts
every URL-shaped token and every libpq password= value, so a source that
forgets cannot reintroduce K2 through a sink.

The stderr sink was main returning the error: Rust printed it verbatim and
exited 1, while the README promises 2 and EXIT_ERROR was defined and never
produced. main now prints the redacted error itself and exits EXIT_ERROR.

Part of #271

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… a failure (W10, sweep 3)

Sweep of everything that turns an indeterminate outcome into a definite
one. Three more, beyond K4. A per-phase replication observation whose
pg_stat_replication or synchronous_standby_names could not be read came
back as an empty name and no rows, which is what a primary with no standby
looks like; it now carries error, a null name and no rows. A
pg_stat_activity the lock sampler could not read at startup arrived as an
empty list, which is what "no frontend carried its name" looks like, and
the report blamed the driver; lock_attribution is now one function a test
pins and names the unreadable view as the reason. A re-offer or scheduled
block that reached a session while it had no connection was dropped without
a trace, so a re-offer never sent and one the server never answered read
the same; each is now a client failure of its kind.

Part of #271

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The reconnect-outage test asserted the failed attempt's error names a
closed socket. That is where Linux fails the handshake, at the read; on
another platform the first write after the peer's close can fail with a
broken pipe instead. Either is a failed attempt with a reason, which is all
the test needs.

Part of #271

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The artifact's schema requires a p50 and a p99 for every phase it names,
and the code supplied them with `unwrap_or(0.0)`. A phase that
acknowledged nothing therefore went into the evidence claiming a latency
of zero: a measurement that was never taken, written into the document
whose entire purpose is to be trustworthy. It is the same unknown-as-zero
this crate has spent several rounds removing from everywhere else, in the
one place it matters most.

The run now withholds the artifact and names the phase.

Reusing `PremiseContradicted` rather than inventing a code: a capacity
artifact rests on every phase it names having measured acknowledgements,
and one that did not makes the artifact evidence of nothing, which is
what exit 8 already means. A new exit code for each new way of being
unmeasurable would fragment a contract other tooling reads.

Worth stating plainly, because the first reading overstated it: this is
not a hole through which a run could have passed a capacity gate. The
validator requires positive offered, acknowledged and committed counts,
so it would refuse such an artifact on the counts long before reading the
latency. The defect is that the harness authored a false number at all
and left catching it to the consumer.

Found by the round-6 worker, which reported it as adjacent to its task
rather than in it, and left the decision here. That is the reporting
habit an earlier round's silence made necessary.

Part of #271
Brings the load harness onto the current 3.x.x, which carries #322 (the
shared integration gate and the required fmt, clippy and cargo-deny jobs) and
#316. The only conflict was the root Cargo.toml: 3.x.x's file is kept,
including its commented rust-version pin, and the qbit-prism-load member is
added beside qbit-prism-test-gate.

Part of #271
W4's first probe on the previous base exited 4 on eight shares, stopped,
and asked -- which is what it was told to do, and the report was better
than the finding that prompted the fix. Round 6 already answers the part
it flagged: `classify_committed_gap` matches on the outcome, not on what
caused it, so a submit left outstanding when the teardown drain expires is
covered as much as a peer close.

What its numbers showed is the part nobody had looked at. Its
`slow_database` ACK p99 was 25.3 s against a 25 s drain limit, so at
matrix load a tail of outstanding submits at teardown is not an edge case,
it is every run. Every one of those that PostgreSQL then held would have
exited 5, and exit 5 would have stopped meaning "the server and the miner
disagree" and started meaning "the run ended". A signal that fires on
every run is not a signal, and it would have masked a real divergence
appearing mid-matrix.

So the two causes are now distinguished. A no-response recorded because
the run itself stopped waiting carries `window_ended: true`; the server is
still allowed to answer it, and in production the connection would still
be there to carry the answer. It is reported, named on stderr and kept in
`no_response_commits` -- it just does not by itself make the run exit 5.
A no-response caused inside the run still does.

`fail_pending`'s reason string is now a named constant rather than a
literal compared by hand, because the distinction decides an exit code.

One of W10's own tests had to be corrected rather than mechanically
updated: its case is a peer close mid-run, so it must count toward the
exit code, and it now derives that count the way the run does instead of
asserting a constant.

Part of #271

@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: 5d0042f629

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

Comment thread crates/qbit-prism-load/src/run.rs Resolved
Comment thread crates/qbit-prism-load/src/run.rs Resolved
kiwidream and others added 3 commits September 15, 2026 14:26
…e lost

With `--mid-flight-kill`, `classify_gaps` skipped the kill phase entirely:
not the no-responses the kill produced, the whole phase. A share that
phase acknowledged in the ordinary way -- before the kill, on the healthy
frontend, or after the relaunch -- and that PostgreSQL then lost sat in
`reconciliation.missing`, reached no durability finding, and the run could
exit 0. A committed row in that phase that nothing explained was skipped
the same way. That is a false negative on the one thing the harness exists
to catch, and the inverse of the false alarms the earlier rounds removed.

What the kill legitimately explains is exactly its census: the submits
outstanding on the killed frontend whose answers it destroyed, which are
re-offered and reported under `mid_flight_kill` with the server's answer
and whether PostgreSQL holds each. So `classify_gaps` now takes, per phase,
the share ids of that census instead of a flag, and exempts only a
committed row whose submit is in it. Everything else in the phase is
classified as it is in every other phase: an acknowledged share missing
from PostgreSQL and a committed row nothing explains are durability
findings under `mid_flight_kill` (exit 4), and a no-response the kill did
not cause -- a socket on the healthy frontend closing for its own reasons
-- is a no-response commit as anywhere (exit 5). A kill that found nothing
outstanding has an empty census and exempts nothing.

The README says so, because `durability_findings` and
`no_response_commits` can now name the `mid_flight_kill` phase, which they
never could before. The matrix does not run that phase, so no existing
result changes.

Part of #271

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The reconnect phase's drained restart starts a third of the way in and can
still be draining, relaunching, or waiting for `/healthz` when the phase's
deadline arrives. `drive_phase` then sees it through with nothing scheduled,
and `run_inner` stamped the phase's end only after that wait returned. So the
idle tail landed inside `duration_millis`, the order- and settlement-lock
windows, the process windows, and the denominator of the achieved and offered
rates: a configured 60 s phase came out longer, and its throughput understated.

I kept scheduling to the deadline and moved the measured end to it, rather
than forcing the restart to complete outside the bounds -- the restart has to
be seen through before the next phase offers to a paused or dead-pointed
session, and its own deadlines already bound that wait. `drive_phase` now
records `ended`/`ended_wall` at the instant it stops scheduling, before the
see-it-through loop, and `run_inner` reads those instead of stamping its own
after the loop. The wait for the relaunch is now boundary time, outside the
window, the way the settle before the next phase's delay already is. The
restart is still counted as this phase's, under `drained_restarts` and
`frontend_restarts`.

`drive_phase` and `PhaseOutcome` are now `pub`, and `drive_phase` takes the
`NodeState` it used rather than the whole `RunContext`, so the boundary can be
tested without a database.

The README's `reconnect` phase description now says the phase's duration,
`ended_at`, lock and process windows and rate denominators cover exactly the
scheduling window and that the relaunch wait is boundary time. In the existing
runs every reconnect phase shows `duration_seconds` 60.0 exactly, the ones
that restarted a frontend included, so no matrix result changes; the fix keeps
that true when a restart does outrun the deadline.

Part of #271

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Brings the load harness onto the current 3.x.x, which carries #322 (the
shared integration gate and the required fmt, clippy and cargo-deny jobs) and
#316. The only conflict was the root Cargo.toml: 3.x.x's file is kept,
including its commented rust-version pin, and the qbit-prism-load member is
added beside qbit-prism-test-gate.

Part of #271

@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: a9e0966385

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

Comment thread crates/qbit-prism-load/src/run.rs Resolved
Comment thread crates/qbit-prism-load/src/kill.rs Resolved
Stop and reap each frontend before reading its final stderr so background
rebuilds cannot log a size refusal after evidence has been checked.
Add regression coverage proving the scanned logs cannot grow afterward.

Part of #271
Pause affected sessions before the kill, wait for their outstanding work
to settle, and acknowledge their event barriers through the collector
before taking the census and resuming offers. Use one bounded census
deadline and abort on incomplete session or collector accounting.

Cover delayed session records, collector lag, timeout paths, and a real
disconnected session forwarding its barrier after discarding queued work.

Part of #271

@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: 92b998299e

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

Comment thread crates/qbit-prism-load/src/run.rs Resolved
Include accepted re-offers in the offered and acknowledged share sets.
A deliberate kill explains the original lost response, but an accepted
re-offer whose row is missing must produce a durability finding and exit 4.

Keep duplicate and unanswered re-offers in their existing census classes.
Cover missing and committed rows, repeated acknowledgements, and exit-code
selection; update the documented distinction.

Part of #271

@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: ef35434c02

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

Comment thread crates/qbit-prism-load/src/kill.rs Resolved
Comment thread crates/qbit-prism-load/src/cluster.rs Resolved
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