Skip to content

PRISM: converge tip refreshes on latest epochs - #101

Merged
djh58 merged 11 commits into
1.x.xfrom
dan/prism-clients-alert-check
Jul 29, 2026
Merged

djh58 merged 11 commits into
1.x.xfrom
dan/prism-clients-alert-check

Conversation

@djh58

@djh58 djh58 commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add default-off PRISM_TIP_REFRESH_EPOCH_FANOUT support so an owning refresh wave can converge on the latest observed tip and payout epoch instead of abandoning progress after supersession.
  • Fence per-connection admission by epoch while preserving immutable bundle stamping, hashrate-descending admission, atomic difficulty/notify delivery, and post-send delivery proof.
  • Add fixed-cardinality wave-outcome and fleet-coverage metrics, visibility for stale-grace block solves, and distinct durable stale-job abandonment causes.
  • Add deterministic concurrency coverage for repeated supersession, build re-entry, same-tip payout publication, wire ordering, retained shares, failed connections, and shutdown.

Why

During fast block cadence, refresh waves can be superseded faster than abort-and-retry delivery completes. Re-entering the owning wave with the newest immutable state lets already-admitted sends finish while preventing obsolete queued work from crossing the per-connection epoch fence.

Solved submissions degraded by stale grace and distinct stale-job abandonment causes were also not separately observable, making rollout behavior harder to evaluate.

Operational limits

  • The feature defaults to 0; leaving it disabled preserves legacy refresh behavior, and returning it to 0 is the rollback path.
  • Payout publication remains fail closed, chain-trust checks remain authoritative, and worker-count limits are unchanged.
  • Already-admitted sends may finish; obsolete queued work is canceled, and subsequent passes recompute eligible clients until delivered work reaches the newest epoch.
  • Coverage uses a frozen fleet snapshot and fixed labels only; it adds no per-connection metric series.

Validation

  • python3 -m compileall -q docker lab tests examples scripts
  • Focused PRISM coordinator, epoch, and Compose unit suites
  • python3 -m unittest discover -s tests -p 'test_*.py'
  • Repeated deterministic epoch-concurrency suite runs
  • git ls-files '*.sh' | xargs bash -n
  • git ls-files '*.sh' | xargs shellcheck -x
  • Docker Compose config --quiet for the permissionless, real-miner-smoke, auxpow, and prism profiles
  • git diff --check origin/1.x.x...HEAD

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

High Risk
Changes core PRISM tip-refresh coordination, per-connection job delivery, and block-candidate abandonment paths under fast tip cadence; rollout is gated off by default but enabling it alters live mining behavior and failure classification.

Overview
Adds default-off PRISM_TIP_REFRESH_EPOCH_FANOUT so the owning tip-refresh wave can re-enter after supersession instead of abort-and-retry, converging fleet delivery on the latest tip/payout epoch while payout publication and chain-trust fences stay authoritative.

When enabled, the coordinator mints refresh epochs on tip detection and payout publication, stamps jobs with tip_refresh_epoch_sequence, and fences per-connection admission so older epochs cannot regress on the wire. Delivery proof still advances only after successful sends; wave re-entry is bounded by pass budget and backoff, with a fixpoint check before the wave completes.

Rollout observability: Prometheus counters/histograms for wave outcomes (completed, build_superseded, fanout_superseded, etc.) and fixed-label hashrate coverage latency (50/95/99 cohorts). Separate metrics for stale-grace block solves dropped and stale-job abandons (tip_moved vs balance_stale); durable outbox rows record the abandonment message.

Docs, Compose, and .env.example document staged enable and rollback via 0.

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

Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
djh58 and others added 4 commits July 29, 2026 14:44
Keep both metric blocks at the tip_refresh_metrics_lines seam: the
hashrate-coverage histogram from this branch and the serve-builder
counters from #99.

Co-Authored-By: Claude Fable 5 <[email protected]>
- Reselect clients whose delivered work is a collection job once the
  pool latches ready, matching the epoch fixpoint so an owning wave
  cannot re-enter forever with no candidate to serve.
- Back off between re-entry passes and bound each wave by a pass
  budget that hands convergence to the scheduled retry, so sustained
  tip churn cannot poll template RPCs in a tight loop.
- Record a dedicated shutdown wave outcome when stop interrupts
  convergence instead of reporting the wave completed.

Co-Authored-By: Claude Fable 5 <[email protected]>
- Negative control: with the per-connection epoch fence disabled, a
  queued stale delivery that already passed global validation reaches
  registration and the socket; the intervening-job comparator admits
  it and only the fence blocks it.
- Regression coverage for delivered-collection reselection under a
  ready latch, the wave pass budget's scheduled-retry fallback,
  re-entry gating, and the shutdown wave outcome.

Co-Authored-By: Claude Fable 5 <[email protected]>
Keep-both resolutions: PrismJobContext gains both the epoch sequence
stamp from this branch and the retained version-rolling mask from
#100, at the dataclass and its construction site; .env.example keeps
both new entries.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
@djh58

djh58 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Pushed four commits addressing the Bugbot findings and the review follow-ups, and folding in the two base merges.

fd09988, f610e0f — merge 1.x.x after #99 and #100. Additive seams only: the coverage histogram + serve-builder counters coexist in tip_refresh_metrics_lines, and PrismJobContext gains both the epoch sequence stamp (this branch) and the retained version-rolling mask (#100) at the dataclass and its construction site.

77a9e77 — prism: harden epoch wave re-entry and outcome reporting.

  • Owner loop livelock after failed send (Bugbot, high): client_needs_tip_template_refresh now reselects a client whose delivered work is a collection job once the pool latches ready, matching _tip_refresh_epoch_fixpoint_reached. Previously only the active job was checked for collection status, so a windowed registration whose send failed could leave the fixpoint permanently open with no selectable candidate. The comment at the delivered-check site also records why an "admitted-epoch equal → skip" dedupe must not be added there: admission is monotonic and survives a failed send, so it would deselect a client the fixpoint still counts as undelivered (the equal-epoch re-serve stays, accepted as idempotent on the wire).
  • Completed outcome on unfinished shutdown (Bugbot, low): a wave interrupted by shutdown before the fixpoint now records a dedicated shutdown outcome (label set stays fixed-cardinality) instead of completed.
  • Re-entry churn: superseded or incomplete passes back off (PRISM_TIP_REFRESH_REENTRY_BACKOFF_SECONDS, 50ms) and each wave is bounded by PRISM_TIP_REFRESH_WAVE_PASS_BUDGET (64 passes) before handing convergence to the scheduled retry, so sustained tip churn cannot poll template RPCs in a tight loop.

9baa557 — tests.

  • Negative control pinning the per-connection epoch fence as load-bearing on the wire: with the fence disabled, a queued stale delivery that already passed global validation reaches registration and the socket — the intervening-job comparator admits it by design (an old-tip snapshot must normally not block a newer-tip active job), and only the fence stops the epoch regression.
  • Regression tests for the delivered-collection reselection, the shutdown outcome (unit test plus the extended shutdown-drain test), the pass budget's scheduled-retry fallback, and re-entry gating. Both coordinator behavior fixes were verified to fail against the pre-fix code.

Validation on the final tree (post-#99/#100): python3 -m compileall clean; focused PRISM suites 570/570 (epoch suite now 23 tests, including #100's job-cache/vardiff/first-job-latency additions); full unittest discover matches the 1.x.x baseline; git ls-files '*.sh' | xargs bash -n and git diff --check clean.

Comment thread lab/prism/prism_coordinator.py Resolved
djh58 and others added 2 commits July 29, 2026 15:46
- A wave that declines re-entry because of shutdown now records the
  shutdown outcome instead of a supersession label, so terminal
  supersession counts stay meaningful during restarts. Legacy waves
  never re-enter and keep their supersession outcome.
- An initial-job delivery blocked by the per-connection epoch fence
  completes the pending request against the newer current-tip work the
  fence proves is registered, instead of retrying into the initial-job
  deadline disconnect of an already-served client.
- A converged wave consumes refresh retries armed before its fixpoint
  verification, inside the same lock hold that proved convergence, so
  recovered supersessions no longer leave a stale retry that re-runs a
  full wave against finished work.

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

djh58 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Round-2 Bugbot findings verified and fixed in 1d97acb + 8626220.

  • Shutdown misreported after re-entry wait (medium): real — a shutdown arriving during the re-entry decision or its backoff recorded fanout_superseded/build_superseded. Waves that decline re-entry now classify through _interrupted_wave_outcome: with epoch fanout active and stop set, the outcome is shutdown; legacy waves never re-enter, so their supersession outcome stands (flag-off parity is test-pinned).
  • Initial-job fence retries until disconnect (medium): real — the fence blocks only strictly older epochs, so a miss proves the connection already registered newer refresh work; retrying could spin into the initial-job deadline, which disconnects the client. The fence-miss branch now completes a pending request that newer current-tip work satisfies (note_initial_job_delivered's existing current-tip validation decides), and only keeps retrying when the newer work is not yet current-tip.
  • Stale retry after successful re-entry (medium): real and worth fixing — superseded passes arm the coalesced retry, the owning wave recovers by re-entry, and the armed retry made blockpoll immediately re-run a full wave against finished work. A converged wave now consumes retries armed before its fixpoint verification, inside the same lock hold that proved convergence, so signals armed afterwards (including a losing observer's newer-tip retry) stay armed. The pass-budget path deliberately leaves its retry armed — that retry owns the unconverged remainder (also test-pinned).

All three fixes were verified to fail their new regression tests against the pre-fix code. Focused suites 574/574; full discover matches the 1.x.x baseline.

Comment thread lab/prism/prism_coordinator.py Resolved
A payout publication advances the payout generation of the target the
fleet is already converging on; it must not move or invent the epoch
tip. The mint previously preferred the candidate's source hash, and an
accepted-block preview stores the accepted block's own hash there —
not a template parent, and possibly trailing an already-observed newer
tip. Labeling the live epoch with it strands token currency, identity
publication, and the fixpoint until a later tip observation remints.
The mint now labels from the current epoch tip, then the latest
detected or published tip, and never from candidate source hashes.

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

djh58 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Verified and fixed in f37b2c5: payout mint uses non-tip hash (high) — real, and the most important finding so far.

The accepted-block preview publication reserves the payout source with the accepted block's own hash, and the epoch mint preferred candidate.source_tip_hash for the epoch's tip label. That hash is not a template parent: if the block loses a tip race, or the publication trails an already-observed newer tip, the live epoch is labeled with a hash no delivered work can ever match — the fixpoint cannot converge, the epoch identity cannot publish (snapshot mismatch), stamping falls back to epoch 0, and the per-connection fence then blocks those registrations. With the flag enabled, refresh delivery stalls until the next real tip observation remints — precisely in the moments after an accepted block.

Fix: a payout publication advances the payout generation of the target the fleet is already converging on; it must not move or invent the tip. The mint now labels from the current epoch tip, falling back to the latest detected then published tip, and never from candidate source hashes (_payout_epoch_tip_hash_locked). PublishedPayoutState.source_tip_hash keeps its existing value and uses.

Regression tests pin the label-source priority and drive the real accepted-block preview publication, asserting the epoch stays on the observed tip while sequence and payout generation advance; the publication test fails against the pre-fix code with the epoch labeled by the block hash. Focused suites 576/576; full discover matches the 1.x.x baseline.

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

Comment thread lab/prism/prism_coordinator.py Resolved
The payout publication minted a new epoch but left the published
stamping identity on the previous payout generation, so every rebuilt
bundle mismatched it and stamped epoch 0 — which the fence blocks for
previously admitted connections until the next wave republishes.
Initial deliveries stamping through bundle identity could spin on that
window and reach the deadline disconnect. Re-anchor the identity in
the same lock hold as the mint; the publish helper already no-ops when
the epoch tip is not the published snapshot tip, which the owning wave
handles.

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

djh58 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Verified and fixed in 9d7ba5a: stale identity after payout mint (medium) — real. The payout publication minted a new epoch but left the published stamping identity on the previous payout generation, so every rebuilt bundle mismatched it and stamped epoch 0, which the per-connection fence blocks for previously admitted connections until the next wave republishes the identity. Initial deliveries stamping through bundle identity could spin on that window and reach the deadline disconnect. The mint now re-anchors the identity in the same lock hold; the publish helper already no-ops when the epoch tip is not the published snapshot tip (the owning wave handles that transition). Regression test drives the real accepted-block preview publication and asserts the identity advances with the mint and a rebuilt bundle stamps the minted epoch, not 0; it fails against the pre-fix code. Focused suites 577/577.

@djh58
djh58 merged commit e2fb33d into 1.x.x Jul 29, 2026
10 checks passed
RobertClarke added a commit that referenced this pull request Jul 30, 2026
* Revert "Survive production build latency in payout-artifact reuse (2026-07-29 re-land) (#103)"

This reverts commit cd32c13.

The re-land brownouted mainnet on 2026-07-30 (generation-churn brownout);
the payout-artifact reuse line is abandoned and 1.x.x returns to the #101
(e2fb33d) behavior.

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

* Revert "Make payout-ledger-artifact reuse anchor-scoped so it survives production share rates (#102)"

This reverts commit fcc2c3e.

Anchor-scoped reuse livelocked mainnet payouts on 2026-07-29 (born-expired
artifact livelock); together with the #103 revert this restores the
payout-artifact machinery to its #101 (e2fb33d) state: exact-count fence
semantics, no staleness/rearm/anchor-age knobs, no admission-deadline
machinery.

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