Skip to content

3.x.x: alert on order and settlement advisory-lock waits (#461 S-C) - #463

Merged
kiwidream merged 3 commits into
3.x.xfrom
cutover-safety/lock-wait-alerts
Sep 22, 2026
Merged

kiwidream merged 3 commits into
3.x.xfrom
cutover-safety/lock-wait-alerts

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Part of #461 (S-C). Target 3.x.x, base pin 587aef59.

What

Two native alert rules for qbit_prism_database_advisory_lock_wait_seconds (recorded since #328, no rule until now — docs/prism-alert-migration.md:120), in docs/prism-native-alert-rules.json:

  • PrismDatabaseAdvisoryLockWaitHigh (warning): per-lock p99 over 5 m of lock=~"order|settlement" > 1 s, from ≥10 waits for that lock.
  • PrismDatabaseAdvisoryLockFailuresCritical (critical, page: "true"): per-lock result="failure" share > 5 % over 5 m, from ≥10 waits.

Both are gated on the snapshot-fresh gate used by the other cached-body families (Family::is_live excludes LockWait; api/metrics_snapshot/tests.rs shows it is served frozen from the cached body), not up == 1. lock="migration" is excluded and the description says why (taken only at schema initialisation; waiting out an online migration is expected). basis cites #271's 15/31/63 ORDER_LOCK waiters, the 5 s PRISM_DATABASE_LOCK_TIMEOUT_MS default, that no native percentile exists, and "provisional, measure in #291/#447".

Derived artifacts regenerated (generate_prism_alerts.py --snapshot against qbit-tools a007a142, sha verified): migration tables, prism-alert-rules-qbit-tools.patch. Hand-written prose corrected: the first-offer histogram exists as qbit_prism_block_submit_seconds (#391) and carries no firing rule because it yields one sample per found block (prism-alert-migration.md, prism-native-metrics.md, prism-alert-migration.json retired reasons). tests/observability/inventory.rs relaxes the "no rule on this family" assertion for the two uids only; the deployment test's rule count goes 62→64.

No metric, label or registration changes (src/metrics* untouched; #278).

Tests

14 new scenarios in tests/fixtures/prism-alert-scenarios.json: fires per lock, fast waits, migration-only waits, stale / unpublished / missing snapshot, both sides of the 5 % boundary, below the per-lock minimum, a failing lock that cannot borrow the other lock's samples, both locks breaching at once (value 2). Mutation checks (applied and restored): selector widened to lock=~".*" → migration scenario fails; snapshot gate dropped → stale scenarios fail; per-lock count gate collapsed to a shared minimum → borrow scenario fails (both rules); hand edit inside the generated table → generate_prism_alerts.py --check fails.

generate_prism_alerts.py --check --snapshot, test_prism_alert_promql.py (promtool 3.14.0; 30 expressions, 87 scenarios), test_prism_alert_deployment.py, generate_prism_metrics.py --check, cargo test --test observability, fmt, clippy, settings/gate/toolchain checks — all pass.

Not covered

Thresholds are provisional until #447/#291. promtool registers native rules as recording rules, so for/severity are not timing-tested (pre-existing). A hand edit inside the generated migration table is caught by generate_prism_alerts.py --check (run by the observability inventory test) but not by test_prism_alert_deployment.py, because specification_digest() does not hash the .md — pre-existing, one-line follow-up.

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

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@kiwidream

Copy link
Copy Markdown
Member Author

CI note: the shard-1 failure on 068ed0d9 was api_database::shared_database_serves_all_contracts_and_global_reward_ranks panicking in fixture setup (tests/api_database.rs:101, "canceling statement due to lock timeout" on the ledger connect), before any assertion. This PR changes no Rust runtime code (docs, fixture scenarios, the observability inventory assertion and the deployment test's rule count); the same test passes locally on this head (2/2) and shard 1 is green on #462 and #464 from the same base. Retriggering CI.

@kiwidream kiwidream closed this Sep 18, 2026
@kiwidream kiwidream reopened this Sep 18, 2026
kiwidream and others added 3 commits September 22, 2026 15:14
qbit_prism_database_advisory_lock_wait_seconds has been recorded since #328
with no rule attached, so a coordinator can sit behind the order or settlement
advisory lock indefinitely without anyone being paged.

Add two native rules. PrismDatabaseAdvisoryLockWaitHigh watches the per-lock
p99 over five minutes, and PrismDatabaseAdvisoryLockFailuresCritical pages on
the per-lock failure ratio, where failure also covers a wait abandoned by
cancellation. Both exclude lock="migration": that lock is taken only at schema
initialization, where waiting out an online migration window is expected
rather than a fault.

The family is rendered from the cached snapshot body rather than read live at
scrape time, so both rules carry the snapshot-fresh gate the other cached-body
rules use. A stale or unpublished body suppresses them instead of repeating an
old percentile, and the failure ratio stays absent rather than zero until a
first failure is observed, which is why no-data remains OK.

Fixture scenarios cover per-lock discrimination, the per-lock sample minimum,
migration-only waits, stale and missing snapshot series, and both sides of the
five-percent failure boundary. The inventory prohibition on this family is
narrowed to these two rule UIDs so no other rule can reach for it, and the
first-offer prohibition is untouched.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The migration narrative still said proof-to-first-offer waits were declared
with a rule deferred, and that advisory-lock waits had no rule written. Both
are now wrong: the first-offer histogram is instrumented as
qbit_prism_block_submit_seconds under #391, and the advisory-lock rules land
in this branch.

Say what is actually true. First-offer carries no firing rule because it is
observed at most once per found block, which is too sparse for a rate or a
percentile, not because a rule is pending. Name the two advisory-lock rules
and record that lock="migration" is deliberately outside them. The same
correction applies to the retired-name reasons, so the generated migration
tables and the review-only deployment patch are regenerated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Every sample-minimum scenario so far carried only result="success" series, so
PrismDatabaseAdvisoryLockFailuresCritical's ratio was absent and its >=10 gate
was never evaluated. Collapsing that gate to a shared minimum across both
locks therefore passed the suite untouched.

Add a scenario where a busy clean lock records 100 waits with no failures
while the other lock records two waits, one of them a failure. The ratio is
0.5 but the sample is two, so the per-lock gate drops it and the contract
value stays zero; a shared minimum would lend the clean lock's hundred waits
to the failing one and page. Add a second scenario where both locks breach on
their own samples, pinning the value at two for the percentile and the ratio
alike so neither rule may silently collapse two locks into one series.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kiwidream
kiwidream force-pushed the cutover-safety/lock-wait-alerts branch from 068ed0d to a6d10b3 Compare September 22, 2026 19:20
@kiwidream
kiwidream merged commit 8864996 into 3.x.x Sep 22, 2026
21 checks passed
djh58 added a commit that referenced this pull request Sep 22, 2026
Refs #493. Resolves the scenario fixture as a by-name union (the #463
advisory-lock scenarios plus this branch's landing cases) and regenerates
the deployment patch. The native paging-rule assertion now also covers
the #463 advisory-lock critical, which already satisfies it; the exact
set check becomes a subset check so new paging rules are covered rather
than listed.

Co-Authored-By: Claude Fable 5.1 <[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