Skip to content

Extract PRISM coordinator core owners - #74

Open
kiwidream wants to merge 1 commit into
prism-test-shardsfrom
prism-coordinator-core-owners
Open

Extract PRISM coordinator core owners#74
kiwidream wants to merge 1 commit into
prism-test-shardsfrom
prism-coordinator-core-owners

Conversation

@kiwidream

@kiwidream kiwidream commented Jul 20, 2026

Copy link
Copy Markdown
Member

Position in the stack

PR 2 of 9. Base: prism-test-shards. Depends on PR 73. Next: PR 75.

Review this PR against its configured base so the diff contains only the core-owner extraction. See the stack guide for the complete order.

Why this slice exists

PrismCoordinator had accumulated configuration, lifecycle, payout, template, refresh, Stratum, delivery, and persistence state machines. That made lock ownership, cancellation, queue bounds, and shutdown ordering difficult to reason about. This slice establishes the target architecture: the coordinator remains the composition root and stable facade, while each domain owns its mutable state and worker lifecycle.

What changes

  • Extract configuration/RPC, shutdown admission, background-service registration, bounded execution, progress health, CTV, and payout ownership.
  • Extract template artifacts, bundle compilation/building, latest-wins tip refresh, Stratum sessions, job delivery, and share writing/recovery.
  • Wire owners through explicit narrow ports and lazy single-flight factories.
  • Keep existing coordinator call sites working through thin delegates and demonstrated compatibility exports.
  • Preserve the refresh/livelock, queue reclamation, build-priority, reconnect, and public reward-window cache behavior present at the stack base.
  • Make decimal environment parsing fail closed for malformed and non-finite values.

Why the diff is large

This is the widest ownership boundary in the stack: about 33,300 additions and 14,600 deletions across 52 files. More than 12,600 lines leave prism_coordinator.py; the corresponding logic is reorganized into cohesive owner modules, explicit port adapters, and direct owner tests. GitHub therefore counts moved-and-reshaped logic, new boundary types, and test coverage as additions rather than recognizing a simple move.

The size does not represent 33,000 lines of new product behavior. A useful review order is:

  1. configuration, shutdown, background services, and bounded executor;
  2. payout, templates, bundle construction, and tip refresh;
  3. sessions, job delivery, and share writer;
  4. coordinator _ensure_* factories, ports, and facade delegates;
  5. direct owner tests and the tight coordinator regressions.

Behavior and risk

This is a high-risk structural change because it touches mining liveness, share durability, payout state, and shutdown. Environment names/defaults and public behavior are preserved. Owners now hold their own locks, queues, counters, and cancellation; leaf services do not import the coordinator.

The current 1.x.x tip contains later retry-throttling commit e2aba4a, which is outside this reviewed slice. Final integration must port that behavior into the extracted refresh/candidate/finalization owners rather than restoring it to the coordinator.

Validation

  • 288 focused configuration, lifecycle, job, refresh, session, delivery, and share-writer tests passed at this boundary.
  • The cumulative final tree passes 1,217 PRISM and 1,551 full-discovery tests; see final validation.
  • Docker Python compile and Docker Ruff passed.
  • Existing environment contracts and the reward-window cache configuration remain covered.

Operator impact

No migration is required in this slice. Existing configuration names and defaults remain valid, including PRISM_PUBLIC_REWARD_WINDOW_CACHE_SECONDS.


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


Note

High Risk
Large refactor of coordinator mining liveness, share durability, payout publication, and shutdown paths; incorrect ownership or ordering could cause stuck jobs, lost shares, or unsafe lease release.

Overview
Pulls mining, payout, refresh, delivery, and shutdown logic out of PrismCoordinator into dedicated owner modules, with the coordinator staying the composition root and exposing thin _ensure_* facades plus compatibility re-exports.

New infrastructure includes immutable env loading (coordinator_config), a writer barrier and phased shutdown (coordinator_shutdown), named background thread registration (background_services), a bounded priority job-delivery executor (bounded_executor), and a cancelable audit-bundle subprocess adapter (bundle_compiler).

Job construction moves into JobBundleService: shared bundle cache, latest-wins scheduler (publication-critical vs routine/collection), subprocess cancellation, and metrics. CTV fanout gets a runtime wrapper (ctv_runtime) with its own loop, writer admission, and Prometheus lines. Benchmarks now read tip-refresh and job-bundle metrics from those services instead of coordinator fields.

Behavior and env contracts are intended to stay the same; risk is in lock ordering, cancellation, queue bounds, and shutdown sequencing across the new boundaries.

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

@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: 5f5ed20809

ℹ️ 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/tip_refresh.py Outdated
Comment thread lab/prism/bounded_executor.py
Comment thread lab/prism/ctv_runtime.py Outdated
@kiwidream
kiwidream force-pushed the prism-coordinator-core-owners branch from 5f5ed20 to e3b3e6d Compare July 20, 2026 14:42

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

ℹ️ 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
Comment thread lab/prism/background_services.py
Comment thread lab/prism/bundle_compiler.py Outdated
@kiwidream
kiwidream force-pushed the prism-coordinator-core-owners branch from e3b3e6d to 0cdd951 Compare July 20, 2026 15:28
Comment thread lab/prism/bundle_compiler.py
Comment thread lab/prism/coordinator_config.py
@kiwidream
kiwidream force-pushed the prism-coordinator-core-owners branch from 0cdd951 to afedf8e Compare July 20, 2026 15:34

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

ℹ️ 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 Outdated
@kiwidream
kiwidream force-pushed the prism-coordinator-core-owners branch from afedf8e to aa0257e Compare July 20, 2026 16:02

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

Comment thread lab/prism/coordinator_config.py
@kiwidream
kiwidream force-pushed the prism-test-shards branch from 920a2e6 to d8a99b5 Compare July 22, 2026 13:50
@kiwidream
kiwidream force-pushed the prism-coordinator-core-owners branch from efe2122 to 0438c70 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