Skip to content

Extract PRISM vardiff and block finalization - #78

Open
kiwidream wants to merge 1 commit into
prism-share-submissionfrom
prism-vardiff-finalization
Open

Extract PRISM vardiff and block finalization#78
kiwidream wants to merge 1 commit into
prism-share-submissionfrom
prism-vardiff-finalization

Conversation

@kiwidream

@kiwidream kiwidream commented Jul 20, 2026

Copy link
Copy Markdown
Member

Position in the stack

PR 6 of 9. Base: prism-share-submission. Depends on PR 77. Next: PR 79.

Review this PR against its configured base. See the stack guide for the complete order.

Why this slice exists

Vardiff and accepted-block finalization are separate state machines with strict rollback, durability, payout, audit, and notification ordering. Both were embedded in the coordinator. This slice gives each an explicit owner and names the finalization phases so failures and latency can be observed at the correct boundary.

What changes

  • Move share-window retargeting, idle sweeps, speculative difficulty state, rollback, bounded workers, and metrics into vardiff_service.
  • Move accepted-block landing and confirmation into block_finalization as six replay-safe named phases.
  • Replace large coordinator bodies with explicit ports, compatibility descriptors, and thin delegates.
  • Add phase/interarrival metrics and direct tests for the new boundaries.
  • Record the evidence-based B3 decision to omit a second finalization lane.

Why the diff is sizeable

The roughly 2,480 additions and 1,580 deletions represent two large coordinator state machines moving into owner modules: about 1,040 lines for finalization and 910 for vardiff, while nearly 1,600 lines leave the coordinator. New direct owner tests and the B3 decision record account for most of the remaining additions.

Review vardiff speculative-state restoration first, then the six finalization phases and their ports, and finally verify the coordinator methods are only construction or delegation.

B3 decision

A second finalization lane is intentionally omitted. Available timing evidence does not show valid-candidate delay, while another lane would require a new durable handoff plus additional parent, admission, and shutdown ordering. The new metrics define evidence that can justify revisiting the decision later.

Validation

  • 117 focused vardiff, finalization, and candidate tests passed at this boundary.
  • Cumulative PRISM and Rust regressions pass on the final tree.
  • Docker image validation was run at this milestone.
  • git diff --check passed.

Operator impact

No migration or required configuration change is introduced by this slice.


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


Note

Medium Risk
Large refactor of payout, audit, and ledger-confirmation ordering on the block-submitter path; behavior is intended to be preserved but the moved finalization logic is security- and durability-sensitive.

Overview
Extracts vardiff and accepted-block finalization from PrismCoordinator into dedicated owner modules, leaving the coordinator as lazy construction plus thin delegates.

vardiff_service now owns share-window retargeting, idle sweeps, bounded idle workers, speculative difficulty rollback, and Prometheus idle metrics. Coordinator vardiff APIs delegate through _ensure_vardiff_service() and compatibility descriptors that migrate existing embedder state.

block_finalization introduces BlockFinalizationService with six ordered, replay-safe phases (admission → land/confirm → CTV/credit → evidence → audit publish → accounting). The former monolithic submit_block_candidate / _land_and_confirm_block_candidate bodies move here, with phase timing and candidate interarrival metrics exposed on the metrics endpoint.

docs/prism-coordinator-refactor/b3-decision.md records the decision to omit a second finalization lane, using the new metrics as evidence to revisit later.

Adds focused unit tests for finalization phase ordering and vardiff service boundaries.

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

@blacksmith-sh

This comment has been minimized.

Comment thread lab/prism/prism_coordinator.py Outdated
Comment thread lab/prism/prism_coordinator.py
@kiwidream
kiwidream force-pushed the prism-share-submission branch from cdf110a to 3eafe82 Compare July 20, 2026 14:42
@kiwidream
kiwidream force-pushed the prism-vardiff-finalization branch 2 times, most recently from 03498a8 to 941972e Compare July 20, 2026 15:28
@kiwidream
kiwidream force-pushed the prism-share-submission branch from 3eafe82 to 4b369f0 Compare July 20, 2026 15:28
@kiwidream
kiwidream force-pushed the prism-vardiff-finalization branch from 941972e to d3392da Compare July 20, 2026 15:34
@kiwidream
kiwidream force-pushed the prism-share-submission branch from 4b369f0 to 44e43cc Compare July 20, 2026 15:34

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

Comment thread lab/prism/vardiff_service.py Outdated
@kiwidream
kiwidream force-pushed the prism-share-submission branch from 44e43cc to af51efe Compare July 20, 2026 16:02
@kiwidream
kiwidream force-pushed the prism-vardiff-finalization branch from d3392da to 270fcc4 Compare July 20, 2026 16:02
@kiwidream
kiwidream force-pushed the prism-share-submission branch from af51efe to 60b212e Compare July 20, 2026 16:58
@kiwidream
kiwidream force-pushed the prism-vardiff-finalization branch from 270fcc4 to 18d2bc5 Compare July 20, 2026 16:58
@kiwidream
kiwidream force-pushed the prism-share-submission branch from 60b212e to a87052f Compare July 22, 2026 13:50
@kiwidream
kiwidream force-pushed the prism-vardiff-finalization branch from 18d2bc5 to 3e285ff Compare July 22, 2026 13:50
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