Repository navigation
Start PRISM refresh failure budget on first failure - #51
Merged
Merged
Conversation
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 0f81d87. Configure here.
RobertClarke
added a commit
that referenced
this pull request
Jul 18, 2026
poll_qbit_tip_template_once raises TemplateRefreshBlocked (and its _PayoutStatePublicationBlocked subclass) for benign coordination races: a tip superseded mid-refresh, a payout publication fence pending, a refresh raced by payout mutation. Since #51 the generic failure handler recorded these into the template-refresh failure budget, so sustained payout-coordination churn exhausted PRISM_TEMPLATE_REFRESH_FAILURE_EXIT_SECONDS and os._exit(1)'d a process whose qbitd RPC was perfectly healthy -- and each restart re-triggered the same churn, producing a restart loop in production. Re-raise coordination-blocked refreshes ahead of the recording handler: they still propagate so blockpoll/blockwait schedule their immediate retry, but they no longer arm the exit clock. Genuine RPC/qbitd failures still record on first failure and still exit non-zero once the budget elapses; the success-path reset is untouched. Co-Authored-By: Claude Fable 5 <[email protected]>
RobertClarke
added a commit
that referenced
this pull request
Jul 18, 2026
…dget (#56) * Exclude coordination-blocked refreshes from PRISM failure budget poll_qbit_tip_template_once raises TemplateRefreshBlocked (and its _PayoutStatePublicationBlocked subclass) for benign coordination races: a tip superseded mid-refresh, a payout publication fence pending, a refresh raced by payout mutation. Since #51 the generic failure handler recorded these into the template-refresh failure budget, so sustained payout-coordination churn exhausted PRISM_TEMPLATE_REFRESH_FAILURE_EXIT_SECONDS and os._exit(1)'d a process whose qbitd RPC was perfectly healthy -- and each restart re-triggered the same churn, producing a restart loop in production. Re-raise coordination-blocked refreshes ahead of the recording handler: they still propagate so blockpoll/blockwait schedule their immediate retry, but they no longer arm the exit clock. Genuine RPC/qbitd failures still record on first failure and still exit non-zero once the budget elapses; the success-path reset is untouched. Co-Authored-By: Claude Fable 5 <[email protected]> * Narrow budget exemption to supersession races Review feedback (Codex P1, Bugbot high): TemplateRefreshBlocked also wraps genuine failures -- malformed template artifacts, all client job builds failing, untrusted chain views, wrapped RPC validation errors -- and a blanket exemption would let those persist forever without work issuance on a process whose top-of-poll RPCs stay healthy. Introduce TemplateRefreshSuperseded(TemplateRefreshBlocked) and raise it only at the coordination-race sites (tip advanced mid-refresh, payout generation moved, prepared refresh superseded). The failure-budget exemption now covers only that subclass plus the payout publication fence; plain TemplateRefreshBlocked records again, so persistent non-coordination failures arm the budget from a fresh process and still take the budgeted restart path. Co-Authored-By: Claude Fable 5 <[email protected]> * Keep armed budget from firing on exempt refreshes Codex round-2 P1: blockpoll_loop's generic handler checked template_refresh_failure_expired on every exception, so a clock armed by one transient budgeted failure could still be FIRED by a coordination-blocked attempt once churn outlasted the budget -- hard-exiting a process whose qbitd RPC had already recovered. Catch (TemplateRefreshSuperseded, _PayoutStatePublicationBlocked) in blockpoll_loop ahead of the generic handler: log and retry without consulting the budget. The armed clock now waits for the next budgeted failure or clears on the next completed refresh. The pre-armed untrusted-reconciliation and all-builds-failing exits are unaffected -- those raise plain TemplateRefreshBlocked, which still takes the budgeted path. Co-Authored-By: Claude Fable 5 <[email protected]> * Exempt guarded-build and startup supersession races Codex round-3 P1: the sequential/collection-mode path detects superseded snapshots inside maybe_send_job's guarded build -- "tip refresh snapshot was superseded before/during client job build" and "payout state changed during client job build" -- and those still raised plain TemplateRefreshBlocked, so sustained pre-ready coordination churn could arm and exhaust the failure budget despite healthy RPC. The startup prewarm path carries the same supersession trio. Classify all six sites as TemplateRefreshSuperseded. maybe_send_job's guarded handler re-raises TemplateRefreshBlocked unwrapped, so the subclass reaches the poll's exemption intact; genuine build failures still wrap into _JobBuildFailed and stay budgeted via the no-refreshed-work raise. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
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.

Summary
Incident
A slow fanout followed by TemplateRefreshBlocked: payout state changed after refresh client selection immediately exhausted the old 120-second budget because it was measured from the previous successful refresh. That restarted the coordinator and caused a pool outage. The failure budget now begins with the first failed poll instead.
Testing
Note
Medium Risk
Changes when the coordinator self-exits under template refresh stress, directly affecting pool availability during outages; scope is limited to failure-budget timing logic with updated unit tests.
Overview
PRISM’s template-refresh failure exit timer no longer counts from the last successful poll. It now starts on the first failure in a consecutive outage and clears on any successful refresh (including same-tip no-ops).
template_refresh_failure_expiredcomparesnowagainsttemplate_refresh_failure_started_monotonicinstead oflast_successful_template_refresh_monotonic. A new_record_template_refresh_failurestamps that start time once per failure streak (skipped when the budget is disabled). The heavy tip-refresh path records failures on exception and resets the streak on success.This avoids prematurely hitting
PRISM_TEMPLATE_REFRESH_FAILURE_EXIT_SECONDSafter a long healthy run when a briefTemplateRefreshBlockedor similar failure occurs.Reviewed by Cursor Bugbot for commit ad3295e. Bugbot is set up for automated code reviews on this repo. Configure here.