Skip to content

Cloud prefetch discards results it has already paid for when the phase is abandoned #280

Closed

Description

@nc9

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

  1. added
    bug
    P2
    size: M
    on Sep 23, 2026
  2. nc9 commented on Oct 8, 2026

    @nc9
    ContributorAuthor

    Status: #582 is open and green, waiting on a human merge (credits hold list).

    The cloud prefetch now fills a caller-owned CloudPrefetchAccumulator as 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. prefetchCloudDataWithDeadline and a deadlineMs option 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.

  3. nc9 commented on Oct 8, 2026

    @nc9
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bugsize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions