Skip to content

3.x.x: measure ORDER_LOCK holds by holder and landing-window share acks, guard settlement's hold over appends, and alert on slow landings (#602) - #615

Merged
djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b602-measure
Sep 30, 2026
Merged

djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b602-measure

Conversation

@djh58

@djh58 djh58 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Refs #602. Step 1 of the plan: measurement and guard (R3, R4, R6, R7). No change to lock scope or settlement logic.

What changes

R3: ORDER_LOCK holds by holder. qbit_prism_database_order_lock_hold_seconds{holder} sits beside the existing wait histogram. Every ledger ORDER_LOCK acquisition now goes through Ledger::lock_order. It returns a guard that the holder keeps until COMMIT or ROLLBACK, so a hold runs from the grant of the lock to the end of the transaction. The guard's clock starts at the instant the wait ended, so the append path reads no extra clock.

holder transaction
append the share append (with a block-solving share's candidate bytes)
candidate_insert a block-only candidate's insert
first_confirmation the offering frontend's settlement that confirmed its block for the first time
settlement any other settlement, including an abandon
reconcile the reorg reconciler, which can also confirm a peer's block
orphan the orphan disposition
prepared the refresh's window snapshot that prepared work is built from
cleanup blob garbage collection
fatal_state fatal-state recovery
operator policy and signing transitions, archive verify and restore (when run with a registry)

The schema cutover's hold is not observed, because its caller owns and commits the transaction. Archive's statement-scoped append drain is not observed either, because it holds nothing past its statement. The ladder runs from 1 ms to 10 s, so #602's 250 ms budget is a bucket edge. The label set is closed and its keys are reserved at declaration, so the first observation allocates nothing. A source scan (every_order_lock_acquisition_records_its_hold) keeps every other acquisition on the helper and every guard bound until its transaction ends.

R4: landing-window share acks. qbit_prism_share_ack_landing_window_seconds{result} holds the share_ack_seconds observations whose submission arrived within 30 s after a pool block acceptance this frontend observed. An acceptance is its own submitblock acceptance, or a peer frontend's block on the active chain, seen either before it is confirmed or already confirmed at the tip. The second case matters: the regtest measurement showed a peer's settlement usually finishes before this frontend's reconciler looks. A buried block first seen confirmed, as after a restart, opens no window. The family uses the same ladder, so steady state is a subtraction. The window's end sits in an atomic: outside a window the Stratum path pays one atomic load, and the arrival instant it compares against is the one the ack's elapsed time already uses. No extra clock read.

R7: alerts. Each landing window gets a verdict 30 s after it stops admitting submissions. Its nearest-rank p99 is over a bound exactly when more than 1% of its acks took longer, and the process counts that exactly rather than reading buckets. qbit_prism_share_ack_slow_landing_windows{p99_above_seconds="2"|"10"} publishes the number of consecutive slow windows, and -1 before the first verdict.

rule severity condition
PrismLandingAckP99Slow ticket (no page) landing-window ack p99 > 2 s in three consecutive windows
PrismLandingAckP99High warning landing-window ack p99 > 10 s in the latest window
PrismPoolResubmissionRejectRatioHigh warning pool-wide duplicate-share + unknown-job + stale-job rejections > 5% of decisions over 5 min, at least 500 decisions, for 5 min

All three thresholds are provisional (#291). The promtool scenarios cover firing, pending, no verdict yet, reset, stale snapshot, low volume, other reasons and a frontend with a stale snapshot. The deployment patch is regenerated and the deployment test checks the new rules' severity, dwell and no-data states.

R6: guard. appends_commit_within_budget_while_a_settlement_is_held holds a real settlement open: a trigger sleeps 3 s inside the offering frontend's first-confirmation UPDATE. Meanwhile the other frontend runs 8 appends. It is an expected failure, following the #582 / #598 pattern. It passes while the appends wait for the settlement's COMMIT, and it checks that they were delayed by the held settlement, not by something else. Once they commit within #602's budget (no ack over 2 s, p99 at most 500 ms), it fails with "#602 looks fixed".

Measurement (#602 item e)

Measured on regtest and on the fake node with a 400k window, 2 release frontends, 100 sessions at 100 shares/s and 3 own blocks per run, on a loaded shared host (4 pinned cores). Full tables are in the #602 comment.

  • First confirmation holds ORDER_LOCK for 6-20 ms with 5-130 recipients and 38-42 ms with 2,600. It grows with accounts, not with the window, and stays well under R2's 250 ms.
  • Append holds average 1.5-3.8 ms (p99 ≤ 25 ms). Reconcile, prepared and cleanup each average ≤ 6 ms.
  • Landing-window ack p99 ≤ 50 ms, against ≤ 25 ms in steady state. No slow landing window.
  • The R6 guard shows the structural exposure is real: a settlement held 3 s delays every concurrent append by 3.00-3.04 s.

Tests

  • New gated tests in tests/b602_order_lock_hold.rs, listed in test/prism-gated-tests.txt:
    • a_landing_records_each_order_lock_hold_under_its_holder (R3)
    • acknowledgements_after_an_acceptance_are_read_in_the_landing_window (R4, over a real Stratum socket)
    • appends_commit_within_budget_while_a_settlement_is_held (R6)
    • plus the source scan, which is not gated
  • Unit tests for the landing-window verdict (metrics::landing_acks), with a paused clock.
  • The observability census, contract, cardinality, snapshot and allocation tests are updated for the three families.
  • Per-PR CI runtime added: about 7 s for the new binary's gated tests (3.0 s of that is the R6 hold), plus building and linking one more test binary.

Mutants, each run against the test that should catch it:

mutant caught by
hold recorded at the grant a_landing_records…: "is not a first_confirmation hold"
hold measured as zero a_landing_records…: "held ORDER_LOCK 0 s, outside [0.3, …]"
no first_confirmation relabel a_landing_records…
acceptance opens no window acknowledgements_after…: "…after its own acceptance is missing from the landing window"
a peer's block first seen confirmed at the tip opens no window acknowledgements_after…: "…after a peer's landing is missing from the landing window"
every ack counted as in a window acknowledgements_after…: "an acknowledgement with no acceptance was read as a landing window's"
settlement without ORDER_LOCK (a stand-in for the step-2 fix) appends_commit…: "#602 looks fixed: every append committed within 2s (slowest 45.8ms…)"
verdict at ≥1% instead of >1% landing_acks unit test
ticket after two windows promtool: "two slow landing windows in a row never ticket", "pending inside the ticket dwell"
warning reads the 2 s bound promtool: "three slow landing windows…", "one landing window over 10 seconds warns"
pool ratio drops unknown-job promtool: "…spread over frontends and reasons warn pool-wide"
pool ratio ignores snapshot freshness promtool: "a frontend with a stale snapshot is left out"

🤖 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.

…ks, guard settlement's hold over appends, and alert on slow landings (#602)

Step 1 of #602: measurement and guard, no behaviour change. Lock scope and
settlement logic are unchanged.

R3. qbit_prism_database_order_lock_hold_seconds{holder} records every
ORDER_LOCK hold, from the grant of the lock to the end of its transaction,
beside the existing wait histogram. Every ledger acquisition goes through
Ledger::lock_order, which returns a guard the holder keeps until COMMIT or
ROLLBACK. The guard starts from the instant the wait ended, so the append
path reads no extra clock. Ten holders: append, candidate_insert,
first_confirmation (the settlement that first confirmed its block),
settlement (any other, including an abandon), reconcile, orphan, prepared
(the refresh's window snapshot), cleanup, fatal_state and operator (policy
and signing transitions, archive verify and restore). The schema cutover,
whose transaction its caller commits, and archive's statement-scoped drain
are not observed. The ladder runs from 1 ms to 10 s. A source scan keeps
every other acquisition on the helper and every guard bound.

R4. qbit_prism_share_ack_landing_window_seconds{result} holds the
share_ack_seconds observations whose submission arrived within 30 s after a
pool block acceptance this frontend observed: its own submitblock
acceptance, or a peer's block on the active chain, seen before it is
confirmed or already confirmed at the tip. A buried block first seen
confirmed, as after a restart, opens none. It uses the same ladder, so
steady state is a subtraction. The window's end sits in an
atomic, so outside a window the Stratum path pays one atomic load, and the
arrival instant it compares is the one the ack's elapsed time already uses.

R7. Each window gets a verdict 30 s after it stops admitting submissions:
its nearest-rank p99 exceeds a bound exactly when more than 1% of its acks
did, counted exactly. qbit_prism_share_ack_slow_landing_windows
{p99_above_seconds="2"|"10"} publishes the consecutive slow windows, -1
before the first verdict. PrismLandingAckP99Slow tickets at three windows in
a row over 2 s; PrismLandingAckP99High warns at one over 10 s;
PrismPoolResubmissionRejectRatioHigh warns when duplicate-share, unknown-job
and stale-job rejections exceed 5% of the pool's decisions over five
minutes. Thresholds are provisional. The deployment patch is regenerated.

R6. A gated test holds a settlement open with a trigger that sleeps in its
first-confirmation UPDATE and appends from the other frontend meanwhile. It
is an expected failure: it passes while the appends wait for the
settlement's COMMIT and fails with "#602 looks fixed" once they commit
within #602's budget.

Refs #602

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

djh58 commented Sep 30, 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.

…racker, let a window settle past the next acceptance, and simplify the hold guard (#602)

Review follow-ups on the first commit:

- A landing window no longer depends on the revision-work tracker's
  insert. That tracker's saturation, retired-height and capacity limits
  would have stopped every later window and frozen the slow-window gauge.
  LandingAcks now de-duplicates by block height itself, and the three
  acceptance hooks call it directly.
- A later acceptance leaves the previous window settling, so its late
  (slow) acknowledgements count toward its own verdict instead of the next
  window's.
- lock_order reads the clock after lock() returns. The shared lock helpers
  keep their original signatures.
- Stratum and test acknowledgements share one recording path.
- The settlement-hold probe matches only this database's sleeping
  qbit_pool_blocks UPDATE.
- The source scan requires every explicit end of a hold to follow its
  COMMIT.
- The R4 test no longer refreshes before the offering frontend's ack,
  since the refresh's reconciler would open the window on its own.
- Docs: reconcile runs on every template build, and first_confirmation and
  settlement are counted per attempt.

Refs #602

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

djh58 commented Sep 30, 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.

…a reorg's replacement block opens its own (#602)

A reorg's replacement pool block at the same or a lower height is a new
settlement under ORDER_LOCK, but height de-duplication gave it no landing
window. LandingAcks now remembers the last 64 blocks that opened a window by
hash (case-insensitive), so the reconciler seeing a block this frontend
offered still opens nothing, and any other block opens its own.

Refs #602

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

djh58 commented Sep 30, 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 1dbb6ff. Configure here.

@djh58

djh58 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member Author

Review ledger at 1dbb6fff (CI green: 22 pass, 9 skipped)

Stakes: medium. This adds metrics, alerts and an expected-failure test only. Lock scope and settlement logic are unchanged.

Lane Result
/code-review medium (local, pre-PR) No bugs; one comment fixed.
Adversarial review (Claude) No refutation.
Maintainability review (Claude) No blockers; fixable items folded into the second commit.
Bugbot (high effort) 1 medium finding on the second commit, fixed in 1dbb6fff. Clean before that.
Cross-provider adversarial lane Not run: this change's review is limited to Claude models.
ID Finding Disposition
F1 Landing windows depended on the revision-work tracker; saturating it would freeze the landing-window gauge. Fixed: windows are de-duplicated independently of that tracker.
F2 A later acceptance closed the previous window before its late acks counted. Fixed: the previous window settles first.
F3 lock_order read the clock before lock(), changing the shared lock helpers. Fixed: the clock is read after lock().
F4 Two share-ack recording paths. Fixed: one path.
F5 The source scan did not assert that every drop(order) follows COMMIT. Fixed, with mutant M9.
F6 Bugbot: height-based de-duplication skipped a reorg's replacement pool block at the same or a lower height, which is a new settlement. Fixed: de-duplicated by block hash over a bounded set of the last 64. The metrics-level test covers the same block twice (one window) and a different block at H and at H-1 (a window each). The mutant that restores the height key fails it.
R1 A minimum sample count for the landing-window ticket. Rejected by the review lane; kept as is. The ticket fires on three consecutive slow windows, and this can be revisited once production data exists.
R2 Relabel the hold before COMMIT. Rejected: holds are per attempt by design, and relabelling would merge retries.

Measurements (posted on #602): at a 400k window with 2 frontends on a loaded host, first confirmation held ORDER_LOCK for 6–20 ms (38–42 ms at 2,600 recipients). Landing-window ack p99 was ≤ 50 ms, with no slow windows. The R6 expected-failure test shows the structural exposure: a 3 s settlement hold delays all concurrent appends by about 3 s.

Mutants: 8 code and 4 alert mutants, plus M8–M10 on the follow-ups, are all killed.

@djh58
djh58 merged commit eb3acb1 into 3.x.x Sep 30, 2026
31 checks passed
Anatolie added a commit that referenced this pull request Sep 30, 2026
Brings in #623's --faults (pinned null in every preset), #615's ORDER_LOCK
hold measurements and the other 3.x.x commits since 72efbcb/1932cb30.

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