Repository navigation
Make PRISM share-window reads scale with the window, not ledger history (1.x.x) - #115
Merged
Merged
Conversation
The paged cutoff walk finds the reward-window boundary in O(window), but the snapshot's final ranking pass consumed that cutoff by joining the one-row cutoff CTE into the scan. The planner applies a joined cutoff as a post-scan filter, so the pass was free to walk the entire accepted history backwards and discard everything below the boundary, making each execution cost O(history) instead of O(window) as the ledger grows. Consume the cutoff as a scalar subquery instead: it plans as an InitPlan the backward index scan uses as its start bound, keeping the final pass proportional to the window. Port qbit_prism_window() from its one-row-per-step recursion (one lateral index probe per share) to the same paged walk with the same bounded final pass. Window contents are unchanged: identical rows, cumulative sums, and partial-credit boundary behavior, verified row-for-row against the previous shapes on a synthetic 500k-share ledger across a boundary-stress weight grid (exact cumulative boundaries, page boundaries at 4095/4096/4097, single-share and full-history windows), plus byte-identical snapshot JSON output. Co-Authored-By: Claude Fable 5 <[email protected]>
The bounded branch of snapshot_at_job_issue was only pinned by query-text assertions; the live-Postgres check exercised just the unbounded branch. Assert the crossing share is included and nothing past it at exact cumulative boundaries, and that a beyond-history weight matches the unbounded snapshot. Co-Authored-By: Claude Fable 5 <[email protected]>
Every existing fixture fits inside one 4096-row cutoff page, so the recursive page step of both bounded window readers never executed in any committed test. Seed 9000 deterministic unit-difficulty shares and assert exact row counts and boundary share IDs for the bounded snapshot (weights straddling the 4096/8192 page boundaries, exact-history, and beyond-history) and for the audit window path through qbit_prism_window() (window weights 4096, 8192, and a page-3 crossing). Also pin the schema to exactly one windowed difficulty sum, and note at both walk sites that page-granular stopping relies on the strictly positive share_difficulty constraint. Co-Authored-By: Claude Fable 5 <[email protected]>
Member
Author
|
CI note: the "Lint, compile, and test" job on this branch inherits a pre-existing hang on the current |
This comment has been minimized.
This comment has been minimized.
This was referenced Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PRISM's reward-window readers find the window's lower boundary cheaply (the 4096-row paged cutoff walk introduced in #58), but then consume that boundary in a way the planner cannot use:
snapshot_at_job_issue(the job-build/audit window snapshot) joined the one-rowpage_cutoffCTE into its final ranking pass. A joined cutoff is applied as a post-scan join filter, so the backward pkey walk is free to visit the entire accepted history on every execution and discard everything below the boundary — O(history) per call, growing linearly as the ledger grows, on paths that run continuously (payout-artifact builds, payout publication, reconcile candidate preparation).qbit_prism_window()function (settlement/audit paths) still used the pre-Reduce PRISM shared tip-refresh bundle latency #58 recursion: one lateral index probe per share, i.e. window-size probes per call.This change:
qbit_prism_window()to the same paged walk with the same bounded final pass.Window contents are unchanged: identical rows, cumulative sums, and partial-credit crossing behavior.
Verification
Against a synthetic 500k-share ledger on Postgres 16 (anchor mid-history so ~10% of rows are ineligible, including accept-lag rows straddling the anchor; ~3% rejected rows):
qbit_prism_window():EXCEPT ALLin both directions returns zero rows across a 27-weight boundary-stress grid — exact cumulative boundaries (cum(k)-1,cum(k),cum(k)+1for k in {1, 2, 1000, 4095, 4096, 4097, 8192, 20000}), a single-unit window, and a beyond-total-history weight (447,565-row full window).Tests
python3 -m unittest tests.test_prism_share_ledger— 139 tests, OK (query/schema shape assertions updated: the cutoff must appear as the scalar-subquery start bound, andCROSS JOIN page_cutoffmust not reappear)python3 -m unittest tests.test_prism_reward_window_invariant tests.test_prism_incremental_payout_window— 5 tests, OKmake test-prism-postgres-ledger— live Postgres 16 end-to-end check, extended here to assert the bounded snapshot's crossing behavior at exact cumulative boundaries (window weights 1/103/104/205/206 over known share difficulties) and that a beyond-history weight returns the same rows as the unbounded snapshot. The rewrittenqbit_prism_window()is executed by the same check via the audit window path.🤖 Generated with Claude Code
Note
Cursor Bugbot is generating a summary for commit 3c2a42a. Configure here.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.