Skip to content

Exclude coordination-blocked refreshes from PRISM template failure budget - #56

Merged
RobertClarke merged 4 commits into
1.x.xfrom
exclude-blocked-refresh-budget
Jul 18, 2026
Merged

RobertClarke merged 4 commits into
1.x.xfrom
exclude-blocked-refresh-budget

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Problem

poll_qbit_tip_template_once raises TemplateRefreshBlocked for benign coordination races — a tip superseded mid-refresh, payout state changing during fanout — and _PayoutStatePublicationBlocked whenever a payout publication fence is pending. The generic except Exception at the end of the poll recorded all of these via _record_template_refresh_failure.

Since #51 the failure budget starts at the first recorded failure. Once PRISM_TEMPLATE_REFRESH_FAILURE_EXIT_SECONDS (deployed: 600) elapsed without a completed refresh, blockpoll os._exit(1)'d. Observed in production: sustained payout-coordination churn self-terminates a process whose qbitd RPC is perfectly healthy, and each restart re-triggers the churn — a restart loop.

Fix

Introduce TemplateRefreshSuperseded(TemplateRefreshBlocked) and raise it at the coordination-race sites only: tip advanced mid-refresh (fetch, sequential, prepared fanout, queued work), payout-state generation moved (client selection, sequential, post-fanout token checks, payout-only invalidation), and prepared-refresh supersession (fanout submission/cancellation registration, pending-token loss). #58's _BundlePreparationSuperseded ("newer tip superseded shared bundle preparation"), which escapes shared_job_bundle into the poll, subclasses it.

The poll re-raises (TemplateRefreshSuperseded, _PayoutStatePublicationBlocked) ahead of the recording handler: blocked refreshes still propagate — blockpoll_loop/blockwait_loop still schedule their immediate retry — but they no longer arm the exit clock.

Everything else stays budgeted, per review feedback from Codex and Bugbot: plain TemplateRefreshBlocked also wraps genuine failures — malformed template artifacts, all client job builds failing, untrusted chain views, RPC validation errors — and those persistent states must still take the budgeted restart path even when top-of-poll RPCs stay healthy. Raw RPC/qbitd failures record as before, and the success-path reset is untouched.

Coordination-blocked attempts can neither arm nor fire the budget: blockpoll_loop catches the two exempt types ahead of its generic handler and retries without consulting template_refresh_failure_expired, so a clock armed by a transient budgeted failure waits for the next budgeted failure (or clears on the next completed refresh) instead of exiting mid-churn. An already-armed budget still fires on any subsequent budgeted failure — matching the existing test_untrusted_reconciliation_exhausts_template_refresh_failure_budget / test_all_refresh_job_builds_failing_exhausts_failure_budget semantics, which raise plain TemplateRefreshBlocked.

Acceptance

  • Coordination storms never exit: test_sustained_blocked_refresh_storm_never_exhausts_failure_budget drives the real poll through alternating TemplateRefreshSuperseded/payout-fence failures spanning >2x the budget window with a healthy tip RPC — no os._exit, clock never armed.
  • Real outage still exits: test_rpc_outage_arms_and_exhausts_failure_budget simulates qbitd unreachable — the budget arms on the first raw RPC failure and the loop exits non-zero once it elapses.
  • Non-coordination blocked states still exit (review scenario): test_persistent_blocked_template_derivation_arms_and_exhausts_failure_budget and test_non_coordination_blocked_refresh_still_starts_failure_budget prove plain TemplateRefreshBlocked (malformed artifacts / failing builds) arms the budget from a fresh process and takes the restart path.
  • No recording on coordination races: test_coordination_blocked_refresh_does_not_start_failure_budget covers both exempt types at the poll level.
  • Armed budget not fired by churn: test_armed_budget_is_not_fired_by_coordination_blocked_refresh pre-arms the clock, drives blocked churn past the budget window, and asserts no exit with the clock left armed.

All 512 tests across the 14 coordinator-dependent test modules pass, rebased on current 1.x.x (includes #58).

🤖 Generated with Claude Code


Note

Medium Risk
Touches core blockpoll shutdown logic and error taxonomy; misclassification could either mask real outages or reintroduce restart loops under churn.

Overview
Fixes a production restart loop where benign tip/payout coordination races were counted like real template failures and eventually drove blockpoll_loop to os._exit(1) despite healthy qbitd RPC.

Introduces TemplateRefreshSuperseded (TemplateRefreshBlocked subclass) and reclassifies coordination-race sites—tip moved during fetch/fanout/sequential refresh, payout generation drift, prepared-refresh token loss, payout-only invalidation supersession—so they raise the new type. _BundlePreparationSuperseded now subclasses it as well.

poll_qbit_tip_template_once and blockpoll_loop catch (TemplateRefreshSuperseded, _PayoutStatePublicationBlocked) before _record_template_refresh_failure / template_refresh_failure_expired, so these paths still schedule immediate retries but never arm or fire the failure clock. Plain TemplateRefreshBlocked (bad artifacts, failed job builds, RPC validation errors, etc.) and raw RPC exceptions keep the budgeted restart behavior.

Adds coordinator tests for coordination storms, armed-budget + churn, RPC outage, and persistent non-coordination blocked states.

Reviewed by Cursor Bugbot for commit fa2ae52. 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 acffce0. Configure here.

Comment thread lab/prism/prism_coordinator.py Resolved

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

ℹ️ 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
RobertClarke and others added 2 commits July 17, 2026 21:31
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]>
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]>
@RobertClarke
RobertClarke force-pushed the exclude-blocked-refresh-budget branch from acffce0 to 13bb5ba Compare July 18, 2026 01:33
@RobertClarke

Copy link
Copy Markdown
Member Author

@codex review

@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: 13bb5ba3ed

ℹ️ 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
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]>
@RobertClarke

Copy link
Copy Markdown
Member Author

@codex review

@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: 7779bf0e66

ℹ️ 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
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]>
@RobertClarke

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: fa2ae52167

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

@RobertClarke
RobertClarke merged commit 9e9fcb1 into 1.x.x Jul 18, 2026
9 checks passed
RobertClarke pushed a commit that referenced this pull request Jul 18, 2026
Reconcile the tip publication boundary (build/validate before submit
authority moves) with 1.x.x's short publication lane (#58), bounded
build supersession (#57), superseded-vs-blocked budget taxonomy (#56),
and delivery priorities:

- keep construction outside the publication lane, then run the PR's
  final validation and atomic prepared publication inside it
- drop the base's early tip publication before template fetch; the
  poll now only records a detection there
- compare build-pipeline supersession gates against the newest
  detected tip so a replacement build for a detected-but-unpublished
  tip can cache and publish itself
- cancel obsolete bundle/job builds at detection time
- clear retained ready bundles when publication flips the tip
- classify prepared-publication races as TemplateRefreshSuperseded so
  coordination churn cannot arm the restart budget
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