Repository navigation
perf(engine): start page rules on pages whose cloud prefetch has finished (#2121) - #2185
Merged
Merged
Conversation
3 tasks
…shed (#2121) LateCloudResults binds a running prefetch to runStreamingRules: the runner is built once Stage 0 decides the site profile, each page's rules run once CloudPrefetchAccumulator.pageEnvelopes says its envelopes are final, and the site rules run on an exact copy of the settled store (batch order, abandon skips included). The prefetch's own store is never written live, so the awaited result is unchanged. With a rule cache, pages keyed before the prefetch settles bypass it; later pages use the serial run-context key. Signed-off-by: Nik Cubrilovic <[email protected]>
…adline drops its cloud waiter #2121 Review fixes for pub#2185: - LateCloudResults records a rejected prefetch (failed); runStreamingRules then never binds the late rule cache, so pages that ran on early results are never stored under a key hashing an absent store and site profile. - streamPageRules aborts the cloudReady wait when deadlineAt wins; pageReady and CloudPrefetchAccumulator.changed take the signal and remove their waiter instead of leaving it parked. - Tests: rejection mid-run, deadline during a cloudReady wait, stream batches straddling settle, a plugin pack waiting for settle, Stage-0 failure / skipAll / emptyResult waking waiters, a url in two batches. Signed-off-by: Nik Cubrilovic <[email protected]>
…clock, not wall time #2121 Signed-off-by: Nik Cubrilovic <[email protected]>
Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
boat/engine-early-rules-2121
branch
from
November 22, 2026 12:25
2ab3376 to
149bee0
Compare
nc9
marked this pull request as ready for review
November 22, 2026 12:46
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.
Closes #2121 (option A, planning's decision).
What changed
CloudPrefetchAccumulator(src/cloud-prefetch.ts) gains per-page readiness on its existing state:pageEnvelopes(url)returns every envelope the final store will hold for that page, or null while one can still change;changed()wakes a reader when a batch lands, a service finishes, Stage 0 decides or the run settles/abandons;resultexposes the settled result. No new event or budget mechanism:onCall, the budgets and the dispatch are untouched, and the prefetch's own store is still written only by the batch-order merge.LateCloudResults(src/late-cloud-results.ts, exported) binds a running prefetch to the rules. It owns the store the runner reads: a page about to run gets its own final envelopes copied in; on settle the store is rebuilt as an exact copy of the result store (batch order, abandon skips included).runStreamingRules({ lateCloudResults }): universe and site-fetch overlap the prefetch; the runner is built once Stage 0 decides the site profile;streamPageRuleswaits per page (cloudReady, bounded bydeadlineAt); the site rules run on the settled store. Plugin rule packs wait for settle before the page pass. Without the option nothing changes.prefetchCloudDataWithDeadlinetakes an optional caller-owned accumulator;runContainerCloudPrefetchFromPayloadspassesinput.accumulatoron its deadline path.Cache key: option (i)
Pages whose batch is keyed before the prefetch settles bypass the rule cache (null key: no read, no write).
lateBoundRuleCachebinds on the first key asked after settle, hashing the settled store with the samecomputeRunContextHashinputs as the serial path, so those pages use exactly the serial key. The serial branch hashesscopeas before (same inputs, same call).rule cache: the serial key and hits are unchanged; late pages after settle hit them, early ones neither read nor write. A serial cold run stores 24 entries and a serial warm run replays all 24. A late run that settles first replays the same 24 and adds no new key. A late run with render batch 0 held stores 0 and replays 0, and its report is still identical.the run-context hash of the settled late store equals the serial store's.Acceptance criteria
src/late-cloud-results.tspageReady,src/cloud-prefetch.tspageEnvelopes,src/streaming.tscloudReady, wired insrc/adapter.tsrunStreamingRules. TestAC1: page rules run on pages whose prefetch finished while a later render batch is still out: the last render batch is held until a page's rules have written, then released by that write, not by the backstop. Mutation (the page pass waits for settle) fails it.AC2: with batch 0 slow, the awaited store is in batch order, and so is the late view once settled. The awaitedprefetchCloudDatarender keys start with p0. The view, filled p1, p2, p3 before p0, is rebuilt in batch order on settle. Live writes go to the binder's view, never the prefetch store, so no delete-then-set is needed there; the rebuild is the reorder. Fail-before by mutation: patching the view instead of rebuilding it fails the test.AC3: a batch that lands after abandon() does not overwrite the abandon's skips. Abandon at 100 ms, then the held batch lands and merges into the prefetch's own store. The abandon result,pageEnvelopesand the rules' store all keepprefetch-out-of-time. Fail-before by mutation: binding fromacc.store, or readingacc.storein the settled branch ofpageEnvelopes, each fails it.tests/late-cloud-results-golden-2121.test.ts. 518 pages, every cloud rule on, deterministic stub cloud, render batch 0 at 150 ms and the rest at 10 ms. The serial and late runs give identical golden snapshots and identical report JSON (timestamps removed). Small-fixture twin:AC4 (small fixture).bun run packages/audit-engine/scripts/bench-late-cloud-results.ts --runs 2Latency model: canonical golden fixture, 500 cloud page payloads, no network. Stage 0 site-metadata 1500 ms. Each site-unit service 500 ms. ai-parse and authority-signals 500 ms per batch. Render 2000 ms per batch, paid on submit. Batch size 10 (render's cap) with 4 batches in flight. Both arms are timed from prefetch start to rules returned. Page readiness needs every page-unit service, and render runs last, so the overlap covers the universe and site-fetch phases plus page rules during the render batches.
Gates
cd packages/audit-engine && bun run typecheck: clean.cd apps/cli && bun run typecheck: clean.bun run format:checkandbun run lint: exit 0 (audit-engine has no format/lint script).bun run scripts/test-suites.ts --check: test suites cover every test file.bun run scripts/test-suites.ts --run audit-engine: 2375 pass, 3 skip, 0 fail (2378 tests, 250 files).bun run scripts/test-suites.ts --run cli: 4574 pass, 14 skip, 0 fail (4588 tests, 395 files).Notes
lateCloudResults(follow-up in the private repo). The CLI path stays serial.Review fix round (c9f3cef)
LateCloudResults.failedrecords a rejected prefetch, and the late cache binder inrunStreamingRulesthen returns null, so every page in that run gets a null key (no read, no write). Test:a prefetch that rejects mid-run writes nothing to the rule cache, does not throw, and the report is produced(fails without the guard: entries get stored under a key hashing an absent store and site profile).streamPageRulesaborts the cloud wait whendeadlineAtwins.pageReady(url, signal)andCloudPrefetchAccumulator.changed(signal)remove their waiter instead of leaving it parked until the next change. Test:deadlineAt expiring during a cloudReady wait ends the page pass and leaves no waiter parked(one waiter is parked before the deadline and none after; it fails without the abort, and it fails when pageReady ignores the signal).lateBoundRuleCacheunit test of one key loop straddling settle). A plugin rule pack waits for settle. Stage-0 failure,skipAll(preflight failure and cloud disabled) andemptyResulteach wake the waiters. A url listed in two batches is final only once both batches have returned, and it carries the later batch's envelope.test-suites --checkpasses.--run audit-engine: 2395 pass, 3 skip, 0 fail.--run cli: 4583 pass, 14 skip, 0 fail.Scope notes
lateCloudResultsis the follow-up squirrelscan/repo#5025. Until then, no run takes this path.