Skip to content

3.x.x: landing-phase metrics for #458 (durable-state observation, alternative to #475) - #494

Closed
kiwidream wants to merge 11 commits into
3.x.xfrom
landing-phase-metrics-458
Closed

kiwidream wants to merge 11 commits into
3.x.xfrom
landing-phase-metrics-458

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Refs #458.

Adds the landing-phase boundary 2.x.x exported and 3.x.x did not, as three registry families and two alert rules, with no change to landing, refresh, Stratum or deadline behaviour:

  • qbit_prism_accepted_block_work_publication_seconds{result=published|superseded}: from the durable accepted-offer time (qbit_block_candidate_outbox.offered_at_ms, the offering frontend's clock before its one submitblock) to this frontend's first publication whose payout revision includes the block's landing. Observed after the fact, once per block per process, in publication order, with the published revision revalidated against the cluster's in the same snapshot. Every frontend samples, not only the one that offered. Adopted blocks carry no offer time and yield no sample.
  • qbit_prism_accepted_block_oldest_unpublished_seconds: derived from durable rows on every health tick, so a restart cannot forget a hold; counts landed rows only (unlanded and lost-race rows belong to the existing candidate gauges); -1 until this frontend first publishes the cluster revision, on read failure, budget overrun or clock skew.
  • qbit_prism_stale_payout_revision_job_refusals_total: job builds refused in build_job's admission because this frontend's published payout revision differs from the cluster's; publication-stamp races and lease refusals are not counted.
  • Rules: PrismAcceptedBlockWorkPublicationStalled (critical, paging, gauge > 120 s for 1m; dwell deliberately shorter than the 5m that made the coverage page fire only at recovery in PRISM: an orphaned own block stalls job delivery for ~300 s on every lost tip race #413) and PrismStalePayoutRevisionJobRefusals (warning, non-paging, any increase in 10m; 3.x.x: Cutover qualification — migration rehearsal, failover drill, soak, go/no-go #291 sets the paging rate). The five no replacement migration rows flip to migrated through the generator; rows 202/205 of the deleted-test map name the native tests.

Verification on the head: fmt, clippy -D warnings, the gate/settings/toolchain checks, both generators --check, promtool (79 scenarios), the deployment test (78 -> 64 rules, 26 deletions), observability/allocation/census tests, the named database targets and the CI explicit database targets, all on disposable PostgreSQL 16.15. Mutation checks M1-M7 from the issue plan are each caught by a named test. Census: exactly three new families, one closed label enum, 47 -> 50 families.

Status: rebased onto 3.x.x at 9b6caedf after #475 landed a different implementation of the same boundary. Both family sets now coexist: the census tests assert 54 families (51 from 3.x.x plus these three), the five migration rows keep #475's mapping and these two rules are additional, and the generated inventory, migration table and qbit-tools patch are regenerated on the rebased tree (78 -> 67 proposed rules). The review of #475 against this branch's adversarial findings is filed as #493. Not covered: no qbitd on the verification host (live_regtest not run locally), thresholds provisional pending #291/#447, adopted blocks yield no histogram sample.

🤖 Generated with Claude Code

kiwidream and others added 11 commits September 18, 2026 15:23
…n families (#458)

Add three #458 families to the registry with typed observe methods:
the lazy accepted_block_work_publication_seconds histogram by a closed
published/superseded result, the accepted_block_oldest_unpublished_seconds
gauge (registered at -1, unknown before observation) and the
stale_payout_revision_job_refusals_total counter (registered at 0).
Nothing records them yet. Pin the census, cardinality, deferred-histogram
and allocation contracts for the new series.

Co-Authored-By: Claude Opus 5 <[email protected]>
Feed the #458 families from observation-only call sites:

- After refresh_once's publication returns, capture the published payout
  revision and the wall clock and spawn a detached task. It reads the
  cluster revision and every accepted outbox row offered since process
  start in one read-only statement, records nothing if the cluster has
  moved past the published revision, and otherwise samples each landed,
  unsampled row once per process: the newest landing as published, older
  ones as superseded. A negative cross-host interval is skew and is
  dropped with a warning.
- publish_health recomputes the oldest-unpublished gauge from the same
  durable rows every tick, bounded at one second; a failed or overrun
  read is -1, never zero.
- build_job counts the stale payout snapshot refusal it already makes.

A row is landed when it is terminal submitted or chain reconciliation
confirmed its pool block first: reconcile_blocks_in confirms and bumps the
revision in one transaction while the outbox row is still unfinished.
Adopted rows record the unknown outcome and are never read.

Co-Authored-By: Claude Opus 5 <[email protected]>
Add the database-gated accepted_publication_latency target on the
scripted node: an accepted landing is sampled once from its durable
offer time at the publication that carries it; an unlanded or adopted
row is never sampled; the pending age rises across ticks and a failed
refresh, survives a second acceptance and reads -1 when its read fails;
two landings before one publication record one published and one
superseded sample; a publication the cluster moved past records nothing
until the next one; and the stale-revision counter follows only the
build_job refusal. Each test prints its samples before asserting.

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

A frontend restarted in the middle of a landed but unpublished hold read
0, because the gauge shared the histogram's process-start bound. Keep
that bound for the histogram (a restart must not sample twice), but read
every retained accepted row for the gauge. A row is covered when this
process sampled it, or when it is landed and the snapshot's cluster
revision equals the revision this frontend publishes; otherwise it stays
pending, which is the truthful behind state, restarts included. Covered
rows are remembered in process, so an unrelated later bump does not
count an already published landing as waiting again.

Add a restart test: a second process started mid-hold reports the
hold's age, reads 0 once it publishes the cluster revision, records no
sample, and stays 0 across an unrelated revision bump.

Co-Authored-By: Claude Opus 5 <[email protected]>
- The pending gauge counts landed rows only. An accepted block that never
  landed (offered, reconciliation, a lost race awaiting its orphan proof)
  belongs to the candidate gauges and no longer holds it up.
- The gauge is unknown until this process sees one tick at which its
  published revision equals the cluster's. That tick covers every landing
  then retained, so a restart never reports the age of history it cannot
  attribute. After it, only landings not yet covered count.
- The stale-revision counter moves to the one branch that refuses because
  the work's payout revision is not the cluster's. It counts only inside
  build_job's first admission (a task-local scope), never a publication
  race, an unselectable lease, a resume or a repair. Control flow and error
  text are unchanged.
- Publication observations run in order: refresh enqueues, and one drain
  task observes first in, first out. A block's sample always ends at the
  earliest publication that carries it.
- The remembered sampled and covered sets are pruned to the rows the
  latest read still returns.
- Add a test-only seam between reservation and publication in
  refresh_once, and unit tests for the queue order, pruning, the seeding
  rule, unlanded rows and a skewed histogram interval.

Co-Authored-By: Claude Opus 5 <[email protected]>
Rewrite the restart test to the seeding rule: a restarted frontend reads
unknown until it publishes the cluster revision, then zero; a later
unpublished landing is the hold, rising and not reset by a second
landing, and it returns to zero at the publication that samples both.
Add a real lost-race test, which is never pending or sampled, and a
queued-order test showing a block's sample ends at the first
publication's instant. The unlanded and second-acceptance cases now
expect unlanded rows not to count. Register the new gated tests and the
database-backed publication seam test.

Co-Authored-By: Claude Opus 5 <[email protected]>
Add the two native rules for the landing-phase families (#458): a paging
rule on the per-frontend oldest-unpublished gauge with a one-minute dwell,
so the page fires during a landed-but-unpublished hold rather than at
recovery as in #413, and a paging rule on stale-payout-revision job
refusals, which replace the 2.x.x parent-preview wait timeouts and the
degraded-publication rule native has no path for.

Move the five deployed preview-publication and parent-preview-timeout
alerts from no-replacement to migrated, point the two retired 2.x.x
families at the native names, update the disposition counts, and add
promtool scenarios for fire, healthy zero, unknown -1, stale snapshot and
scrape gap. A new inventory assertion keeps any rule on the
oldest-unpublished gauge under the five-minute dwell that made #413
visible only at recovery.

Co-Authored-By: Claude Opus 5 <[email protected]>
Rendered from the frozen a007a142 template with the updated rule and
migration specifications; the generator and deployment checks pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
Annotate the three #458 registry families in the metric metadata and
regenerate the inventory: the publication histogram replaces the 2.x.x
preview-publication histogram, the stale-revision refusal counter
replaces the parent-preview wait timeouts, and the oldest-unpublished
gauge documents its -1 unknown cases. Describe each family's boundary,
clocks and at-most-once sampling in the metric guide, point the two
rules' producer references at the registry, label and publication
lines, and regenerate the migration tables and review patch.

Co-Authored-By: Claude Opus 5 <[email protected]>
Move tests/test_prism_issue_224_landing.py and
tests/test_prism_accepted_preview_publication_latency.py from needs
triage to partial, naming the accepted-publication tests that assert
their surviving behaviour and what stays uncovered or retired; drop
both from the needs-triage section and adjust the summary counts.

Co-Authored-By: Claude Opus 5 <[email protected]>
The oldest-unpublished gauge now counts landed rows only and reads
unknown until the process first publishes the cluster revision; say so
in the rule, metadata and guide, and point unlanded accepted blocks,
including lost races awaiting orphan proof, at the candidate gauges.
The refusal counter counts only build_job's first-admission refusal on
a revision mismatch, and its rule becomes a warning without a page
label: refusals also occur routinely between a landing's revision bump
and a non-offering frontend's next refresh, and #291 sets the critical
rate. Record publication-order sampling and set pruning for the
histogram, update the migration reasons and scenario names, repoint the
producer references and deleted-test-map citations, and regenerate the
inventory, migration tables and review patch.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-22T17:14:14.243921Z 98d0f3e PR opened
ℹ️ 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.

@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: 98d0f3e215

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

// Abandoned and orphaned rows are the failure-terminal
// set: they never land a revision, so they are neither
// measurable nor pending.
settled_without_landing: matches!(state.as_str(), "abandoned" | ORPHANED_STATE),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep reactivated orphan rows observable

Do not permanently classify every orphaned row as having settled without landing. Ledger::reconcile_blocks_in can later move that row's inactive pool block back to confirmed and bump the payout revision after a reorg; this query then returns landed = true but also settled_without_landing = true, so both the pending-age gauge and publication histogram filter out the newly landed accepted block. The same exclusion can lose a sample when a block was briefly confirmed before its candidate was terminally orphaned.

Useful? React with 👍 / 👎.

FROM qbit_prism_cluster c \
LEFT JOIN qbit_block_candidate_outbox o \
ON o.offer_outcome='accepted' AND o.offered_at_ms IS NOT NULL \
AND ($1::bigint IS NULL OR o.offered_at_ms>=$1) \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid filtering cross-host offers by the local start clock

Use a boundary that is comparable across frontends instead of applying this process's wall-clock start directly to another host's offered_at_ms. For example, if this frontend starts at local time T while the offering frontend is one second behind and accepts a block during that first second, the row's timestamp is less than T and is permanently omitted from every histogram observation on this frontend, even though the code explicitly permits clock disagreement between hosts. A database-clock boundary or initially captured hash set would preserve the intended per-frontend samples without relying on synchronized clocks.

Useful? React with 👍 / 👎.

@kiwidream

Copy link
Copy Markdown
Member Author

Closing as superseded by #475 (7089a17d, merged 2026-09-21), which implemented the #458 boundary; #458 closed on 2026-09-22 on that implementation plus #495's map row.

This PR was rebased after #475 landed and, as its description says, would ship a second, parallel set of landing-phase families and alert rules for the same boundary. That is not something to merge, whatever CI would say.

What this branch did differently and is worth keeping is already filed as review findings on #475 in #493: the oldest-unpublished gauge derived from durable rows rather than process-local tracking (#493 item 4, exactly-once across a restart), and the unknown-state handling (#493 item 5). The two open review threads here (reactivated orphan rows becoming invisible; cross-host offers filtered by the local start clock) apply to any durable-row design and should be carried into whichever PR addresses #493.

Branch head at close: 98d0f3e2.

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