Skip to content

3.x.x: refuse CTV settlement without a pool fee and page when no work reaches the observed tip (#525) - #534

Merged
djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b525-pool-fee-guard
Sep 28, 2026
Merged

djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b525-pool-fee-guard

Conversation

@djh58

@djh58 djh58 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Closes #525

Problem

With CTV settlement on and the pool fee off, the first positive balance below the payout floor stops all work. Every build on the next tip fails with PayoutExceedsCandidateBalance, because only the pool fee can take sub-floor dust (add_swept_dust_to_pool_fee). No job is published on the new parent. Nothing paged: the symptoms were a template refresh deferred WARN per refresh and, once readiness lapsed, health_state 0, which no rule reads.

This PR takes the small pre-GA route from the issue: refuse the configuration, and page on the stall. apply_payout_policy is unchanged.

1. Fail fast

Config::ensure_pool_fee_settles_dust refuses PRISM_CTV_SETTLEMENT_ENABLED=1 without PRISM_POOL_FEE_ENABLED=1. The message names both settings and the reason. Any fee is accepted, PRISM_POOL_FEE_BPS=0 included: a 0-bps fee pays nothing until dust must be swept.

Entry point Behaviour
run (server::run) refuses before any listener or database connection
check-config fails
self-check fails, report ok: false
policy-transition target refused
policy-transition current side, operator tools still read a fee-less configuration, so policy-transition can repair a cluster that ran without a fee
make doctor (check-env.sh) mirrors the rule, including a process-environment override of the sourced .env

Direct (non-CTV) settlement is equally exposed and is not refused here. It calls the same apply_payout_policy with the same floor and prior balances. .env.example, compose.yaml and the load harness default to direct settlement with the fee off, so a fee-off pool in any mode stalls on the first sub-floor balance. Making a fee mandatory in all modes, or adding a no-fee dust path, is tracked in #535. Until then, the paging rule below covers both paths. .env.example, compose.yaml and PRISM.md now say so.

2. Make the stall page

Monitoring gap: the existing coverage rules cannot see this class of stall.

PrismSemanticWorkCoverageLoss, PrismSemanticWorkCoverageLossCritical and PrismCurrentWorkGapHigh compare each session with the latest published work generation. They never compare it with the node's tip. When every refresh on a new tip fails, the published generation stays on the old parent, and every miner still holds it, so coverage reads 1 for the whole stall. work_refresh_metric asserts exactly that.

PrismAcceptedRevisionWorkPendingCritical covers only blocks this frontend saw accepted, and forgets them on restart. Any persistent refresh failure was therefore invisible to paging, on a new tip or the same parent: a dust stall, an RPC, template or database error, or a hung build.

Flagging for Alex: this seems worth checking against the other "current work" signals.

  • New gauge: qbit_prism_work_refresh_stalled_seconds.
    • It is the time since Coordinator::refresh_once last succeeded, whether that refresh published new work or revalidated the current work. Before the first success it counts from process start, so a restart into a stall still grows.
    • Only that success renews readiness, and share and block admission require readiness within the health timeout. The age is therefore exactly how long this frontend has been unable to serve current work.
    • It grows through all of these, on either settlement path:
      • a stall on a new tip;
      • a stall on the same parent, e.g. a dust rebuild after the 60 s re-anchor;
      • a refresh that fails before its tip observation, or hangs.
    • A healthy frontend reads at most about one poll interval.
  • New rule: PrismWorkRefreshStalledCritical (qbit-prism-work-refresh-stalled-critical).
  • Regenerated with the generators: native metric inventory, metadata, migration table and the qbit-tools patch. Rules go from 72 to 73.

The first commit measured only the time since the observed tip departed from the published one. Review showed that design missed same-parent stalls, so the second commit replaces it; the departure clock is gone.

Tests

Test Kind What it proves
config::tests::ctv_settlement_without_a_pool_fee_is_refused / ..._with_any_pool_fee_is_accepted (200 and 0 bps) / direct_settlement_without_a_pool_fee_is_not_refused_here unit the guard, and its scope
pool_fee_guard (5 tests) CLI subprocess, no DB check-config refuses (unset and =0) and accepts (200 and 0 bps); run and self-check refuse; a transition target is refused, but not a fee-less current configuration
work_refresh_metric::failing_refreshes_grow_the_refresh_stall_gauge_while_coverage_reads_one gated (PostgreSQL), real server binary + fake node one miner holds work on tip A; a same-parent stall and then a new-tip stall each grow the gauge while semantic coverage stays 1; each successful refresh brings it back below 3 s
6 #525 promtool scenarios alert pages at 4m30s with coverage 0; pending inside the dwell; resolves; sub-120 s refreshes never page; -1 never pages; stale snapshot defers
test_check_env_production_gate (+3), test_mainnet_compose_contract (+1) Python doctor refusal and acceptance; a process-environment disable beats an env-file enable; the mainnet fixture enables a fee

crates/qbit-prism/tests/repro_prism_stall.rs still pins the policy-level error.

Mutants (each applied, rebuilt and run)

Mutant Caught by
gauge never published (publish_work_refresh_stalled call removed) work_refresh_metric: times out waiting for work on tip A
clock renewed on every refresh attempt, failed ones included work_refresh_metric: times out waiting for the same-parent stall
clock never renewed on success work_refresh_metric: "healthy frontend drifted"
guard always passes 4 of 5 pool_fee_guard tests, and the config unit test
doctor check disabled 3 subtests of test_ctv_settlement_requires_a_pool_fee_before_docker_check
doctor ignores the process-environment fee flag test_process_environment_disables_a_pool_fee_the_env_file_enables and the acceptance subtests
rule threshold 1200 s / dwell 0s / != 0 (counts -1) the pages / pending-inside-dwell / unobserved-tip scenarios

Fixtures changed (additive)

  • live_regtest CTV servers, the config_cli CTV success case and the CTV policy-transition support now run a 0-bps fee, with PRISM_POOL_FEE_P2MR_PROGRAM_HEX and a recipient ID.
  • A case that sets its own PRISM_POOL_FEE_* in server_env (3.x.x: follow weighted multi-address shares to spent outputs on a live regtest node (#521 scenario 7) #524's weighted-recipients case sets an address) replaces the CTV default whole. Otherwise its address would sit beside the default program, and startup would refuse with "configure exactly one pool fee address or P2MR program".
  • observability census counts are bumped by one family and one series.
  • tests/fixtures/mainnet-compose.env enables a 200-bps fee.

Local verification

  • cargo test -p qbit-prism-server --lib: 576 passed.
  • pool_fee_guard, work_refresh_metric (gated, PRISM_TEST_REQUIRE_INTEGRATION=1), observability, config_cli, metrics_allocation and ledger_postgres -- policy_transition (13) all pass.
  • On the rebased tree, the live regtest cases pass:
  • repro_prism_stall passes.
  • cargo clippy -p qbit-prism-server --all-targets -D warnings and cargo fmt --check are clean.
  • test_prism_alert_promql.py (promtool 3.14.0): 154 scenarios.
  • generate_prism_alerts.py --check, test_prism_alert_deployment.py (73 rules), generate_prism_metrics.py --check, check_prism_settings.py, check_gate_env_reads.py and check_deleted_test_map.py all pass.
  • Python doctor and settings tests: 72 OK.
  • test_mainnet_compose_contract needs Docker, which the local host does not have, so CI runs it.

Per-PR CI runtime added

  • rust-tests: pool_fee_guard adds about 15 s wall-clock. One case waits out the closed-port database pool timeout, and the other cases run alongside it. The unit tests add under 0.1 s.
  • prism-native-postgres: work_refresh_metric adds about 25 s.
  • Alert and doctor checks: 6 promtool scenarios and 3 Python tests add a few seconds.
  • Build: two small new test binaries.

🤖 Generated with Claude Code

… reaches the observed tip (#525)

With CTV settlement on and the pool fee off, the first positive balance
below the payout floor fails every work build on the next tip with
PayoutExceedsCandidateBalance: only the pool fee can take sub-floor dust
(add_swept_dust_to_pool_fee). No job is published on the new parent, and
mining stops until the dust reaches the floor or leaves the window. The
only symptom was a WARN line per refresh.

Fail fast. Config::ensure_pool_fee_settles_dust refuses
PRISM_CTV_SETTLEMENT_ENABLED=1 without PRISM_POOL_FEE_ENABLED=1, names
both settings and the reason, and accepts any fee, 0 bps included. Four
entry points check it: server::run (before any listener or the
database), check-config, self-check, and a policy-transition target.
The current side of a transition, and the operator tools, still read a
fee-less configuration, so policy-transition can repair a cluster that
ran without a fee. make doctor mirrors the rule, including a
process-environment override of the sourced .env. apply_payout_policy
is unchanged.

Make the stall page. Semantic coverage cannot see it: sessions are
compared with the latest published generation, which stays on the old
parent while every refresh fails, so the ratio reads 1. The new gauge
qbit_prism_current_parent_work_missing_seconds reads the coordinator's
tip state at each health publication. It is the time since the observed
tip first departed from the published tip, clocked like the
replacement-build lease: retries and newer tips never renew it, and it
is 0 once work is published on the tip and -1 before any tip
observation. PrismCurrentParentWorkMissingCritical pages at 120 s for
1 m, gated on a fresh snapshot, on either settlement path. That makes
it the safety net for direct settlement, which applies the same policy
and is not refused here.

Fixtures: the live regtest CTV servers run a 0-bps fee unless a case
sets its own PRISM_POOL_FEE_* in server_env, as the weighted-recipients
case does with an address. The config_cli CTV success case and the CTV
policy-transition support also run a 0-bps fee. The mainnet
Compose fixture enables a fee. .env.example and compose.yaml explain
the exposure; their defaults (CTV off) were already accepted.

Tests:
- config unit tests: refuse, accept at 200 and at 0 bps, direct not
  refused.
- pool_fee_guard (CLI): check-config refuses and accepts; run and
  self-check refuse; a policy-transition target is refused, but not a
  fee-less current configuration.
- TipState unit tests.
- Gated parent_work_metric: the real server against the fake node. One
  miner holds work on tip A; tip B fails every refresh after its
  observation. The gauge grows while coverage stays 1 and health 0, and
  it returns to 0 when B publishes.
- Six promtool scenarios and doctor tests.

Mutants caught: gauge never published, gauge blind to the departure,
guard disabled, doctor check disabled, and rule threshold, dwell or
unknown gate broken. repro_prism_stall still pins the policy.

Closes #525

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream September 28, 2026 18:10
@djh58

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor 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.

Stale Bugbot comment from a previous run.

…525 review)

Review found that the first gauge counted only after the observed tip
departed from the published one. A #525 stall can start on the same
parent: in direct mode, dust from gross alone fails the 60 s re-anchor
rebuild on the current tip. Readiness then lapses and shares are refused,
but the gauge read 0, and it paged only after the next network block,
never if the pool finds most blocks. A refresh that failed before its
own tip observation (e.g. a database error) or hung was also invisible.

The gauge is now qbit_prism_work_refresh_stalled_seconds: the time since
Coordinator::refresh_once last succeeded (published or revalidated
work), counted from start before the first success. Only that success
renews readiness, so the age is exactly how long the frontend has been
unable to serve current work, whatever the cause. The rule is renamed
PrismWorkRefreshStalledCritical, with the same 120 s / 1 m / fresh-snapshot
shape. The TipState departure clock and its tests are removed, so the
lease predicate is no longer duplicated.

work_refresh_metric replaces parent_work_metric. The real server runs
against the fake node through two stalls: a same-parent one (tip
unchanged, template for another parent) and a new-tip one. The gauge
keeps growing through both while semantic coverage reads 1, and it drops
back below 3 s once a refresh succeeds. Mutants caught: the clock renewed
on failed refreshes, never renewed, or never published.

Also from review:
- self-check runs its local checks before returning the pool-fee refusal;
- the mainnet-deployment pool-fee block no longer splits the walletless
  broadcaster lead-in from its example;
- the non-CTV exposure cites #535;
- the policy-transition fixture derives its fee policy from one list;
- a doctor test proves a process-environment disable beats an env-file
  enable (it fails with the override removed).

Refs #525

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

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5953d79. Configure here.

@djh58

djh58 commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

Deep-review ledger (#525)

Stakes: high. This PR gates pool-fee and payout configuration and adds a paging rule, so bugbot was summoned for both commits.

Lanes:

  • /code-review medium;
  • thermo-nuclear quality review;
  • adversarial review (Claude). The Codex adversarial lane was not run: this lane is restricted to Claude models.
  • Cursor bugbot: no issues on 31fe5b7 or 5953d79.

Commits:

  • 31fe5b7: the guard and the first gauge.
  • 5953d79: review fixes, including the gauge redesign.

For review, @kiwidream

  1. New paging rule. PrismWorkRefreshStalledCritical (uid qbit-prism-work-refresh-stalled-critical) reads the new gauge qbit_prism_work_refresh_stalled_seconds. The gauge is the time since this frontend's last successful template refresh, or since start before the first.
  2. Monitoring gap. No existing rule could see this class of stall. The coverage rules (PrismSemanticWorkCoverageLoss*, PrismCurrentWorkGapHigh) compare each session with the latest published generation, never with the tip. When every refresh fails, that generation stays put, so coverage reads 1 for the whole stall.
    • work_refresh_metric asserts this for both a same-parent stall and a new-tip stall.
    • PrismAcceptedRevisionWorkPendingCritical only covers blocks this frontend saw accepted, and forgets them on restart.
    • Before this PR, any persistent refresh failure paged nowhere.

Findings

ID Lane Finding Disposition
adv-1 (major) adversarial The first gauge counted only after the observed tip departed from the published tip. A same-parent stall (dust on the 60 s re-anchor rebuild, readiness lapses, shares refused) read 0, and paged only after the next network block, or never. fixed in 5953d79: the gauge is now the time since the last successful refresh; the E2E test gains a same-parent phase
adv-2 adversarial A refresh that fails before its own tip observation (e.g. a database error), or with blockwait off, never started the clock. fixed in 5953d79 by the same redesign
cr-2 code-review Same as adv-2. fixed in 5953d79
cr-1 code-review self-check returned the pool-fee refusal before running its local checks. fixed in 5953d79: the local checks run first, then the refusal is returned
thermo-1 thermo The departed-and-unpublished predicate was duplicated from the lease code. fixed in 5953d79: the TipState clock is removed
thermo-2 thermo The mainnet-deployment pool-fee block split the walletless-broadcast lead-in from its example. fixed in 5953d79
thermo-3 thermo The non-CTV exposure was not tied to an issue. fixed: #535 is cited in .env.example, compose.yaml, PRISM.md, the guard's doc comment and its pinning test
thermo-4 thermo server.rs reached into observed_tip. fixed: Coordinator::work_refresh_age
thermo nits thermo Naming; the policy-transition fixture duplicated its fee; the "only symptom was a WARN" claim. fixed (the claim is corrected in the PR body; 31fe5b7's message is left as is to avoid a force-push)
adv-4 adversarial The doctor's disable cases could not fail with the process-environment override removed. fixed: a new env-file-enable / process-disable test fails with the override removed
thermo nit (doctor) thermo The doctor's CTV gate does not lowercase PRISM_CTV_SETTLEMENT_ENABLED, so True skips the whole CTV block. rejected for this PR: the pattern predates this change and applies to every existing CTV doctor check. The server still refuses at startup, and the new fee check itself matches the Rust parser
adv-3 adversarial If the shell exports PRISM_POOL_FEE_ENABLED="" over an env file that enables it, the doctor passes while Compose resolves 0. rejected: the failure is safe, because the server refuses at startup with the same message. Empty shell overrides are a pre-existing doctor limitation shared by PRISM_CTV_SETTLEMENT_ENABLED
bugbot bugbot No issues on 31fe5b7 or 5953d79. nothing to action

Verification of 5953d79

CI on 5953d79: green (21 pass, 1 skipped).

The first run had one shard failure: compact_runtime_e2e::issued_expiry_during_sql_wait_does_not_publish_or_renew_original_identity, with "proxy connection task failed" from the test's own SQL forwarding proxy. It is unrelated to this PR: 20 local runs passed, 10 on this head and 10 on 3.x.x, and the rerun passed. The coordinator is filing it.

🤖 Generated with Claude Code

@djh58
djh58 merged commit 4780552 into 3.x.x Sep 28, 2026
39 of 42 checks passed
djh58 added a commit that referenced this pull request Sep 29, 2026
…h setup to a 0-bps fee (#535) (#568)

* 3.x.x: require a pool fee in every settlement mode and default a fresh setup to a 0-bps fee (#535)

Without a pool fee, apply_payout_policy cannot settle sub-floor dust, so
the first positive balance below the payout floor fails every work build
and mining stops. #534 refused this only for CTV settlement; direct
settlement applies the same policy and was the default in .env.example,
compose.yaml and the load harness.

Config::ensure_pool_fee_settles_dust now refuses a pool without a fee in
both modes, naming the mode, the setting and the reason. run,
check-config, self-check and a policy-transition target refuse it; the
current side of a transition still reads a fee-less configuration, so
policy-transition remains the way to enable a fee on a cluster that ran
without one. make doctor mirrors the rule. PRISM_POOL_FEE_BPS=0 is still
allowed and pays nothing until dust must be swept. apply_payout_policy is
unchanged.

Defaults: compose.yaml enables the fee (rate unset, so 0 bps) but sets no
recipient, because the deploy role runs compose.yaml alone and renders an
address without a program; a recipient default there would put both
beside each other and every server would refuse to start. .env.example,
which a fresh setup copies to .env, enables a 0-bps fee to a synthetic lab
program (recipient dev-pool-fee) that nobody holds a key for, and
production refuses that program. The "exactly one address or program" and
"requires PRISM_POOL_FEE_ENABLED=1" messages now say what to set.

The load harness launches every frontend with the fee on; legacy presets
run it at 0 bps. A 0-bps fee adds no output until dust must be swept,
where a fee-off frontend would have stalled, so a run that completed
fee-off reproduces its results at 0 bps.

Tests: config unit tests and the pool_fee_guard CLI tests cover refusal
and acceptance in both modes (0 and 200 bps), the production refusal of
the lab program, and .env.example as a valid configuration in both modes;
doctor tests cover both modes and the .env.example defaults; the mainnet
compose contract renders compose.yaml as the deploy role does and checks
it names exactly one recipient. Every test fixture that launched a
fee-less server now runs a 0-bps fee.

Closes #535

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

* 3.x.x: keep compose.yaml's pool fee off by default, and check the fee recipient in make doctor (#535 review)

Review of the first commit found that compose.yaml's new
PRISM_POOL_FEE_ENABLED default of 1, with no recipient default, broke a
deployment that never set the flag. Such a deployment got the fee enabled
with an empty address and an empty program, so Config::from_env failed.
Every tool that reads the configuration failed with it, including the
current side of policy-transition, which is the documented way to enable
a fee. Compose cannot supply a recipient, so the default goes back to 0:
that deployment now gets the clear startup refusal, and policy-transition
still reads it. .env.example stays the valid fresh setup.

make doctor now also refuses an enabled fee with no recipient. In
production it refuses .env.example's lab program where no address replaces
it; an address beside the sourced lab program is left to the server, which
sees only what Compose passes. As with the flag, process-environment
overrides of the address and program apply.

Tests: policy-transition from compose's fee-off defaults (every fee
setting empty, the flag unset or 0, both modes) reads the current
configuration and accepts a 0-bps target; doctor tests for the missing
recipient and the production lab program. The 0-bps fixture now lives
only in tests/support/pool_fee.rs, which live_regtest and fatal_state
reuse.

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