Skip to content

Skip PRISM payout republish on covered block replays - #59

Merged
kiwidream merged 3 commits into
1.x.xfrom
fix-noop-replay-publish-bump
Jul 18, 2026
Merged

kiwidream merged 3 commits into
1.x.xfrom
fix-noop-replay-publish-bump

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Problem

PRISM mainnet livelocks after a found block. Since #49, every block-candidate finalization — including a fully idempotent replay where confirm_accepted_block confirmed nothing new — runs the reserve/publish sequence: _reserve_payout_state_source_if_current("direct_block") + _block_payout_state_publication(force=True) + publication. Publication bumps _payout_state_generation, wipes the entire job-bundle cache, and schedules an immediate tip-refresh retry. With a candidate stuck in replay, block_submit_loop repeats this every iteration, so every in-flight template refresh aborts at "payout state changed after refresh client selection" and miners see 100% stale-job rejects.

The pre-#49 guard was if confirmed_count in {0, 1} and confirmed_count: — a confirmed_count == 0 replay bumped nothing. #49 removed the no-op arm.

Fix

Peel off the fully idempotent replay in submit_block_candidate: when confirmed_count == 0 and _payout_source_requires_publication() is false (every reserved payout source is already published), set payout_publication_covered and skip source reservation, publication blocking, and the post-lock publish fallbacks entirely.

Two details beyond the guard itself:

  • The post-lock fallbacks are gated too. After the prepare lock, published is None would otherwise trigger reconcile_prism_pool_blocks_once(_force_publish=True) (or the retry-budget publisher when the reconciler is disabled) and re-create the livelock through that path.
  • Why the source-generation check rather than the literal pre-Shorten PRISM payout delivery gate critical sections #49 guard or tip equality: under the Shorten PRISM payout delivery gate critical sections #49 machinery, a prior attempt that confirmed rows but failed before publishing always leaves its source reserved — or fenced as direct_block_uncertain by the exception handler, which blocks delivery until a publication lands. A plain zero-count skip would leave that fence blocked forever; tip equality has the same hole because after a fence our block is the published tip. _payout_source_requires_publication() distinguishes exactly those cases, so crash/fence replays still publish.

A genuinely new confirmation (confirmed_count == 1) takes the unchanged branch and publishes exactly as before. No lock ordering or publish mechanics were touched; the predicate takes _job_cache_lock → self.lock under the already-held prepare lock, the established order.

_advance_payout_state_generation no longer has production callers; it stays for the 13 test call sites that use it as the smallest complete invalidation cycle, with a comment saying so.

Verification

  • New regression test test_idempotent_direct_block_replay_skips_publication runs the incident flow end-to-end: fresh submit publishes once (generation 1, tip published), then the durable candidate replays with the block as active tip and a confirmed_count: 0 confirmation — asserting no generation bump, no source reservation, a seeded job-bundle cache entry survives, zero _schedule_tip_refresh_retry calls, no pending-refresh mark, and an open delivery gate.
  • The prior test that codified the regression behavior (test_idempotent_direct_block_confirmation_publishes_reserved_source, which required a generation bump on a zero-count replay) is rewritten into the above.
  • All PRISM suites pass: 570 tests across vardiff, job-cache, tip-refresh validation, shutdown, hot-path, CTV refresh priority, representative independence, immutable refresh artifacts, direct stratum, self-check, reward-window invariant, share ledger, and audit API.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Note

Medium Risk
Touches payout publication and block-submit finalization on a hot path; logic is narrow but mistakes could leave delivery fenced or skip needed publishes.

Overview
Fixes a post-block livelock where idempotent submit_block_candidate replays (confirmed_count == 0 after the tip moved on) still reserved a payout source, force-blocked publication, and republished—bumping _payout_state_generation, wiping the job-bundle cache, and scheduling tip-refresh churn that aborted in-flight template refreshes.

submit_block_candidate now sets payout_publication_covered when confirmation added nothing, delivery is not publication-fenced (_payout_state_publication_fenced), and every reserved source is already published (_payout_source_requires_publication is false). That path skips reserve/block/publish while still publishing when a prior attempt left an unpublished source or a leaked publication fence needs healing. Reorg reconcile and the disabled-reconciler publish fallbacks are gated on not payout_publication_covered so they cannot re-trigger the same loop.

Adds _payout_state_publication_fenced, documents that _advance_payout_state_generation is test-only, and replaces/extends vardiff tests for skip vs fence-heal replay behavior.

Reviewed by Cursor Bugbot for commit c5be3a6. Bugbot is set up for automated code reviews on this repo. Configure here.

Since #49, every block-candidate finalization ran the reserve/publish
sequence even when confirm_accepted_block reported nothing new. A
candidate stuck in replay therefore bumped the payout-state generation,
wiped the job-bundle cache, and scheduled an immediate tip-refresh retry
on every block_submit_loop iteration, aborting each in-flight template
refresh ("payout state changed after refresh client selection") and
livelocking job delivery after a found block.

Peel off the fully idempotent replay: when confirmed_count == 0 and no
reserved payout source awaits publication, the published payout state
already covers the candidate, so skip source reservation, publication
blocking, and the post-lock force-publish fallbacks entirely. A replay
whose prior attempt confirmed rows but failed before publishing always
leaves its source reserved (or fenced as direct_block_uncertain), so it
still publishes through the existing path, and a genuinely new
confirmation (confirmed_count == 1) publishes exactly as before.

_advance_payout_state_generation no longer has production callers; keep
it for the tests that use it as the smallest complete invalidation
cycle, with a comment saying so.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
qbit_confirm_pool_block reports confirmed_count=0 for an already-
confirmed block only once the active tip height moved past it; while the
block is still the tip an idempotent replay reports 1 and must keep
publishing because it is indistinguishable from a freshly flipped row.
Rework the regression test to replay as an active ancestor under an
advanced tip, and document the confirm semantics plus the restart case
at the covered-replay skip.

Co-Authored-By: Claude Fable 5 <[email protected]>

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3ade287. Configure here.

Comment thread lab/prism/prism_coordinator.py Resolved
A finalization attempt can force-block delivery after a superseding
source already published (its own reservation lost the race), then fail
before the republish lands. That leaks a delivery fence whose source
generation matches the published source, so the covered-replay skip
would bail out and nothing would ever clear the fence, blocking every
job build. Require a clear publication fence before skipping, so a
confirmed_count=0 replay of that tail still republishes and unblocks
delivery.

Co-Authored-By: Claude Fable 5 <[email protected]>
@kiwidream
kiwidream merged commit ce45496 into 1.x.x Jul 18, 2026
9 checks passed

@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: c5be3a6ef8

ℹ️ 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 thread lab/prism/prism_coordinator.py Resolved
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.

2 participants