Skip to content

3.x.x: answer a share whose commit gate closed for unavailable authority as backend-rpc-unavailable, not ledger-confirmation-failed (#716) - #718

Merged
RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/716-authority-unavailable-answer
Oct 6, 2026
Merged

RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/716-authority-unavailable-answer

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Refs #716

Why. A share admitted under a published-work lease checks that authority again just before COMMIT, while the append holds ORDER_LOCK. The check uses non-blocking try_reads on the frontend's publication authority. During a tip change, the tip poll, a fee or readiness write, or the publication itself can hold or queue for those locks, and then the gate closes as AuthorityUnavailable. The same closure covers readiness or a tip observation that lapsed or changed. Until now that closure was answered ledger-confirmation-failed, "share was not committed because its commit gate closed".

Nothing is written, so the ledger is fine. But ledger-confirmation-failed is what PrismShareAppendFailures counts, so the alert fired at tip changes under load. N2's D1 run on the pair at rc.1 saw 4 such refusals in 500/s for 300 s across 7 tip changes, and the alert fired.

What changes for miners. The closure that won the gate decides the answer:

  • StaleAuthority, where the lease expired or its publication was replaced, stays stale-job.
  • AuthorityUnavailable is answered as admission answers readiness it cannot prove, with message "current chain state is unavailable".
  • A deadline closure, and a refusal that records no closure, stay ledger-confirmation-failed. In production the deadline answers before this classification, with "share was not confirmed by the database", which is also unchanged.

The numeric code stays 20, so Stratum clients see only the reason ID and message change.

The deadline race (Codex's P2):

  • A lease fence can close the gate at the pre-COMMIT hook while the append's ROLLBACK is still in flight at the acknowledgement deadline.
  • gate.close() also reports an already-closed gate, so the deadline path used to abort the append and answer its own ledger failure. That applied to a proven stale lease too.
  • The deadline path now asks the gate which closure won it. Both paths share closed_gate_outcome().

Metrics and alerts:

  • PrismShareAppendFailures matches reason_id=~"ledger-confirmation-failed|ledger-outcome-unknown" (docs/prism-native-alert-rules.json), so this case no longer fires it.
  • These refusals now count under qbit_prism_rejections_total{reason_id="backend-rpc-unavailable"}, or backend-database-unavailable as above. Only the reject-ratio rules watch those reasons, at 5% of decisions; a handful of refusals per tip change doesn't come close.
  • The INFO line share commit gate refused before COMMIT now has a closure field, and is logged where the closure is known.
    • authority-unavailable within seconds of a tip change is the contention case. Away from tip changes it is a readiness loss.
    • A WARN share persistence failed is still the real ledger failure.
  • docs/prism-rejections.md describes the cases under "Commit-gate refusals". The reason table and the metric inventory list this new source of both reasons.

What stays strict:

The load harness needs no change. qbit_prism_load::classify already counts both reasons as backend refusals, as it does ledger-confirmation-failed, and the live session-load test already expects them.

Tests:

  • commit_reconcile_each_gate_closure_keeps_its_own_answer drives each closure through submit with the memory ledger.

    • A test-only knob makes the pre-COMMIT hook refuse with a given closure, or with none. The unspecified refusal keeps the duplicate check, as production's hook does.
    • It pins the wire answer for all four closures, plus the database case, with no record, no credit and no WARN.
    • It checks the INFO line's closure label.
  • commit_reconcile_a_fence_closure_keeps_its_answer_when_the_rollback_outlasts_the_deadline holds the refused append's rollback past a 300 ms deadline. Both fence closures keep their answers, and the append is aborted. Against the old deadline path it fails with "share was not confirmed by the database".

  • Three authority_lease tests pinned the old answer for this closure: a changed readiness epoch, an aged tip observation, and the lock-contention and unknown-readiness matrix. They now expect backend-rpc-unavailable. The matrix's held readiness write lock is what showed the answer must not re-read readiness.

  • candidate_window_qualification's phase-B allowance after the tip move also accepts the gate's new answer. By design that answer is admission's too, so the comment notes that the wire can't tell the two apart there.

  • Local runs, without a database:

    • the coordinator:: lib tests: 341 of 341 passed;
    • clippy with -D warnings, cargo fmt --check and scripts/generate_prism_metrics.py --check are clean.

    CI runs the full gated suite.

Runtime code changes only in coordinator/miner_submit.rs, plus a test-only gate hook in submit_ledger.rs. It's an rc.3 candidate alongside #711's fix (B), and is not to be merged without the coordinator's go.

🤖 Generated with Claude Code

…ity as backend-rpc-unavailable, not ledger-confirmation-failed (#716)

A share admitted under a published-work lease checks that authority again
just before COMMIT, with a non-blocking try_read. During a tip change the
tip poll, a fee or readiness write, or the publication itself can hold or
wait for one of those locks. The gate then closes as AuthorityUnavailable,
and the share was answered ledger-confirmation-failed, "share was not
committed because its commit gate closed". Nothing is written, so the
ledger is fine. But that reason feeds PrismShareAppendFailures, so the
alert fired at tip changes under load: 4 refusals in N2's D1 run at rc.1.

Now the closure that won the gate decides the answer:
- A proven stale lease (StaleAuthority) stays stale-job.
- AuthorityUnavailable answers backend-rpc-unavailable, "current chain state
  is unavailable", the answer admission gives when it can't prove readiness
  or the lease. It is still never credited, and not stale-job, since a failed
  try_read proves nothing about the work.
- A deadline closure and a refusal with no recorded closure stay
  ledger-confirmation-failed.

The INFO "share commit gate refused before COMMIT" now carries a closure
field and is logged where the closure is known. Admission's identical
refusals share one constructor, chain_state_unavailable().

The credit-preserving fix, which retries instead of refusing, stays open in
#716.

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

chatgpt-codex-connector Bot commented Oct 6, 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-10-06T09:16:14.216658Z e0c68d4 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: 37df63bac6

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

…, and name the database when the refresh failed on it (#716)

A lease fence can close the commit gate at the pre-COMMIT hook while
the append's ROLLBACK is still in flight at the acknowledgement deadline.
gate.close() also reports such an already-closed gate, so the deadline
path aborted the append and answered its own ledger-confirmation-failed.
That turned a proven stale lease, or unavailable authority, back into
the failure this change stops feeding PrismShareAppendFailures. The
deadline path now asks the gate which closure won it. Both paths share
closed_gate_outcome(), which logs the INFO line with its closure field.

AuthorityUnavailable is answered as admission answers readiness it
cannot prove: stale_readiness_reason() picks backend-database-unavailable
when the latest refresh failed on the ledger database, or the refresh in
flight is still blocked on it (#581, #655), and backend-rpc-unavailable
otherwise. It uses the readiness flag admission already read, because
the readiness lock's contention may be what closed the gate. The
admission sites keep their own literals; the shared constructor is gone.

Tests:
- The closure test adds the database case and checks the INFO line's
  closure label.
- A new test holds the refused append's rollback past the deadline.
  Without this fix it fails with "share was not confirmed by the
  database".
- The memory ledger's unspecified refusal now keeps the duplicate check,
  as the production hook does.

The docs describe what the authority-unavailable closure covers beyond
lock contention.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke merged commit caa4e84 into 3.x.x Oct 6, 2026
40 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/716-authority-unavailable-answer branch October 6, 2026 09:35
RobertClarke added a commit that referenced this pull request Oct 6, 2026
…-rpc-unavailable

#718 (caa4e84) landed before the rc.2 tag. Per the coordinator, rc.2
includes it, with no revert, and #717 is rebased onto it.

The notes now:
- name the change: a share refused at the commit gate because chain-state
  authority was briefly unavailable at a tip change answers
  backend-rpc-unavailable ("current chain state is unavailable"), or
  backend-database-unavailable, instead of ledger-confirmation-failed. So
  PrismShareAppendFailures no longer fires for it. The share is still
  never credited; the credit-preserving retry is #716's follow-up;
- give the runtime changes since rc.1 as migration 025 plus #718's
  answer in coordinator/miner_submit.rs;
- move #716 from the open issues to the partly fixed ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.2: rc.1 plus
migration 025 (#708, #710), #718's commit-gate answer for #716, and the
legacy-audit-body sidecar tool (#715). Both Cargo.lock files move only
their workspace-member entries.

doc/release-notes-3.0.0-rc.2.md covers:
- the changes since rc.1 (U3's lines, and #716 fix A in the coordinator's
  words);
- upgrading from 2.0.x (the sidecar tool and FETCH_COUNT) and from rc.1
  (migrate before any rc.2 frontend starts);
- the lean verification, since the runtime changes are 025 and #718;
- the known issues, including #711, #712, #713 and #704.

The development-line notes name 3.0.0-rc.2 as the tree's identity, they
and the 3.0.0 notes link both candidates' notes, and a doc example's tag
reads v3.0.0-rc.1.

L3 run 37444397320 (l3-full) measured this tree. 32 of 33 runs passed.
throughput-400k-window-2fe-async-3-blocks-r2 refused one valid share at
the commit gate (#716's open part, answered backend-rpc-unavailable), and
the coordinator carried that verdict as a named exception.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
…, and what each pair figure measured

From the review of #722, with the figures confirmed by the coordinator:
- #716 (open part) gives its three measured rates: 4 in about 149k
  shares in N2's rc.1 D1 sustained run on the pair, 1 in about 121k in
  the peak run on #719's build, and 1 in about 150k in rc.2's L3.
- #712 stays in the known issues. #721's parallel export shortens the
  export, but the source export is still on the critical path and both
  exports sit inside the cutover outage. #721's \gset move in the serial
  SQL is mentioned.
- #711 is improved by fix B and stays open for fix A, with the ceiling
  still flagged under 788.
- Each pair figure says what it measured:
  - rc.1's 1,479 ms is on the same shape, and an earlier under-offered
    run measured 1,116 ms;
  - the 1.473 ms hold is order_lock_hold_seconds{holder="append"} on the
    rc.1 runtime;
  - the 750/s ceiling is with the load balancer preferring the primary's
    frontend;
  - the failover drill run is described.
- The measured build is rc.3 without #718's answer mapping, and the 2.0.x
  upgrade points to the parallel export.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Oct 27, 2026
… share keeps its credit (#716) (#788)

A share admitted under a tip-change lease checks its chain authority at
the pre-COMMIT hook, under ORDER_LOCK, with non-blocking try_reads. While
the tip poll, a fee or readiness write, or the publication holds or is
queued for one of the three authority locks, the read fails. Since #718
the gate then closed as AuthorityUnavailable and the share was answered
backend-rpc-unavailable: nothing was written, so a valid share lost its
credit. The L3 preset throughput-400k-window-2fe-async-3-blocks fails on
exactly this, `steady_state: valid shares refused` 1-3 per run (#779).

This is #716's fix B. Contention proves nothing about the lease, so it no
longer closes the gate:
- LeaseCommitFence reports a failed try_read as Contended, apart from
  Unavailable (readiness or tip authority lapsed) and Stale.
- CommitGate gets a Contended state. A contended hook moves the gate
  there by compare-and-swap from Open and refuses; the append rolls back
  as before, releasing ORDER_LOCK.
- CommitGate::retry_after_contention waits for the authority outside
  ORDER_LOCK and any transaction (the ordered AuthorityView read that
  admission already uses), checks the lease against it as the hook does,
  and drops the guards. A lease that still holds reopens the gate
  (Contended to Open) for another attempt; a revoked one closes it with
  its own answer (stale-job, or current chain state is unavailable).
- close_for closes a contended gate too. The deadline, or a
  cancellation, that finds the append still waiting out contention
  closes it as the new AuthorityContended: answered as authority the gate
  cannot prove, and logged closure="authority-contended", because the
  authority held the share back, not the ledger.
- persist_share_pass's append task loops on that. Only a fenced append
  can be retried, and it never carries a candidate, so the retry copies
  only the share.

The acknowledgement and credit invariants hold because COMMIT is still
sent only after the one Open-to-Committing transition, and every close
leaves Open or Contended by compare-and-swap, so no attempt can commit
once the deadline closed the gate. A retried attempt is a fresh
transaction after a definite rollback, and the immutable share_id row
still deduplicates. The authority guards are never held across database
I/O, and the deadline bounds the loop.

Each retry logs INFO "share commit gate waited out contention for its
authority; appending again" with share_id and waited_ms.
docs/prism-rejections.md, the rejections_total metadata and the
generated inventory describe the new behaviour.

Tests: the old contention test held a writer's guard across the hook and
expected a refusal; it is replaced by tests that the share waits and is
credited for each of the three locks, that a publication or readiness
epoch change during the wait keeps that change's answer, that the
deadline during the wait is answered as contended authority and nothing
commits after it, and that unknown readiness is still refused without a
retry. A gate unit test covers the Contended transitions, the closure
table gains authority-contended, and the PostgreSQL hook test now proves
through real SQL rollbacks that a contended gate reopens and commits the
same share after the wait. The three contention tests fail on the
previous code.

Refs #716, #779.

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