Repository navigation
Skip PRISM payout republish on covered block replays - #59
Merged
Merged
Conversation
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]>
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]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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.
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]>
There was a problem hiding this comment.
💡 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".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
PRISM mainnet livelocks after a found block. Since #49, every block-candidate finalization — including a fully idempotent replay where
confirm_accepted_blockconfirmed 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_looprepeats 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:— aconfirmed_count == 0replay bumped nothing. #49 removed the no-op arm.Fix
Peel off the fully idempotent replay in
submit_block_candidate: whenconfirmed_count == 0and_payout_source_requires_publication()is false (every reserved payout source is already published), setpayout_publication_coveredand skip source reservation, publication blocking, and the post-lock publish fallbacks entirely.Two details beyond the guard itself:
published is Nonewould otherwise triggerreconcile_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.direct_block_uncertainby 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.lockunder the already-held prepare lock, the established order._advance_payout_state_generationno 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
test_idempotent_direct_block_replay_skips_publicationruns 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 aconfirmed_count: 0confirmation — asserting no generation bump, no source reservation, a seeded job-bundle cache entry survives, zero_schedule_tip_refresh_retrycalls, no pending-refresh mark, and an open delivery gate.test_idempotent_direct_block_confirmation_publishes_reserved_source, which required a generation bump on a zero-count replay) is rewritten into the above.🤖 Generated with Claude Code
Need help on this PR? Tag
/codesmithwith 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_candidatereplays (confirmed_count == 0after 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_candidatenow setspayout_publication_coveredwhen confirmation added nothing, delivery is not publication-fenced (_payout_state_publication_fenced), and every reserved source is already published (_payout_source_requires_publicationis 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 onnot payout_publication_coveredso they cannot re-trigger the same loop.Adds
_payout_state_publication_fenced, documents that_advance_payout_state_generationis 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.