Skip to content

3.x.x: nightly e2e for PostgreSQL disk exhaustion and wall-clock jumps, and a per-PR Stratum transcript replay (#575) - #586

Merged
djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b575-exhaustion-replay
Sep 29, 2026
Merged

djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b575-exhaustion-replay

Conversation

@djh58

@djh58 djh58 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Refs #575, #554

#575 item 5 (resource exhaustion) and the automatable half of item 3 (replay of recorded Stratum transcripts). Test-only: no server code changes. One follow-up is filed as #581.

What each test does

(a) PostgreSQL disk exhaustion (nightly)

live_regtest::disk_exhaustion_tests::postgres_volume_full_refuses_shares_cleanly_and_recovers_once_space_is_freed

  • The test's own PostgreSQL 16 keeps its whole data directory (with pg_wal) on a 160 MiB ext4 image mounted with fuse2fs -o fakeroot through the setuid fusermount3. No root is needed. The log and socket stay off the volume.
  • Four clients (two per server) mine shares that are not blocks. DiskFullInjector::start fills the filesystem to ENOSPC, and mining continues through the full state until a paging rule has fired on each server (bounded). Every phase is bounded. stop then frees the space. PostgreSQL PANICs on a WAL write and stays down; the test starts it again as a supervisor would. The PRISM servers are never restarted.
  • Asserts:
    • every share a client saw acknowledged is in the ledger;
    • refusals are explicit and bounded, some with the reasons PrismShareAppendFailures counts, whose input rises;
    • no ledger-confirmation-failed share is credited;
    • a paging rule's condition, mirrored from docs/prism-native-alert-rules.json with its expression pinned, holds for its for on every server;
    • after space is freed, both original processes accept shares again (about 1 s), land a new block, and pass the carry-forward integrity check.
  • support/disk_full_injector.rs is the reusable fill/release injector (mount / volume / home / start / stop) for 3.x.x: Fault injection under load (L4/L5) (#487 S16) #554's full-WAL-volume fault under load.

(b) Wall-clock jumps (nightly)

live_regtest::clock_jump_tests::wall_clock_jumps_keep_windows_claims_and_payouts_and_land_every_block_once

  • Both servers and a private PostgreSQL run under libfaketime. Only realtime is faked (FAKETIME_DONT_FAKE_MONOTONIC=1), as with an NTP step. Each has its own offset file, and every move is verified: the HTTP Date for a server, clock_timestamp() for the database.
  • Both servers reach the node through an RPC proxy that counts every submitblock and can hold one.
  • Phases:
    • server 0 jumps −10 min / +10 min, and server 1 jumps −3 h / +3 h;
    • the database jumps +2 h while server 0's block is held mid-landing, which expires the live claim;
    • the database then jumps back 2 h while server 1's block is held;
    • finally every clock is real again.
  • Asserts:
  • Since 3.x.x: cap a block proof's acknowledgement wait at the share commit timeout instead of 60 s (#574) #577, a held block's answer may be ledger-outcome-unknown once the hold outlasts the share commit timeout. The test accepts either answer, and then requires the block to land and its share to be credited exactly once.
  • A server more than PRISM_TEMPLATE_MAX_AGE_SECONDS (120 s) ahead of the node calls every template stale and serves no current work. That is fail-safe, not wrong work. The test asserts this, and checks that PrismWorkRefreshStalledCritical fires (its condition held about 110 s against a 60 s for) and that the server serves again once corrected.

(c) Stratum transcript replay (per PR)

live_regtest::transcript_replay_tests::recorded_stratum_transcripts_replay_compatibly_against_a_live_server, plus an ungated corpus check.

  • Transcripts are JSON lines with direction, timestamp and message, after a header labelled synthetic or captured.
  • The client's lines are replayed on one connection. Worker names get the regtest address. A submit the recorded pool accepted is solved again on live work, keeping its shape (5 fields, or 6 with version bits).
  • Answers are checked for compatibility per method (subscribe shape, configure and version-rolling mask, success or failure parity), along with notification shapes and ordering.
  • The corpus is five synthetic transcripts: cgminer, bmminer version rolling, NiceHash extranonce.subscribe, Braiins multi-extension mining.configure, and esp-miner suggest_difficulty plus an unsupported method.
  • tests/fixtures/stratum_transcripts/README.md documents how to add real captured transcripts, including redaction.

Findings

Mutants (each test fails against a broken build)

test mutant failure
(a) SaveOutcome::Failed acknowledges the share acknowledged shares missing from the ledger: [...]
(b) share append's ledger clock follows the database clock backwards (no GREATEST) database back 2 h mid-landing: server 0 refused its block
(c) mining.configure refuses version rolling bmminer-version-rolling: version rolling refused where the recorded pool granted it
(c) mining.extranonce.subscribe unsupported nicehash-extranonce-subscribe: failed where the recorded pool succeeded

Runtime

  • Per PR: (c) adds about 4 s to the live_regtest shard (3.7 s locally, fixture included); the corpus check takes milliseconds.
  • Nightly: (a) adds about 3.5 min and (b) about 5.1 min to live-nightly, which took 13 min last night and has a 60 min limit.
  • A branch dispatch of prism-load-nightly (run 36607091066, at 228664cb) confirmed that fuse2fs, /dev/fuse and libfaketime work on the runner. The disk variant passed there. The clock variant exposed a check made mid-backoff, which b53a78be fixes (see the ledger).

CI notes

Scope note

live_share_client.rs's solver and live_private_postgres.rs repeat logic that already exists privately inside #521's modules (the weighted-recipients Session, node-outage BlockClient, pg-failover Cluster). Consolidating them would mean editing those modules, which other lanes are working next to, so this PR adds new shared modules only. The new ones are self-contained so later tests can reuse them.

🤖 Generated with Claude Code

…s, and a per-PR Stratum transcript replay (#575)

Three live_regtest scenarios for #575's item 5 and the automatable half of
item 3.

Disk exhaustion (nightly): the test's own PostgreSQL 16 keeps its whole
data directory on a small ext4 image mounted with fuse2fs through the
setuid fusermount helper, so no root is needed. Clients mine shares that
are not blocks on both servers while a ballast fills the filesystem to
ENOSPC, mine through the full state past the paging rules' `for`, then the
space is freed. It asserts that every acknowledged share is in the ledger,
that refusals are explicit (some with the reasons PrismShareAppendFailures
counts) and no ledger-confirmation-failed share is credited, that a paging
rule's condition (mirrored from docs/prism-native-alert-rules.json) holds
for its `for` on every server, and that both original server processes
accept shares again, land a block and keep carry integrity once space is
freed. The fill/release mechanism is a reusable DiskFullInjector for #554.

Clock jumps (nightly): both servers and a private PostgreSQL run under
libfaketime (realtime only). Each server jumps minutes and hours behind and
ahead; the database jumps two hours ahead and back while a found block's
submitblock is held mid-landing. It asserts that every acknowledged share
is credited once with a monotonic ledger clock, that every block is offered
exactly once, lands once and matches its audit bundle, and carry integrity.
A held block's answer may be ledger-outcome-unknown at the share commit
timeout (#577); it must still land and be credited once. A server more than
PRISM_TEMPLATE_MAX_AGE_SECONDS ahead of the node serves
no work (fail-safe) and PrismWorkRefreshStalledCritical fires; corrected,
it serves again. One outbox row is left in reconciliation after the
database clock steps back, which #581 tracks and the test pins.

Transcript replay (per PR, about 4 s): a JSON-lines Stratum transcript
format and harness that replays recorded client sessions against a live
server and checks each answer for compatibility, with a synthetic corpus
for cgminer, bmminer version rolling, NiceHash extranonce.subscribe,
Braiins mining.configure extensions and esp-miner suggest_difficulty.

The nightly job installs fuse2fs, fuse3, faketime and libfaketime, and the
three tests are named in test/e2e-scenarios.toml (#543).

Refs #575, #554

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream September 29, 2026 17:42
@blacksmith-sh

This comment has been minimized.

…, bounded disk-full phases, one Stratum session

Review follow-ups on the #575 scenarios; tests only.

- Clock jumps: every ordinary share a serving server mines must be
  accepted. Before, only the block was checked, so a server refusing every
  share after a clock step still passed. The one exception is the phase
  right after the database clock steps back, where the stale-job and
  ledger-confirmation-failed refusals #581 records are allowed.
- Clock jumps: each block's outbox row is given its reconciliation retry
  (10 s per attempt) to finish before it is checked. The nightly dispatch
  on this branch caught a row released into reconciliation by a
  post-offer step that lost a payout-revision race, checked mid-backoff.
- Disk exhaustion: every phase is bounded (a server that never accepts
  fails the test instead of hanging the job), and the full state ends
  when a paging rule has fired on each server, bounded, instead of a fixed
  200 s after the first refusal of either server.
- One StratumSession serves both the share client and the transcript
  replay; answers are typed (accepted, rejected, timed out, lost) instead
  of matched on error text.
- Rule mirrors, the sliding [5m] window and the `for` verdicts live in the
  alert-rules module; the submitblock proxy and the host-tool helpers get
  their own support files; impossible states are gone from the types.

Refs #575, #554

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

djh58 commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

Deep-review ledger (head b53a78be, CI green except the #584 manifest gap)

Stakes: low. The change is test-only. No server code changes. It adds nightly e2e for PostgreSQL disk exhaustion and wall-clock jumps, and a per-PR Stratum transcript replay.

Lanes:

  • /code-review high, run before the first commit;
  • a thermo-nuclear quality review and an adversarial review (Claude), both on 228664cb;
  • a branch dispatch of prism-load-nightly, run 36607091066, on 228664cb with pr-smoke and the live variants.

The second adversarial model and bugbot were not run. No human or review-bot comments had been posted when this ledger was written; Blacksmith's CI bot reported the e2e-manifest failure noted at the end.

# Lane Finding Disposition
1 code-review The submitblock proxy kept one upstream connection per server connection. A held call could outlast qbitd's idle timeout and then be written into a dead socket, causing a spurious double offer. Fixed in 228664cb: a new upstream connection per request, opened after any hold.
2 code-review The client's 30 s answer bound was shorter than the server's block-only acknowledgement bound. Fixed in 228664cb: 70 s. After #577 the server's bound is the share commit timeout (15 s), which also covers held blocks.
3 code-review The full-state hold was timed from the first refusal on either server, not on each server. Fixed in 228664cb, and superseded in b53a78be: the full state now ends when a paging rule has fired on each server, bounded.
4 code-review The rule mirrors measured [5m] increases from the pre-fill scrape, although the full state can last longer than 5 min. Fixed in 228664cb: a sliding five-minute base, now in live_alert_rules.rs.
5 code-review The private cluster's port was not reserved until PostgreSQL bound it (#533's race). Fixed in 228664cb: a reservation listener is held until the first start.
6 code-review A timed-out recovery phase left client tasks running during cleanup. Fixed in 228664cb, then b53a78be: every phase has a deadline that the clients themselves observe.
7 code-review Replay had no retry for a job that a new tip superseded mid-transcript, which would make the per-PR gate flaky. Fixed in 228664cb: each transcript starts on the node's tip, and a superseded re-solved submit is solved again, up to 3 times.
8 code-review The injector's plain unmount leaves a dead mount if a file is still open. Fixed in 228664cb: falls back to a lazy unmount.
9 code-review The solver and private-cluster wrapper duplicate helpers that are private to #521's modules. Rejected for this PR. Consolidating means editing modules that other lanes are working next to. The new modules are self-contained for reuse (PR body, "Scope note").
10 code-review Three scenarios repeated the server start and readiness loop. Fixed in 228664cb: start_share_only_servers.
11 thermo There were two Stratum clients (ShareClient and the replay's Live, which had its own reader task). Fixed in b53a78be: one StratumSession, used by both.
12 thermo Answers were matched on error text ("no Stratum message"). Fixed in b53a78be: Answer::{Accepted, Rejected, TimedOut, Lost} and reason_id(). A timeout is recognised by downcasting to Elapsed.
13 thermo Rule evaluation was spread across the scenarios and written twice. Fixed in b53a78be: Mirror, Verdict, snapshot_stale() and label_alternatives live in live_alert_rules.rs.
14 thermo The disk scenario's phase control was tangled: one shared stop flag, anonymous tuples, and identities rebuilt from share_id prefixes. Fixed in b53a78be: a Miner struct, per-phase deadlines, and per-miner acceptance counts.
15 thermo Types allowed impossible states: Served flags, Options that were always Some. Fixed in b53a78be: enum Served, and plain fields.
16 thermo Module boundaries: host tools lived in the Postgres module, and the proxy lived in the scenario file. Fixed in b53a78be: live_host_tools.rs and live_submit_proxy.rs.
17 adversarial (major) The clock test never checked that ordinary shares were accepted, so it would pass if the server refused every share after a clock step. Fixed in b53a78be. Every share on a server that must serve is accepted, except the #581 refusals right after the database clock steps back.
18 adversarial The disk test's Before phase was unbounded: a server that never accepts would hang the job. Fixed in b53a78be: bounded, and it fails with a summary.
19 adversarial The disk hold raced PostgreSQL going down later than the first refusal. Fixed in b53a78be: the hold now ends when a rule fires on every server, bounded at 360 s.
20 nightly dispatch The runner environment was unverified. Verified. fuse2fs, /dev/fuse and libfaketime work on the Blacksmith runner. The disk variant passed. The three existing nightly variants passed too.
21 nightly dispatch The clock variant failed once. The server released a held block's row into reconciliation ("post-offer processing failed (node accepted the offer): payout revision changed while observing chain state"), and the test checked the row during its 10 s retry backoff, which quiesce allows. Fixed in b53a78be: verify waits, bounded at 120 s, for each row to settle, excepting #581's row. The server behaved as designed: one offer, and the retry finishes the row.
22 e2e (server) A backward database clock step stretches outbox retries and claim leases. During a PostgreSQL outage, only one alert rule holds past its for. Deferred to #581, as agreed. The nightly test pins today's behaviour and names the issue.

Mutants, re-run on the final code; each test fails:

  • (a) acknowledging a share on SaveOutcome::Failed gives "acknowledged shares missing from the ledger";
  • (b) the ledger clock without GREATEST gives "server 0 refused its block";
  • (c) refusing version rolling makes the bmminer transcript fail;
  • (c) an unsupported mining.extranonce.subscribe makes the NiceHash transcript fail.

Local results on the final code: (a) 203 s, (b) 304 s, (c) 3.5 s, all recorded executed in the gate manifest.

Totals: 19 fixed (including the dispatch-found #21), 1 rejected, 1 deferred, 1 verified.

CI at b53a78be: 19 of 21 checks pass, including all four native PRISM shards and the gated-test execution proof, which shows the replay test executed. The only red is Python shard 1's test_the_checked_in_manifest_passes, plus the aggregate gate that requires it. It fails because of two tests on 3.x.x that no scenario names, which is not from this PR; #584 fixes it, and the job will be re-run once #584 merges.

@djh58 djh58 closed this Sep 29, 2026
@djh58 djh58 reopened this Sep 29, 2026
@djh58
djh58 merged commit b953463 into 3.x.x Sep 29, 2026
21 checks passed
djh58 added a commit that referenced this pull request Sep 29, 2026
Resolves test/prism-nightly-gated-tests.txt: keeps the soak smoke id and #586's clock-jump and disk-exhaustion ids, sorted.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
djh58 added a commit that referenced this pull request Sep 29, 2026
Resolves test/e2e-scenarios.toml: keeps #547's real-node scenarios and #586's #575 scenarios; check_e2e_scenarios and its unit tests pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
djh58 added a commit that referenced this pull request Sep 29, 2026
…587, #593, #594)

Adds #586's disk-full and clock-jump tool installs, #587's weekly cutover rehearsal settings, #593's comment and #594's nightly Stratum fuzz job. Byte-identical to 3.x.x at bcb7749.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
djh58 added a commit that referenced this pull request Sep 29, 2026
…587, #593, #594) (#595)

Adds #586's disk-full and clock-jump tool installs, #587's weekly cutover rehearsal settings, #593's comment and #594's nightly Stratum fuzz job. Byte-identical to 3.x.x.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
djh58 added a commit that referenced this pull request Oct 1, 2026
…, and start each replayed transcript after earlier blocks land (#631, #632) (#640)

* 3.x.x: pause the session load's shares around scenario 2's own blocks, and start each replayed transcript after earlier blocks land (#631, #632)

#631: on regtest a load share weighs about half an own block. The
share-only settings' 2^-32 is the easiest share target there is, and an
own block's block-only proof is credited at regtest's ~2^-31 network
difficulty. So ~15 load shares fill the 8x window, and which earlier
own share survives in each own block's window is a timing race. The
nightly deep reorg under 2,000 sessions hit the case where branch B paid
both miners exactly what branch A did. The load can now pause its share
offers (sessions stay connected and keep taking work), and deep_reorg
pauses them from its seed blocks until branch B's own blocks are paid,
then resumes them for the heal and the reorg. Without a load the hook
does nothing.

#632: esp-miner-suggest-difficulty finds a block, which lands after its
submit is answered. The next transcript's first share could pass its
revision check before the landing and commit after it, and was refused
as ledger-confirmation-failed. current() now also waits until no
candidate is unfinished and /healthz payout_state_generation is the
cluster's payout_revision.

Closes #631, closes #632. Refs #553, #586.

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

* 3.x.x: close the session load's pause barrier on shares already being sent, and on shares that commit after their answer (#631)

Review follow-ups:
- A session now counts itself as unanswered before it reads the pause
  flag. Before, a share could be mid-write when the pauser read zero.
- After the answers drain, the pause also waits until the share ledger
  holds still for 2 s. A lost or ledger-outcome-unknown answer may
  still commit.
- The drain allows twice the answer bound. A stuck share is cleared on
  the first tick past the bound, and ticks can be up to the bound apart.

Refs #631, #553.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 1, 2026
…bel database refusals truthfully, and page a PostgreSQL outage on its own rule (#581)

#586's nightly variants showed two gaps. Every outbox deadline was the
database clock, so a clock step moved it by the step. Forward, a second
frontend took a live claim whose block was still being offered. Backward,
the reconciliation row that takeover left waited two hours, and a dead
holder's claim would have waited lease + step. Separately, a PostgreSQL
outage held only PrismBlockCandidateMetricsUnavailable: the share-refusal
rules were gated on a snapshot whose freshness flaps while the publisher
waits on the database, and their counters were frozen in it. Database stalls
were refused backend-rpc-unavailable, blaming a healthy node.

Leases (option B, operator-chosen): migration 021 adds claim_renewals and
claim_lease_seconds, a partial index over claimed rows, and the
candidate_claim_observed_lease capability (offline, as 018). A frontend
times each claim version (token, renewals) on its own monotonic clock from
the reply that first shows it, and takes the row over only after the whole
lease, by compare and set on that version, whatever the row's schedule
unless it is parked. Holders fence on their token; their heartbeat deadline
is never extended from the database clock. A row last written later than
the clock proves a backward step and is due at once. candidates recover
waits out an observed lease (--unsafe-database-clock-expiry keeps the old
rule) and its release keeps a schedule within the row's own backoff.
candidates abandon times a claim the same way and abandons by compare and
set on the version it watched, so a forward step no longer lets it take a
pending row from a live holder (Codex on #646); the same flag keeps the
old rule. The pool-acquire inventory classifies the revocation helper.

Attribution and alerting: backend-database-unavailable for session
allocation, the payout reads, job persistence and resume when a SQLx error
is in the chain, and stale readiness when the latest refresh failed on the
database. rejections_total and accepted_shares_total render at scrape time,
the two share-refusal rules drop the snapshot gate, and
PrismDatabaseUnavailable (database collector unavailable for 2 m, paging)
is added, with the qbit-tools patch regenerated. #586's nightly tests now
assert the new behaviour.

Three adversarial verifications: leases and labels requested changes (a
renewal after a backward step stranding a dead holder's row; stale readiness
during an outage still blamed the node), both fixed with regression tests;
the re-verification approved. Rebased onto 3.x.x 90327e8 as one commit
(PR #646's series eb5f65e, 1604a75, 5ce263d), past #642 and #645: the
cardinality pins are 77 families, 306 startup and 957 populated series;
the stratum normalization pin stays 15.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 2, 2026
…bel database refusals truthfully, and page a PostgreSQL outage on its own rule (#581)

#586's nightly variants showed two gaps. Every outbox deadline was the
database clock, so a clock step moved it by the step. Forward, a second
frontend took a live claim whose block was still being offered. Backward,
the reconciliation row that takeover left waited two hours, and a dead
holder's claim would have waited lease + step. Separately, a PostgreSQL
outage held only PrismBlockCandidateMetricsUnavailable: the share-refusal
rules were gated on a snapshot whose freshness flaps while the publisher
waits on the database, and their counters were frozen in it. Database stalls
were refused backend-rpc-unavailable, blaming a healthy node.

Leases (option B, operator-chosen): migration 021 adds claim_renewals and
claim_lease_seconds, a partial index over claimed rows, and the
candidate_claim_observed_lease capability (offline, as 018). A frontend
times each claim version (token, renewals) on its own monotonic clock from
the reply that first shows it, and takes the row over only after the whole
lease, by compare and set on that version, whatever the row's schedule
unless it is parked. Holders fence on their token; their heartbeat deadline
is never extended from the database clock. A row last written later than
the clock proves a backward step and is due at once. candidates recover
waits out an observed lease (--unsafe-database-clock-expiry keeps the old
rule) and its release keeps a schedule within the row's own backoff.
candidates abandon times a claim the same way and abandons by compare and
set on the version it watched, so a forward step no longer lets it take a
pending row from a live holder (Codex on #646); the same flag keeps the
old rule. The pool-acquire inventory classifies the revocation helper.

Attribution and alerting: backend-database-unavailable for session
allocation, the payout reads, job persistence and resume when a SQLx error
is in the chain, and stale readiness when the latest refresh failed on the
database. rejections_total and accepted_shares_total render at scrape time,
the two share-refusal rules drop the snapshot gate, and
PrismDatabaseUnavailable (database collector unavailable for 2 m, paging)
is added, with the qbit-tools patch regenerated. #586's nightly tests now
assert the new behaviour.

Three adversarial verifications: leases and labels requested changes (a
renewal after a backward step stranding a dead holder's row; stale readiness
during an outage still blamed the node), both fixed with regression tests;
the re-verification approved. Rebased onto 3.x.x eedf331 as one commit
(PR #646's series eb5f65e, 1604a75, 5ce263d), past #642, #645 and
#643: the cardinality pins are 79 families, 313 startup and 964 populated
series; the stratum normalization pin stays 15. ReadinessState keeps
#643's poll fields and refresh_failed_on_database, whose comment now says
that a guarded tip poll (#622) decides whether readiness ages during a
database outage and this flag decides the label once it does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 2, 2026
…bel database refusals truthfully, and page a PostgreSQL outage on its own rule (#581) (#646)

* 3.x.x: time candidate claim leases on the taker's monotonic clock, label database refusals truthfully, and page a PostgreSQL outage on its own rule (#581)

#586's nightly variants showed two gaps. Every outbox deadline was the
database clock, so a clock step moved it by the step. Forward, a second
frontend took a live claim whose block was still being offered. Backward,
the reconciliation row that takeover left waited two hours, and a dead
holder's claim would have waited lease + step. Separately, a PostgreSQL
outage held only PrismBlockCandidateMetricsUnavailable: the share-refusal
rules were gated on a snapshot whose freshness flaps while the publisher
waits on the database, and their counters were frozen in it. Database stalls
were refused backend-rpc-unavailable, blaming a healthy node.

Leases (option B, operator-chosen): migration 021 adds claim_renewals and
claim_lease_seconds, a partial index over claimed rows, and the
candidate_claim_observed_lease capability (offline, as 018). A frontend
times each claim version (token, renewals) on its own monotonic clock from
the reply that first shows it, and takes the row over only after the whole
lease, by compare and set on that version, whatever the row's schedule
unless it is parked. Holders fence on their token; their heartbeat deadline
is never extended from the database clock. A row last written later than
the clock proves a backward step and is due at once. candidates recover
waits out an observed lease (--unsafe-database-clock-expiry keeps the old
rule) and its release keeps a schedule within the row's own backoff.
candidates abandon times a claim the same way and abandons by compare and
set on the version it watched, so a forward step no longer lets it take a
pending row from a live holder (Codex on #646); the same flag keeps the
old rule. The pool-acquire inventory classifies the revocation helper.

Attribution and alerting: backend-database-unavailable for session
allocation, the payout reads, job persistence and resume when a SQLx error
is in the chain, and stale readiness when the latest refresh failed on the
database. rejections_total and accepted_shares_total render at scrape time,
the two share-refusal rules drop the snapshot gate, and
PrismDatabaseUnavailable (database collector unavailable for 2 m, paging)
is added, with the qbit-tools patch regenerated. #586's nightly tests now
assert the new behaviour.

Three adversarial verifications: leases and labels requested changes (a
renewal after a backward step stranding a dead holder's row; stale readiness
during an outage still blamed the node), both fixed with regression tests;
the re-verification approved. Rebased onto 3.x.x eedf331 as one commit
(PR #646's series eb5f65e, 1604a75, 5ce263d), past #642, #645 and
#643: the cardinality pins are 79 families, 313 startup and 964 populated
series; the stratum normalization pin stays 15. ReadinessState keeps
#643's poll fields and refresh_failed_on_database, whose comment now says
that a guarded tip poll (#622) decides whether readiness ages during a
database outage and this flag decides the label once it does.

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

* 3.x.x: record a refresh's database failure before it releases the refresh lock, so an older refresh cannot overwrite a newer one's (#581)

Codex on #646: refresh_once wrote refresh_failed_on_database after
refresh_once_inner had returned and dropped refresh_lock. Two overlapping
refreshes run serialized under that lock, but the older one could record
its outcome after the newer one had: a success overwriting the database
failure that followed it. If readiness then aged out, the refusal would
blame the node although the latest refresh failed on PostgreSQL.

The work under the lock moves to refresh_locked, and refresh_once_inner
records the outcome before the lock guard drops, so outcomes land in the
order the refreshes ran. The lock order (refresh lock, then readiness) is
the one the refresh already takes.

Test: a refresh paused in its revision read fails on the database while
the test holds readiness, so it cannot record yet. The refresh lock must
still be held, and the newer, successful refresh's outcome is the one
left. On the old code the lock was already free (the headline assertion
fails). The stale-readiness test's comment now names #643's guarded tip
poll.

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

* 3.x.x: label an issued persistence that outlived its deadline as the database's, whichever of the deadline and the statement failed first (#581)

CI shard 0 on 0b21539 failed compact_runtime_e2e's
issued_expiry_during_sql_wait test: a persistence queued on a database
lock past its 1 s deadline was refused backend-database-unavailable when
the statement its shortened statement_timeout cancelled failed first, and
backend-rpc-unavailable when the deadline fired first (a plain string
error). The label depended on which future completed first.

Persistence waits on the ledger alone (its clock and revision reads, the
batch transaction and its row locks, the compact repair it writes), so an
expiry is the database not answering in time. save_issued_record, the one
place that knows the persistence's own deadline, now marks a failure that
outlived it with a typed IssuedPersistenceExpired, and persist_issued_job
labels that backend-database-unavailable before the SQLx-chain rule. A
failure inside the deadline keeps that rule (a statement error is the
database's; an authority refusal stays backend-rpc-unavailable). The full
error chain is logged.

Tests: a unit test forces both orderings on the fake ledger (a statement
failing inside the deadline; the deadline elapsing while the save still
waits, its statement failing afterwards), both
backend-database-unavailable; without the classification the second is
labelled the node's, as in CI. The e2e test now runs both orderings on
PostgreSQL (the waiting statement cancelled inside the deadline; the lock
held past it) and expects the database label for each. A sweep of other
backend-rpc-unavailable assertions found none on a database-wait path.
prism-rejections.md names the case.

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

---------

Co-authored-by: Claude Opus 5.5 <[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