Repository navigation
Reduce PRISM shared tip-refresh bundle latency - #58
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df3332d517
ℹ️ 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".
| record_phase_metrics = bool( | ||
| getattr(self._job_build_phase_local, "tip_refresh_metrics", False) | ||
| ) |
There was a problem hiding this comment.
Initialize job-build state before reading metrics scope
When build_audit_bundle() is called on focused/alternate coordinator instances that have not gone through __init__ or _ensure_job_cache_state() yet, this new direct access to _job_build_phase_local raises AttributeError before the builder subprocess is invoked. That breaks the existing __new__-based tests and any lightweight coordinator path that previously could call build_audit_bundle() directly; call _ensure_job_cache_state() first or guard the attribute lookup.
Useful? React with 👍 / 👎.
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
Summary
Why this design
Profiling a 1,000,000-share refresh showed that serialization/copying dominated: the old builder input was 380.7 MB. The compact job-summary representation reduces that input to 70.8 MB. The deterministic Rust stage is already isolated behind an exec-style subprocess; adding another long-lived multiprocessing layer would retain the copying cost and expand key access. This patch therefore keeps signing behavior and the existing process boundary unchanged, explicitly closes inherited file descriptors, and adds a fail-closed timeout instead of introducing another worker pool.
The keyed flight implementation admits different work identities independently. Identical requests still coalesce, while a new tip/template/payout generation can start immediately and cancels the obsolete subprocess. Artifact preparation is bounded to one thread and one latest-generation request slot.
Benchmarks
All runs used the release Rust builder, 16 clients, the benchmark's production-derived injected I/O latencies, and 128 payout identities routed through CTV settlement.
1.x.xTarget-sized prepared-artifact validation used 21,868 shares, 128 CTV payout identities, and five independent runs:
Every target-sized sample completed under one second. Supersession tests additionally prove that a blocked old generation is canceled and cannot publish or retain a result.
Correctness and safety
close_fds=True, and never receive coordinator sockets, locks, clients, or database objectsValidation
qbit-prismRust tests across all targetsDeterministic coverage includes identical single-flight deduplication, blocked-old/new-generation supersession, obsolete-result rejection, compact/full and artifact/inline parity, subprocess crash/timeout recovery, inherited-socket rejection, repeated supersession bounds, and immediate first delivery from a valid prepared artifact.
Note
Medium Risk
Changes sit on the payout/job-build hot path (ledger snapshots, subprocess signing, cache keys, and supersession) where bugs could delay work or serve stale bundles, but parity tests and fail-closed fencing aim to preserve deterministic audit output.
Overview
This PR targets PRISM ready-pool tip refresh latency by moving ledger work off the critical path and making shared bundle builds cheaper and easier to abandon when tips or payout generations move.
The coordinator can precompute and publish a
PayoutLedgerArtifact(bounded share window + prior balances, fenced by accepted-share counts) and stamp job-bundle cache keys with tip hash, payout generation, and artifact generation. Valid artifacts skip PostgreSQL snapshot/balance work during timed refreshes; a single-threaded preparer keeps scheduling bounded.Shared bundle preparation now uses per-identity single-flight with subprocess cancel/terminate on superseded tip or payout generation,
PRISM_BUNDLE_BUILD_TIMEOUT_SECONDSfail-closed timeouts,close_fdson audit-builder children, and stricter discard rules before cache or delivery. Job-summary builds send a compact, identity-interned share payload toqbit-prism-build-audit-bundle(full canonical input unchanged); the Rust CLI adds--phase-metricsandprofile_audit_buildphase timings fed back into coordinator metrics.PostgreSQL reward-window selection switches from per-share recursive probes to 4,096-row pages with the same cutoff semantics. Rust
compute_prism_windowusesHashSetduplicate detection and an O(n) reverse when shares are already ascending. Observability expands with tip-refresh build phase histograms, queue/inflight/single-flight/supersession counters, and builder IPC byte totals; the job-build benchmark gains miners, CTV settlement, and precompute-artifact modes.Reviewed by Cursor Bugbot for commit 8babe8f. Bugbot is set up for automated code reviews on this repo. Configure here.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.