Skip to content

Bound PRISM refresh build supersession - #57

Merged
kiwidream merged 4 commits into
1.x.xfrom
bound-prism-refresh-supersession
Jul 18, 2026
Merged

kiwidream merged 4 commits into
1.x.xfrom
bound-prism-refresh-supersession

Conversation

@kiwidream

@kiwidream kiwidream commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • build PRISM jobs from immutable template, payout, policy, CTV, signing, and numeric-context snapshots
  • move expensive ledger, payout, builder, signing, and serialization work outside the short refresh publication lane
  • add a bounded latest-generation-wins scheduler with cooperative phase cancellation, subprocess termination, and stale-result rejection
  • precompute immutable payout artifacts per generation and reselect clients at the final publication boundary
  • expose scheduler, cancellation, replacement latency, phase, obsolete-result, and worker lifecycle metrics
  • preserve the bounded initial-job reconnect pipeline added on the current 1.x.x tip

Correctness coverage

  • replacement generation starts before a blocked obsolete builder is released
  • stale results never reach the cache, active job maps, or mining.notify
  • repeated supersession retains only the newest pending request with at most two physical builders
  • tip changes cancel ledger, payout, CTV, signing, assembly, and serialization phases
  • direct-block invalidation cancels construction before payout publication
  • scheduled output exactly matches synchronous output, including decimal-context-sensitive targets
  • builder crash and timeout paths recover on the next worker

Validation

  • Docker Python 3.12 compile check and 124 focused refresh/cache/initial-delivery/artifact tests
  • 233 PRISM coordinator vardiff, payout, block-acceptance, and builder tests
  • deterministic supersession benchmark with a 2.0s blocked obsolete ledger phase:
    • 1.x.x baseline replacement: 2.0037s
    • this branch replacement: 0.0002s
    • both replacement bundles used payout generation 1

Note

High Risk
Changes core mining job construction, payout stamping, tip refresh ordering, and subprocess cancellation paths; incorrect supersession or cache gating could deliver stale jobs or block refresh under load.

Overview
Replaces per-identity singleflight shared bundle preparation with a bounded latest-wins job build scheduler (active + retiring + one pending slot, 2-worker executor). Builds are keyed by JobBuildKey and immutable snapshots (template, payout artifact, policy, CTV, signing, decimal context); PayoutStateArtifact is published with each payout generation and must match before cache or delivery.

Cooperative cancellation (JobBuildCancelled / JobBuildSuperseded) runs through ledger, payout prep, and the audit-bundle subprocess (terminate/kill on supersession or timeout). Tip, template fingerprint, and payout generation changes preempt in-flight builds; stale bundles are rejected at cache, validation token, and client delivery boundaries.

Tip refresh observes the chain tip earlier (before heavy template work), shortens holding of _tip_refresh_lock to publication only, and revalidates client selection at fanout. poll_qbit_tip_template_once can include clients that became eligible after build selection. New Prometheus metrics cover scheduler, cancellation latency, replacement start, and builder worker lifecycle.

Tests add coverage for scheduler equivalence, tip staleness, payout artifact mismatch fallback, lock ordering, and rapid supersession races.

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


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Comment thread lab/prism/prism_coordinator.py Resolved
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: 3effb012fa

ℹ️ 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
Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
@kiwidream
kiwidream force-pushed the bound-prism-refresh-supersession branch from b295984 to 6d69e75 Compare July 18, 2026 01:58

@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 2 potential issues.

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 6d69e75. Configure here.

Comment thread lab/prism/prism_coordinator.py Resolved
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: 6d69e75ef3

ℹ️ 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
Comment thread lab/prism/prism_coordinator.py Resolved
@kiwidream
kiwidream force-pushed the bound-prism-refresh-supersession branch from 6d69e75 to 581a482 Compare July 18, 2026 02:14
@kiwidream

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: 581a48294c

ℹ️ 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 on lines 4535 to +4538
or current.fingerprint != artifacts.fingerprint
or current.generation != artifacts.generation
):
# Snapshot-owned artifacts remain usable even if a newer
# template won the global cache race; just do not retain them.
return True
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not drop clock-only template builds

When a same-tip getblocktemplate update changes only volatile fields such as curtime, the fingerprint remains the same but artifacts.generation advances; if that cache fill happens while a normal initial/per-client build is running, this check rejects the completed bundle and shared_job_bundle() raises JobBuildSuperseded for non-refresh callers. With slow ready-pool builds and the poller refreshing every few seconds, miners can repeatedly retry without receiving work even though the built bundle still extends the current tip.

Useful? React with 👍 / 👎.

Comment on lines +3506 to +3510
now = time.monotonic()
if active.request.cancellation.cancel("superseded"):
active.request.superseded_monotonic = now
self.job_build_scheduler_counts["supersessions"] += 1
request.superseded_monotonic = now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not supersede independent collection builds

Before the pool reaches min_ready_miners, collection-mode bundles are worker-specific, so a second worker's different equivalence_key is not a newer replacement for the first worker's job. This unconditional cancellation makes concurrent initial collection jobs cancel each other; with several miners connecting or authorizing at once, earlier miners keep retrying and can time out or disconnect instead of receiving the bootstrap work needed to make the pool ready.

Useful? React with 👍 / 👎.

@kiwidream
kiwidream merged commit 8f4bb0b into 1.x.x Jul 18, 2026
9 checks passed
RobertClarke pushed a commit that referenced this pull request Jul 18, 2026
…ocking

Reconciles the bounded build-supersession machinery (#57) with this
branch's prospective payout publication and snapshot anchor floor:

- job snapshot anchors clamp below pending share commits at the frozen
  per-generation issued time in _new_job_build_request, which also makes
  the frozen anchor's window byte-reproducible across rebuilds
- bundles built from a reused payout ledger artifact declare the
  artifact's own snapshot anchor
- child builds wait for a pending accepted-parent preview before
  acquiring any confirmed payout input, so no stale confirmed read is
  taken or cached into the published payout state artifact while the
  parent lands
- an accepted-block preview publication installs its preview balances as
  the published payout state artifact instead of reading the ledger,
  whose durable state only catches up after persistence
- accepted blocks cancel obsolete job builds before preview publication,
  preserving the #57 refresh handoff

Co-Authored-By: Claude Fable 5 <[email protected]>
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