Skip to content

fix: default plugin intelligence report exceeds its daily-row scan budget - #4946

Merged
Patrick-Erichsen merged 3 commits into
mainfrom
fix-search-report-scan-budget
Nov 24, 2026
Merged

Patrick-Erichsen merged 3 commits into
mainfrom
fix-search-report-scan-budget

Conversation

@Patrick-Erichsen

Copy link
Copy Markdown
Collaborator

Summary

The staff ClawHub intelligence page fails on its default view (Plugins, both sources) with "The report could not be completed. Refresh to retry." Refreshing cannot help: the report reads 30 days of daily search facts in 500-row pages and stops at 200 pages, and plugin demand across both sources is now about 173,000 rows. Each of the three Workpool attempts reads the same 100,000 rows and fails the same way.

What changed

  • Row budget counts rows, not pages. The reader now uses 4,000-row pages and allows 400,000 daily rows. The limit no longer depends on the page size.
  • Memory is bounded separately. Rows do not bound memory, because each row can introduce a new query and every distinct scoped query is held until ranking. Production already holds up to 86,000 distinct plugin queries in the window. The reader now keeps numeric counters per query (210 bytes measured, down from about 440 for a full report row), builds full rows only for the returned shortlist, and fails explicitly past 120,000 distinct queries, which is about 25 MB of the 64 MB action.
  • An over-budget report ends after one attempt with report_scan_budget_exceeded instead of retrying twice under the generic report_collection_failed.
  • Management explains that outcome by its remedy ("Choose a single source, then try again.") instead of offering a refresh that cannot succeed. Source is the only filter that narrows the scan; scope and view apply after it.
  • specs/search-insights.md records both budgets, the measurements behind them, and the point at which a per-query rollup should replace reading daily facts.

Output is unchanged: same rows, ranking, tie order, totals and truncation. The synchronous GET /api/v1/search-insights and the weekly digest share this reader and get the same budgets.

Evidence

Production, 2026-11-23 UTC, before this change:

  • Default request (demand, plugin, both sources): failed, report_collection_failed, 3 attempts; logs show listDailyInternal called exactly 600 times (3 x 200 pages).
  • Same request with one source: ready in 26-27 s (about 85,000 and 88,000 rows read).
  • 30-day distinct queries: 36,440 (Control UI), 49,222 (web), 48,581 (skills, both sources).

Local, real Convex backend and real browser, fixture of 173,400 plugin daily rows and 86,700 distinct queries:

Default view Result
Before (11f93592908) fails after 3 attempts "The report could not be completed. Refresh to retry."
After ready on the first attempt table renders: 104,040 searches, 20,230 matching queries
After, 240,800 rows / 120,400 queries fails once, report_scan_budget_exceeded "This selection has more search data than one report can analyze. Choose a single source, then try again."

Screenshots are in the first comment.

Tests

  • convex/searchInsights.test.ts: a 173,000-row combined-source window reads completely (fails on main with "Search aggregate scan budget exceeded"); the row budget and the query budget each stop on the first page past the limit; a window at both budgets reads.
  • convex/searchReports.test.ts: an over-budget scan through the real report owner, evidence collector and reader throws a non-retryable error, records report_scan_budget_exceeded once, and leaks no query text. The database boundary is simulated there because the budget is far larger than a fixture.
  • src/routes/-management/SearchInsightsPage.test.tsx: the failure code selects the remedy message.

Commands run on this head:

VITE_CONVEX_URL=https://example.invalid bunx vitest run convex/searchInsights.test.ts convex/searchReports.test.ts convex/featuredIntelligence.test.ts convex/searchWeeklyDigest.test.ts convex/lib/featuredIntelligence.test.ts convex/lib/searchEvidenceDigest.test.ts convex/lib/searchDigestRows.test.ts convex/crons.test.ts src/routes/-management/SearchInsightsPage.test.tsx packages/clawhub-admin/src/commands/searchInsights.test.ts   # 94 passed
bun fmt --no-script --check   # bun 1.4.4
bun run lint
bun run deadcode:ci
bunx tsc --noEmit && bun run ci:types:packages
bun run test:pw:local-auth -- --project=chromium <temporary proof spec>   # baseline and candidate

bun run ci:unit locally: 10,514 passed, 13 failed, all in five scripts/security/* files that timed out while the browser proof ran alongside; those five files pass in isolation on this head (164 tests). Autoreview (Codex, P3) reported one P2 on the first head, that rows did not bound memory; the third commit addresses it and the re-review is clean.

Limits

  • Headroom is finite. At current volume the plugin view uses about 43% of the row budget and at most 72% of the query budget. The spec names the rollup that should replace this scan before then.
  • The weekly digest runs several of these reads concurrently in one action. This change does not alter that; its memory use at production volume was not measured here.
  • Memory figures were measured in Node, not in the Convex runtime.

The default plugin report scans 30 days of daily facts for both sources.
Production passed the 200-page, 100,000-row budget, so every default
report failed. Count rows instead of pages, read 4,000-row pages, and
raise the budget to 400,000 rows, which the 64 MB action can still hold.
…medy

A scan that exceeds the row budget reads the same rows on every retry.
Record report_scan_budget_exceeded, skip the two pointless retries, and
have Management say that a single source narrows the selection instead
of offering a refresh that cannot succeed.
…report memory

Rows alone do not bound memory: each daily row may introduce a new query,
and production already holds up to 86,000 distinct plugin queries in the
30-day window. Keep numeric counters per query (210 bytes measured, down
from about 440 for a full row), build full rows only for the returned
shortlist, and fail explicitly past 120,000 distinct queries.
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clawhub Ready Ready Preview Nov 24, 2026 3:03am UTC

Request Review

@clawsweeper

clawsweeper Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@Patrick-Erichsen

Copy link
Copy Markdown
Collaborator Author

Real-browser proof from a local ClawHub (local Convex backend, dev-auth admin persona, /management?view=search-insights). Fixture: 173,400 plugin daily rows and 86,700 distinct queries across both sources in the 30-day window, seeded by a temporary local-only function that is not part of this PR.

After (this PR): the default view completes on the first attempt

After: default view renders

After, pushed past the query budget (240,800 rows, 120,400 queries): one attempt, then the remedy

After: over-budget message

Before (main at 11f9359), same fixture: three attempts, then the generic failure

Before: default view fails

After: default view renders

After: over-budget message

Before: default view fails

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR increases report scan capacity, reduces retained query memory, and gives over-budget reports a terminal outcome with source-filter guidance.

Example: Staff opens the default Plugins report with 173,400 daily rows across both sources.

  • Before: The report exhausts its 100,000-row allowance on three attempts and displays a generic retry message.
  • After: The supplied local browser proof shows 104,040 searches and 20,230 matching queries.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with inspected browser proof and passing exact-head checks; capacity remains deliberately finite.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected browser captures exercise the changed report reader through local ClawHub, local Convex and the staff management route: the large default fixture renders its report, the oversized-query fixture displays source-filter guidance, and the baseline fails; screenshots do not independently establish attempt counts or peak memory, and the PR discloses unmeasured weekly-digest concurrency and Node-only memory estimates.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Staff cannot load the default Plugins intelligence report, and refreshing repeats the same failed scan.
Reason: The maintainer-authored change restores an existing staff workflow without changing report selection policy, authorization or persisted formats.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still has the demonstrated default-report failure, and this maintainer-authored PR provides a focused repair. No blocking findings.

Priority: P2
Reviewed head: 859c227edb0de554c2277828aaba64680944fec9

Before merge

None.

Findings

None.

Agent review details

How this fits together

Staff dashboard requests enter the saved-report Workpool; its evidence collector reads paginated daily aggregates through the shared report reader and returns ranked counts and current catalog associations.

flowchart TD
  A[Staff dashboard] --> B[Saved report owner]
  B --> C[Workpool job]
  C --> D[Shared report reader]
  E[Daily search aggregates] --> D
  D --> F[Ranked report evidence]
  F --> A
Loading

Technical review

Best possible solution:

Land the bounded repair in the existing shared reader and retain the documented per-query rollup as the future capacity path.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically rejects a window needing more than 200 pages of 500 rows, and the supplied baseline browser capture shows the reported failure with the large fixture; no target code was executed during this review.

Is this the best way to solve the issue?

This is an acceptable immediate capacity repair at the shared owner: larger bounded pages and compact counters preserve complete results, while deterministic budget failures stop retrying; changing only dashboard retries would leave the cause intact, and introducing a rollup now would require a broader storage change.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 11f935929080.

Provenance checked

  • Shared reader scan bounds and accumulated report rows changes intended behavior with a stated reason (unknown: The specification requires complete bounded scans and explicit failure rather than partial demand. The reader extraction in refactor: separate search report reads from maintenance #4925 preserved that contract; local pickaxe and historical-blob reads could not establish the cap's exact introduction because required objects are unavailable.)
  • Background report retries and sanitized failures changes intended behavior with a stated reason (05cee54: feat: run ClawHub intelligence reports in the background #3746 introduced bounded background generation with retry and query-free error handling; this PR preserves sanitization while distinguishing a deterministic capacity failure.)
  • Dashboard report recovery guidance changes intended behavior with a stated reason (05cee54: The background-report lifecycle supplied refresh-based recovery; this PR explains why an unchanged over-budget selection needs a narrower source instead.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main failure boundary: The pinned main reader requests 500 daily rows per page and throws after 200 pages, independently of the requested output shortlist. (convex/lib/searchInsightRead.ts:41, 11f935929080)
  • Introduced repair: The pinned introduction diff counts scanned rows, retains compact counters, preserves filtering and ranking, and constructs full output rows only for the shortlist. (convex/lib/searchInsightRead.ts:77, 859c227edb0d)
  • Inspected browser proof: Patrick-Erichsen's proof comment describes local ClawHub, local Convex and an admin persona. All three attached images were inspected: candidate populated report, candidate over-budget guidance, and separately labeled baseline failure. fix: default plugin intelligence report exceeds its daily-row scan budget #4946 (comment). (859c227edb0d)
  • Exact-head validation: GitHub reports successful static, unit, types-build, packages, e2e-http and playwright-local-auth checks for the reviewed head; live PR metadata reports a clean merge. (859c227edb0d)
  • Saved-data compatibility: searchReportRuns.failureCode already accepts any optional string, and the client accepts string or null; report versions, request normalization and evidence encoding remain unchanged. (convex/schema.ts:4163, 859c227edb0d)
  • Feature history and ownership: History identifies Patrick Erichsen across the dashboard, background-report lifecycle and subsequent intelligence work; Vincent Koc carried the shared-reader extraction in refactor: separate search report reads from maintenance #4925, whose stated contract preserved bounds and failure handling. Some historical blob reads and pickaxe searches failed because lazy fetching is disabled, so exact introduction of the original scan cap remains unverified. (convex/lib/searchInsightRead.ts:41, 11f935929080)

Likely related people:

  • Patrick Erichsen: Raw commit 05cee54 adds convex/searchReports.ts:203 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 05cee5498a7c; files: convex/searchReports.ts)
  • Vincent Koc: Raw commit fa92e0d adds convex/lib/searchInsightRead.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: fa92e0dcc50a; files: convex/lib/searchInsightRead.ts)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Change footprint Production +149/-67; tests +158/-2; specification +17/-2 Production growth implements compact accumulation and terminal budget handling; tests cover the large window, budget failures and visible guidance.

Labels

Label changes:

  • add P2: The default staff intelligence report fails at current production volume, with a limited staff-facing blast radius and a single-source workaround.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The default staff intelligence report fails at current production volume, with a limited staff-facing blast radius and a single-source workaround.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 23, 2026, 10:14 PM ET / November 24, 2026, 03:14 UTC.

@Patrick-Erichsen
Patrick-Erichsen merged commit 722b2e0 into main Nov 24, 2026
86 of 88 checks passed
@Patrick-Erichsen
Patrick-Erichsen deleted the fix-search-report-scan-budget branch November 24, 2026 03:15

This branch was successfully deployed

1 active deployment
Preview – clawhub — 859c227e Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant