Repository navigation
Description
The container's cloud prefetch charges each service as it goes, then throws all of it away if the phase runs out of wall clock. On the first hosted 2,000-page audit that was 100 ai_parse calls and 100 authority_signals calls, every one of them charged server-side and none of them reaching the report.
The charge is not recoverable from the container's side: each service call is a completed request to /v1/services/*, debited there by chargeOrReplay. So the only honest fix is the other one, keeping what was already paid for.
Where it goes wrong
prefetchCloudData (and runContainerCloudPrefetchFromPayloads above it, both in packages/audit-engine/src/cloud-prefetch-run.ts) return a single CloudPrefetchResult when the whole phase finishes. The caller bounds the phase with a wall-clock deadline, and on expiry it has a rejected promise and no way to reach anything the phase had already collected. Everything is discarded together: the store, the site metadata, and the spend lines.
Nothing partial survives because nothing partial is observable. The result is built at the end.
What would fix it
The prefetch needs to expose what it has accumulated before it finishes. Roughly, either an accumulator the caller owns and the prefetch fills in as each service returns, or a per-service callback the caller can collect from, so that abandoning the phase still leaves the caller holding every result that landed.
Whichever shape, two things have to stay true. Results that were charged for must reach cloudScope so the rules use them. And the spend lines for exactly those results must reach the caller, so the run's own accounting matches the ledger, without ever reporting a line twice.
Why now
The hosted side raised the audit page ceiling to 10,000 pages, and prefetch work scales with the crawl. squirrelscan/repo#1995 scales the wall-clock budget with page count, which makes the deadline much rarer, but rarer is not never: a hung provider still ends the phase, and today that still means paying for enrichment nobody receives.
Related: squirrelscan/repo#1995 (the budget, the private half), #1008 (which added the bound).
Acceptance Criteria
- When the cloud prefetch is abandoned at its deadline, results that had already returned are used by the rules rather than discarded
- The spend reported for an abandoned prefetch covers exactly the calls that were charged, with no line reported twice and none omitted
- A prefetch that completes normally behaves exactly as it does today, byte for byte in the report
- A test drives the deadline with some services already returned and asserts both the kept results and the reported spend
Activity
docs(cloud): say abandoned-prefetch spend lists only calls known to b…
nc9 commentedon Oct 8, 2026
Status: #582 is open and green, waiting on a human merge (credits hold list).
The cloud prefetch now fills a caller-owned
CloudPrefetchAccumulatoras each call returns. On the deadline,abandon()returns what had landed instead of throwing it away. Returned results reach the rules. Spend covers exactly the calls known to be charged, each once, including render batches charged on submit, and no new call is sent after the deadline. A prefetch that completes is unchanged byte for byte.prefetchCloudDataWithDeadlineand adeadlineMsoption on the container entry points wrap this.Each acceptance criterion is mapped to its test in the PR description. For hosted audits to pick this up, the runner that enforces the prefetch deadline needs to pass
deadlineMs(or use the accumulator) instead of racing the bare promise.fix(audit-engine): flag balanceAfter as approximate on an abandoned p…
fix(audit-engine): keep paid cloud prefetch results when the phase is…
nc9 commentedon Oct 8, 2026
Landed in #582. The engine now keeps paid prefetch results when a caller bounds the phase with a deadline; wiring the hosted runner to pass the deadline is tracked separately.