Repository navigation
fix(audit-engine): keep paid cloud prefetch results when the phase is abandoned - #582
Conversation
… abandoned The cloud prefetch built its result only when the whole phase finished, so a caller that bounded it with a deadline had nothing to recover on expiry: every result already charged server-side was discarded with the store, the site metadata and the spend lines. Add a caller-owned CloudPrefetchAccumulator that the prefetch fills as each call returns. abandon() turns it into a CloudPrefetchResult at any moment: returned results are kept for the rules, unreturned keys read service-unavailable, and spend covers exactly the calls known to be charged (including a render batch acknowledged on submit), each once. After abandon no new call is dispatched. prefetchCloudDataWithDeadline and a deadlineMs option on the container entry points wrap this so a deadline resolves with the partial result instead of rejecting. A prefetch that completes is unchanged. Refs #280 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #582 (partial-result handling for a cloud prefetch that hits its deadline). I read the full diff but did not run the tests.
No critical or high-severity issues found. |
…e charged A call still in flight when the prefetch deadline fires is not reported, so the docs and changelog no longer claim the spend is exact. Clarify the ABANDONED_STOP comment. Refs #280 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Round 1 (d22615c):
Checks on this push: |
|
Review of #582 (keep paid cloud prefetch results when the phase is abandoned). I read the full source diff and the docs and changelog changes. I did not read the new test file line by line, and I did not run the tests. No blocking problems. The design holds up: a caller-owned accumulator, an idempotent and memoized
|
|
Round 2: no critical, high or medium findings, so no push this round. Replies to the low findings and nits:
|
…-abandon-qf3efx Signed-off-by: Nik Cubrilovic <[email protected]> # Conflicts: # CHANGELOG.md
|
Review of #582 (partial results when the cloud prefetch hits its deadline)
Test coverage is good: the new |
|
Round 3: rebuttals, no code change.
This was the third and final bot-review round, so I'll stop iterating and leave further calls to the maintainer. |
|
Status: ready for a human merge (hold list, credits).
|
Signed-off-by: Nik Cubrilovic <[email protected]>
…refetch A call still in flight when the prefetch is abandoned is not in the spend but may yet be charged, so an abandoned result now carries balanceAfterApproximate whenever it has a balance figure. Completed results are unchanged and never carry the key. Reword the changelog entry and the credits docs to describe the engine capability (keeping paid results when a caller bounds the prefetch with a deadline) rather than shipped hosted behaviour: nothing in this repo passes deadlineMs yet. Refs #280 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the diff for No blocking problems found. The accumulator design holds up.
Test coverage looks good: the new file covers render charged-on-submit, hung providers and the container path. |
|
Review on 49cfecd: no critical, high or medium findings, so no push. This head was the single push requested for the maintainer's changes.
|
* origin/main: feat(core-contracts): audit levels definition (quick, surface, full) (#602) test(rules): restore the real fetch when a graphql test stubs twice (#599) chore(release): v0.0.107 (#595) docs(changelog): release notes for v0.0.107 (#594) feat(rules): add GraphQL introspection and GET mutation probing rules (#593) fix(audit-engine): keep paid cloud prefetch results when the phase is abandoned (#582)
Refs #280
Hold list (credits): a human merges this.
Summary
The cloud prefetch built its
CloudPrefetchResultonly when the whole phase finished. A caller that bounds the phase with a deadline was left with a rejected promise on expiry, and everything already charged server-side (results, site metadata, spend lines) was discarded.How paid results are now preserved and reused
CloudPrefetchAccumulatoris passed in asinput.accumulator. The prefetch writes into it as each call returns. Stage 0 (site metadata) and the site-unit services land their envelope and spend line when their call resolves. Each page-unit batch records its outcome the moment it returns.abandon()turns the accumulator into a normalCloudPrefetchResultat any moment:cloudScopeand the rules use them. The page-unit merge is the same batch-order merge the completed path does.skipped/service-unavailable. This only fills gaps, so nothing that returned is overwritten. Afailuresrecord with detailprefetch deadline reachedmarks the lost coverage.abandoned: true. When it has a balance figure, it also carriesbalanceAfterApproximate: true.prefetchCloudDataWithDeadline(input, ms)and adeadlineMsoption onrunContainerCloudPrefetch/runContainerCloudPrefetchFromPayloadsrace the prefetch against the deadline. When the deadline wins they resolve withabandon()instead of rejecting. A caller that enforces its own deadline can passaccumulatorand callabandon()itself.Charging semantics
renderbatch is charged when it is submitted, so a batch whose submit was acknowledged counts as spent even if its job had not finished. Its pages readservice-unavailable, the same treatment a render poll timeout gets today.keyword-gaps, is not counted. Its response has not arrived, so the container cannot know whether the server will charge it. Because it may yet be charged,balanceAfteron an abandoned result is flaggedbalanceAfterApproximate: true. The server ledger and the account balance stay authoritative, as before. No new call is dispatched after the deadline, so this window is limited to calls already on the wire.abandon()is idempotent and memoized, and its result is built from copies. Calls that land after it never reach a result the caller already holds. If the prefetch finished first,abandon()returns that completed result object unchanged.abandonedorbalanceAfterApproximatekey.Rollout note
This PR adds the engine capability. Nothing in this repo passes
deadlineMsor an accumulator yet: the CLI never bounds the prefetch, so CLI audits are unchanged, and the hosted runner will adopt the option separately. The changelog entry anddocs/cloud/credits.mdxdescribe the capability, not shipped hosted behaviour.Agent skill
The squirrelscan agent skill needs no change. Nothing changes in CLI flags, output shape or rule ids, and
service-unavailablewas already a documented skip reason.Acceptance criteria
packages/audit-engine/tests/cloud-prefetch-abandon.test.ts, "a deadline with some services returned keeps their results...". After the deadline,site-metadata,keyword-gapsand the returned render pagep0areokin the store, and the other pages readservice-unavailable. "container path: deadlineMs keeps what returned instead of rejecting" covers the same path throughrunContainerCloudPrefetchFromPayloadswith the default rule set.spend= keyword-gaps 25 + render 2 units / 4 credits. Those are p0, which returned, and p1, whose submit was acknowledged. p2 to p4 (no submit acknowledged) and p5 (never sent) are excluded. The test also checkstotalSpent29,balanceAfter971 withbalanceAfterApproximate: true, and the failure record. "an abandoned run dispatches nothing more, and late results never reach the result" releases a hung submit after abandon. It asserts that no new batch is sent, thatabandon()returns the same object, and that spend and store are unchanged.toEqualand identical serialization. It also checks there is noabandonedorbalanceAfterApproximatekey, and thatabandon()after completion returns the completed result. The existingtests/cloud-prefetch.test.ts(50 tests) and the CLI parity tests pass unchanged.prefetchCloudDataWithDeadline(..., 50)over a client where some calls resolve, one render job hangs after an acknowledged submit, and others never answer.Verification
Run on head 49cfecd, after merging
main:bun test tests/cloud-prefetch-abandon.test.ts tests/cloud-prefetch.test.tsinpackages/audit-engine: 55 pass, 0 fail.bun test tests/audit/cloud-prefetch-parity.test.ts tests/audit/cloud-prefetch-non-public-base.test.tsinapps/cli: 23 pass, 0 fail.bun run typecheckinpackages/audit-engineandapps/cli: clean.bun run format:check(root): pass.oxlinton the touched files: no new warnings.make validateindocs: all checks passed.bun run test:release: 19 pass.detect-secrets-hook --baseline .secrets.baselineon the changed files: clean.Checklist
Signed-off-byline (git commit -s).