Skip to content

3.x.x: attribute the current server's stale-job and unknown-job rejections to dense-cadence landings (#480) - #513

Merged
kiwidream merged 3 commits into
3.x.xfrom
harness-480-dense-attribution
Sep 24, 2026
Merged

kiwidream merged 3 commits into
3.x.xfrom
harness-480-dense-attribution

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Refs #480 (workstream A, #261; evidence from #447's dense runs). Harness only: crates/qbit-prism-load reporting and its tests. No server change.

The defect. The dense-cadence section attributed a rejection to a landing only when its message was new payout work is pending or new tip work is pending. The current server sends neither on the submit path: new tip work is pending survives only as an internal issuance error, which a submit that resumes a job answers as backend-rpc-unavailable. So every #447 dense run at D1/400k reported 0 attributed rejections, a null window and a 0.0 p99 rejections-per-landing while 16k–21k stale-job and 1.5k–3k unknown-job rejections occurred inside landing spans.

What a landing owns now (classify::landing_cost, README table): stale-job and unknown-job with the server's actual message stale job, plus the two legacy messages from older producers. Not owned, tallied beside the cost by reason_id: the backend refusals (backend-rpc-unavailable, ledger-confirmation-failed, ledger-outcome-unknown, internal-error), the fee-floor stale-job, pool-closed, the reason-less unknown-job budget refusal, and the harness-bug classes. An unrecognised stale-job/unknown-job message, or a reason the classifier does not know, makes that span's combined window, lost_valid_shares and rejected_before_new_revision_work null with a reason, and the #291 budget null with the reason (EP-OBSERVABILITY: an unknown is never 0.0). The recognised subset is kept as owned_count_lower_bound.

Same edge as #458. A span starts at the fake node's submitblock acceptance stamp and the new acceptance_to_new_revision_work_millis and proposed_budget.same_edge_as_issue_458 measure acceptance to the first clean_jobs notify, the edge of qbit_prism_accepted_block_to_revision_work_seconds; the clock offsets are documented.

Tests (tests/harness.rs): synthetic stale-job rejections inside and outside a span (counts per span, one unattributed, backend and fee-floor tallied not owned, a budget refusal inside a span leaves the cost measured); an unrecognised message yields null with a reason; a no-landing phase yields null, not 0.0, including a phase with stranded stale-job rejections; the classifier table against the server's messages.

Not covered. No live dense run was made against the fixed harness; the first criterion is proven on synthetic input. The harness cannot split stale-job by parent vs revision (the wire has no cause; the server metric does). The run-wide rejection_report keeps its legacy rebuild_pending flag, outside the dense section.

Verification. cargo fmt --all --check; cargo clippy --locked --workspace --all-targets -- -D warnings; scripts/check_gate_env_reads.py; scripts/check_prism_settings.py; cargo test --locked -p qbit-prism-load (130 harness tests). Written by a delegated worker; reviewed and re-verified by the coordinator.

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

kiwidream and others added 2 commits September 24, 2026 13:15
…tions to dense-cadence landings (#480)

The dense-cadence section attributed a rejection to a landing only for
`new tip work is pending` or `new payout work is pending`, which the server no
longer sends on the submit path. Every #447 dense run at D1/400k therefore
attributed none of its 16,461-21,504 stale-job and 1,512-2,997 unknown-job
rejections, all `stale job`, and proposed a p99 of 0.0 rejections per landing.

A landing now owns, inside its span, stale-job and unknown-job with
`stale job` as well as the two older messages. Backend refusals
(backend-rpc-unavailable, ledger-confirmation-failed, ledger-outcome-unknown,
internal-error), a fee-floor stale-job, pool-closed and harness-bug classes are
tallied by reason_id beside the cost, never inside it. A stale-job or
unknown-job message the harness does not know, or an unknown reason, is
unrecognised: the span's combined window, lost shares and
rejected-before-new-revision-work become null with a reason, and the #291
budget is null with its reason rather than a percentile over the rest.

Every budget number now carries its own unavailable reason, and a
same_edge_as_issue_458 block reports the acceptance -> new-revision-work count
and time, the edge qbit_prism_accepted_block_to_revision_work_seconds
measures. The README's dense-cadence section names the messages and classes
that count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ognised (#480)

stratum.rs refuses a submit with code 20, `too many unknown job
submissions` and no reason_id once a session has spent its unknown-job
budget. The classifier sent every reason-less message other than `too many
connections` to Unknown, so dense-cadence attribution made it Unrecognised,
and one such refusal inside a landing's span nulled that span's combined
window, lost shares and rejected-before-new-revision-work, and the #291
budget. D1/400k dense runs answer 1,500-3,000 unknown-job submits per run,
so the refusal can erase exactly the numbers #480 restores.

It is now Expected, and so NotOwned for a landing: a rate limit on job
lookups, not retired work. It is matched only on that exact shape (code 20,
no reason_id, that message) and tallied beside the cost under the existing
`(no reason_id)` marker. The classifier-table and span tests cover it, and
the README table and the section's counted_classes text name it.

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

chatgpt-codex-connector Bot commented Sep 24, 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-24T18:11:46.038664Z 62e0105 New commits
ℹ️ 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: 0502610ca3

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

Comment on lines +1056 to +1057
if let Some(worst) = acceptance_work.iter().copied().max_by(f64::total_cmp) {
target.acceptance_work_max.push(worst);

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 Use the first frontend delivery for the #458 edge

When a frontend has multiple sessions that receive the new-revision notify at different times, this stores the slowest session in acceptance_work_max and consequently publishes it as same_edge_as_issue_458.acceptance_to_new_revision_work_p99_millis. The server metric ends on the first successful notify write: revision_work_delivered in crates/qbit-prism-server/src/metrics/landing.rs suppresses subsequent deliveries for the same acceptance epoch and revision. Thus the new harness value does not measure the claimed same edge and can overstate it substantially; use the earliest acceptance_work value (the already-computed first_revision_work) for that proposed-budget distribution.

Useful? React with 👍 / 👎.

@kiwidream kiwidream left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review by a delegated agent on behalf of workstream A (head 0502610).

Verdict: request changes. The change is limited to the new same_edge_as_issue_458 block and the README text that describes it. The core #480 fix is correct: the message table matches every stale-job, unknown-job and reason-less code-20 refusal the server can send on the submit path. Spans tile the phase, unattributed is exact, and the null semantics hold everywhere else.

Findings

Medium: the "same edge as #458" number is a different statistic, and the README's offset text is wrong

crates/qbit-prism-load/src/cadence.rs:1057 (also :971, :1457, :1479; crates/qbit-prism-load/README.md:354-364)

  • Statistic. qbit_prism_accepted_block_to_revision_work_seconds records one sample per block per frontend. That sample ends at the earliest successful mining.notify write at revision ≥ target on any session of that frontend: Landing::resolve in crates/qbit-prism-server/src/metrics/landing.rs does min_by_key(at) over the frontend's deliveries. The harness does something different. It collects one acceptance_work value per session, pushes the per-table max into acceptance_work_max (cadence.rs:1057), and publishes the p99 of those maxima as same_edge_as_issue_458.acceptance_to_new_revision_work_p99_millis. So the harness figure includes the notify fan-out across every session on the frontend, and the server's figure does not. The same block's other number, rejected_before_new_revision_work, already stops at the earliest session (first_revision_work is a min), so the two "same edge" numbers use different end points. The new test pins the max: tests/harness.rs:9253 expects 2_400.0, which is session 3 at 9.4 s. The server-comparable reading is session 2 at 9.0 s, 2_000.0.

  • Start offset. The README (:362-365) and the clock_note say the server "starts its histogram when the frontend classifies the submitblock reply", so its number "sits inside the harness's by one RPC reply and one notify transit". In fact accepted_block is called at two points:

    • On the submitting frontend, at the end of observe_candidate (coordinator.rs, after land_offered returns). That is after ready_chain_info, ledger.observe_chain_view, getblockhash, getbestblockhash and ready_tip.
    • On every other frontend, from reconcile, when that frontend discovers the tip itself. The registry help says so: "each frontend samples every block from its own observation".

    The server's start therefore trails the node's submitblock stamp by several RPCs and a ledger round-trip on the submitter, and by tip-discovery latency on the other frontends. It is not one reply transit. The direction is right (the server's interval is shorter than the harness's). The attribution of the gap is wrong, and a reader who reconciles the two p99s would put fan-out and observe latency on "transit".

  • Failure scenario. Take a #447-shaped dense run: 400k sessions over several frontends. The harness reports acceptance_to_new_revision_work_p99_millis as the time until the last session on a frontend got its notify, plus up to one tip-discovery delay per non-submitting frontend. The server histogram reports first-write-per-frontend. A #291 or #458 reader told these are "the same edge" will see a large gap and read it as either a harness or a server defect.

  • Fix. Publish the per-table min of acceptance_work (the earliest session) as the #458-comparable figure. Keep the max beside it, named as fan-out. Rewrite the start-offset sentence to name observe_candidate (submitter) and reconcile (other frontends).

  • Test that would catch it. In stale_job_rejections_inside_a_span_are_the_landings_and_outside_are_unattributed, assert same_edge_as_issue_458.acceptance_to_new_revision_work_p99_millis == 2_000.0, from the earliest session (session 2 at 9.0 s). Today it is 2_400.0.

Low: #447's exact shape — landings present, no owned rejection — is untested

crates/qbit-prism-load/src/cadence.rs:1445 (the window_p99 empty reason)

  • The README says a 0 count from landings whose spans held no owned rejection "is a measured zero". That is the shape that produced #447's 0.0. The path only returns a count of 0.0 with a null window and the "no landing's span held a rejection the landing owns" reason. No test exercises that path. The no-landing test (tests/harness.rs:8712) says "the count was the field that read 0.0 in #447", but the base already reported null for the no-landing case. The assertions that fail on the base in that test are the new *_unavailable_reason keys, not the null.
  • Test that would catch a regression. Build a current_vocabulary_document-style fixture whose spans hold only not-owned rejections. Assert rejections_per_landing_per_frontend_p99 == 0.0, window_p99_millis == null, and that the window reason is present.

Low: shares_found_in_postgres stays a number when shares is null

crates/qbit-prism-load/src/cadence.rs:1327

  • When unrecognised_in_phase > 0, lost_valid_work.shares is null, but shares_found_in_postgres is still a number (for example 0), computed over shares_recognised only. Unrecognised rejections are never checked against PostgreSQL. split_note still says shares_found_in_postgres "is checked over" shares. This is not a regression (the base did not check them either), but 0 next to a null shares reads as a clean durability pass over the whole phase.
  • Fix. Say "checked over shares_recognised". Alternatively, add the unrecognised share IDs to the Postgres check, since the report already holds their share_id.
  • Test that would catch it. In an_unrecognised_message_in_a_span_makes_the_landings_cost_null_with_a_reason, put the unrecognised share's ID in committed and assert that the report surfaces it.

Low: the acceptance-to-work p99 is nulled by an unrecognised rejection it does not depend on

crates/qbit-prism-load/src/cadence.rs:1457

  • blocking nulls every number in the budget block, including acceptance_to_new_revision_work_p99_millis. That figure is a notify timing and does not depend on which rejections a landing owns. A single unexpected message in a run therefore throws away the #458 comparison too. Nulling the cost numbers is right. Nulling the timing is conservative but loses a valid measurement.
  • Test that would catch it. In the unrecognised-message test, assert that acceptance_to_new_revision_work_p99_millis is still measured.

Low: README and side-report leftovers

  • crates/qbit-prism-load/README.md:843 still lists "the five count distributions in the dense section". This PR adds stale_job_rejections_per_landing and unknown_job_rejections_per_landing, which also carry "unit": "count", so there are now seven.
  • crates/qbit-prism-load/src/run.rs:2754 (outside the diff): the run-wide rejection table's rebuild_pending flag still uses classify::is_rebuild_pending, which knows only the two older messages. On the current server, every stale-job / stale job row there reads rebuild_pending: false, while the dense section owns the same rejections. Either key it on landing_cost(..).owned() or rename it to say "older-producer message".
  • crates/qbit-prism-load/README.md:258: "A landing owns the rejections, inside its span, of work it retired". Attribution is by time, not lineage. A share on work retired by landing N-1 but answered after landing N's tip change goes to N. An unknown-job means the ID left both the live list and the retained graveyard (stratum/retained_jobs.rs: cap and TTL), which any job churn can cause. Suggested wording: "owns the rejections of retired work answered inside its span". No test needed.

Answers to the six questions

  1. Message table vs the server: matches. Here is every submit-path refusal:

    • stale-job / stale job: miner_submit.rs:287 (stale_job: ParentGrace/PayoutRevision), :339, :472, :532; tip_observation.rs:763 (lease proof); stratum.rs:1541 (ResumeExpired).
    • stale-job / job CTV fee is below the current relay floor: miner_submit.rs:318.
    • unknown-job / stale job: stratum.rs:1530.
    • Reason-less code 20: too many unknown job submissions (stratum.rs:1516, submit). The authorize path also has too many authorization attempts (:1247) and too many connections for username (:1301).

    new tip work is pending survives only as an ensure! anyhow error (tip_observation.rs:627). The resume path maps it to backend-rpc-unavailable / job resume unavailable (coordinator.rs:2925), and a non-StratumError from dispatch closes the session without writing a response, so it can never reach the wire. Every submit-path pair maps to the intended LandingCost. too many authorization attempts would classify as Unrecognised, but it can only answer mining.authorize, not a submit, so no span goes null on it. The README table is consistent with landing_cost.

  2. Span attribution. Spans run over the half-open interval [tip.monotonic, next.tip.monotonic), and the last one runs to phase_ended. They are sorted by the fake node's pool tip stamp on the harness monotonic clock and tested against the client's response-read instant (record.responded). They tile the phase, so a rejection cannot be counted in two spans. A rejection before the first span, or at or after phase_ended, is unattributed. Tables are per FrontendHealth, one per frontend child (run.rs:1309), so there is no double counting across frontends. unattributed = owned_in_phase − attributed is exact. The saturating_sub can never trigger.

  3. Null semantics. Every null added in the per-landing tables, lost_valid_work and proposed_budget_for_issue_291 has a sibling reason. owned_count_lower_bound counts only recognised-owned rejections, so it is ≤ the true owned count. Two exceptions are covered above: the shares_found_in_postgres labelling, and the untested measured-zero path.

  4. Same edge as #458. The harness start is TipChange.monotonic, stamped in the fake node's advance(), inside submitblock, before the reply. The harness end is the client's read of the first clean_jobs notify at or after the sampler's bump observation, per session. The server start is accepted_block after observe_candidate (submitter) or reconcile (other frontends). The server end is the socket write of the earliest delivery at revision ≥ target on the frontend. The README's offsets are wrong on the start side and on the statistic (see the Medium finding). A pre-existing caveat still applies: the end is bounded below by the bump sampler (25 ms interval plus a DB read), so a new-revision notify written before the sampler saw the bump is missed.

  5. Tests. None of the three compile on the base (landing_cost, LandingCost, STALE_JOB and UNKNOWN_JOB_BUDGET are new). Reasoning from the base code:

    • stale_job_rejections_inside_a_span… would fail for the stated reason: the base finds 0 rebuild-pending rejections, not 6.
    • an_unrecognised_message… would fail for the stated reason: the base counts combined as 0, not null.
    • The no-landing extension's null assertions already held on the base. Only the reason keys and the stranded sub-case (1 owned, unattributed) are new behaviour.
    • The acceptance_to_new_revision_work assertions pin the max statistic (see the Medium finding).

    I did not run these tests against the base.

  6. Compatibility. All existing keys are kept. lost_valid_work.shares and the per-table lost_valid_shares can now be null. I found no consumer in crates/, scripts/ or docs/: run.rs::dense_cadence_report passes the document through, report.rs does not read the section, and validate_capacity_evidence (qbit-prism-server/src/capacity.rs, qbit-prism-load/src/artifact.rs) does not read dense_cadence. docs/prism-throughput-measurements.md mentions dense_cadence only for the phase-start refusal. There is no compatibility finding.

Command log (on minidev-alex1, at the PR head)

  • cargo build --locked -p qbit-prism-load: passes.
  • cargo clippy --locked -p qbit-prism-load --all-targets -- -D warnings: passes, no warnings.
  • cargo test --locked -p qbit-prism-load: passes. tests/harness.rs 130 passed, 0 failed; tests/quorum_replication.rs 1 passed; lib, bin and doc 0 tests.
  • python3 scripts/check_gate_env_reads.py: passes ("no direct reads … in 317 Rust files").
  • Not run: the new tests against the base 6575f595; the gated test/prism-native-tests.sh suites (the server is untouched); any live dense run.

…urability checks null (#480 review)

The same_edge_as_issue_458 block published the p99 of each landing and
frontend's latest session's acceptance -> new-revision-work time. The
server's accepted_block_to_revision_work_seconds ends at the earliest
delivery on the frontend (Landing::resolve, min_by_key), so the comparable
figure is the earliest session's. acceptance_to_new_revision_work_p99_millis
now takes the per-table min, and the per-table max is published beside it as
acceptance_to_new_revision_work_with_fanout_p99_millis. Both are notify
timings, so an unrecognised rejection no longer nulls them; only a run with
no landing does. The clock_note and the README name where the server's start
really is: the end of observe_candidate on the submitting frontend, and
reconcile's tip discovery on the others.

lost_valid_work.shares_found_in_postgres is null with a reason when shares
is null, and a table's lost_valid_shares_found_in_postgres is null when its
lost_valid_shares is. The checks that were made are published apart,
including a new lookup of the unrecognised rejections' shares.

A test covers #447's exact shape: landings whose spans held no owned
rejection report a measured 0 count and a non-null budget, and a null window
with its reason. The run-wide rejection table's rebuild_pending flag now uses
the dense section's ownership test. The README states that attribution is by
time, not lineage, and lists all seven count distributions.

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

Copy link
Copy Markdown
Member Author

Addressed in 62e0105a (one commit on top of 0502610c), per finding:

  • Medium, same edge as 3.x.x: Landing-phase metrics — time from block acceptance to new-revision work, with the alerts 2.x.x had #458: same_edge_as_issue_458.acceptance_to_new_revision_work_p99_millis is now the p99 of each landing and frontend's earliest-session value, matching Landing::resolve's min_by_key; the latest-session value is published beside it as acceptance_to_new_revision_work_with_fanout_p99_millis, and the summaries carry min as well as max. The clock_note and the README start-offset text now say the server starts at the end of observe_candidate on the submitter (after ready_chain_info, observe_chain_view, getblockhash, getbestblockhash, ready_tip) and from reconcile's tip discovery on the other frontends. The span test asserts 2,000 ms (min), 2,400 ms (fan-out) and that the note names observe_candidate.
  • Low, 3.x.x: Run the D1 production-window load matrix (200k/400k/500k) that #271 could not #447's shape: new test landings_whose_spans_held_no_owned_rejection_report_measured_zeros (two landings, only not-owned rejections in the spans → measured zeros, null window with its reason, non-null same-edge figures).
  • Low, shares_found_in_postgres: null with shares_found_in_postgres_unavailable_reason when shares is null; the recognised and unrecognised share IDs found in PostgreSQL are reported separately, with a sample, from a lookup of the unrecognised rejections' share IDs. The per-table field follows the same rule.
  • Low, timing nulled: the acceptance and fan-out p99s use their own timing closure, nulled only by a no-landing run; the unrecognised-message test asserts they stay measured.
  • Low, leftovers: the README's count-distribution list and the ownership sentence are corrected; attribution is stated as by time, not lineage.

Verified locally: fmt, clippy -D warnings, cargo test -p qbit-prism-load (131 harness tests).

@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: 62e0105af2

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

// The dense section's ownership test, so this table and its
// rebuild_pending_rejections_in_phase agree on the current
// server's `stale job` answers (#480).
"rebuild_pending": classify::landing_cost(&rejection).owned(),

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 Preserve the rejection report's legacy rebuild flag

For any run containing the current server's stale-job or unknown-job / stale job responses, this now emits rebuild_pending: true, although classify::is_rebuild_pending still defines that run-wide flag as the two explicit legacy pending messages and its test confirms stale job is false. This changes the meaning of the general rejection report outside the dense-cadence attribution section and can make consumers treat retention or unknown-job refusals as explicit rebuild-pending responses; keep is_rebuild_pending here and reserve landing_cost for the dense report.

Useful? React with 👍 / 👎.

@kiwidream
kiwidream merged commit 3f5fd4c into 3.x.x Sep 24, 2026
21 checks passed
@kiwidream
kiwidream deleted the harness-480-dense-attribution branch September 24, 2026 18:34
djh58 added a commit that referenced this pull request Sep 25, 2026
Brings in #470, #512, #513, #514 and #515. #515 opens the share append's
transaction through AppendConnection::begin, which records BEGIN completion
so that a future cancelled before the reply retires the connection instead
of returning it to the pool; this branch opens the same transaction with
"BEGIN; SET LOCAL plan_cache_mode = force_generic_plan" so the share_id
probe is planned once per connection.

Resolution keeps both: AppendConnection::begin takes the opening statement
and the append passes APPEND_TRANSACTION_BEGIN. SQLx reads every reply of
that simple query through its ReadyForQuery before begin returns, so the
guard records completion only once the whole batch is in.

ledger_cancelled_begin now cancels the append on the custom BEGIN, and a
new case holds only the batch's closing ReadyForQuery (the execution proxy
gains pause_statement_ready) and proves the connection is still retired.
The pool-acquire inventory, the gated-test manifest and the #482 ops notes
follow the new call sites.

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