Skip to content

Start PRISM refresh failure budget on first failure - #51

Merged
kiwidream merged 2 commits into
1.x.xfrom
fix-prism-refresh-budget
Jul 18, 2026
Merged

kiwidream merged 2 commits into
1.x.xfrom
fix-prism-refresh-budget

Conversation

@kiwidream

@kiwidream kiwidream commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Summary

  • start the template-refresh failure window at the first consecutive failed poll
  • reset the failure window after every successful poll, including same-tip no-op polls
  • preserve disabled-budget behavior and leave unrelated PRISM paths unchanged

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

  • python3 -m unittest tests.test_prism_coordinator_vardiff (221 tests)
  • Python 3.12 compileall for the changed coordinator and test files in Docker

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_expired compares now against template_refresh_failure_started_monotonic instead of last_successful_template_refresh_monotonic. A new _record_template_refresh_failure stamps 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_SECONDS after a long healthy run when a brief TemplateRefreshBlocked or similar failure occurs.

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

@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 0f81d87. Configure here.

Comment thread lab/prism/prism_coordinator.py Resolved
@kiwidream
kiwidream merged commit 9aa0d5a into 1.x.x Jul 18, 2026
9 checks passed
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]>
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