Repository navigation
fix: reduce memory during SQLite usage refresh - #201064
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR releases navigation records and consumed billing entries earlier during SQLite usage aggregation. Example: Refresh 270,391 billed messages with distinct millisecond timestamps.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this PR provides a focused, useful memory reduction with no identified correctness defect; the new Gateway evidence satisfies the previous proof request, while draft status and production CI remain outstanding. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe background usage worker reads SQLite transcript events, resolves billing and branch ancestry, aggregates timestamp buckets, and prepares usage-cache partitions. flowchart TD
A[SQLite transcript events] --> B[Paged transcript reader]
B --> C[Billing and ancestry selection]
C --> D[Release navigation records]
D --> E[Drain entries through pricing batches]
E --> F[Exact timestamp rollup]
F --> G[Usage cache publication]
Technical reviewBest possible solution: Retain this small lifetime optimization in the existing scan owner while keeping the broader production OOM report open. Do we have a high-confidence way to reproduce the issue? Source confirms overlapping retention of navigation, billing entries, and growing timestamp buckets; contributor measurements demonstrate the reduction, but this review did not independently reproduce the reported production OOM. Is this the best way to solve the issue? The patch is a small, appropriate optimization: compute navigation facts first, release the owned projection, preserve billing order, and avoid strong timing keys without changing accounting or storage contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7ce2d10eced5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11. Total +11 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 18, 2026, 12:42 PM ET / 17:42 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…irement-rule * origin/main: (172 commits) test(gateway): expect a revoked person's Goal retry to be hidden as not found (#205698) fix: keep browser disabled when only hardening relay authentication (#203137) fix: recover Linux stream automations after command-anchor crashes (#203149) fix(whatsapp): identify voice-note captions as text in delivery receipts (#205381) fix(test): unblock restart-auth plugin and worker publication qualification (#205679) chore(ui): refresh control ui locales (#205691) fix: reduce memory during SQLite usage refresh (#201064) fix(plugins): readmit native captures with a dangling host link chore(i18n): refresh native locales (#205680) fix(update): hash SQLite lock bytes as zeros so Windows exclusion cannot fail verification (#205668) fix(skill-workshop): skip the skill diet for skills with Markdown outside support directories (#204881) fix(plugins): clarify dated SDK migration notices (#200932) fix: keep the resident launcher when reinstalling Gateway (#205655) fix: show the whole reply when you reopen a TUI session (#200455) test(ui): wait for restored speech player authorization (#199502) feat: let agents post approved GitHub comments (#204301) fix(agents): honor imageMaxDimensionPx at the provider and CLI image handoffs (#205663) chore(ui): refresh control ui locales (#205664) fix(google): preserve playback when Google Live splits audio into parts (#205364) fix: show named characters in exported session messages (#205362) ...
Co-authored-by: Fuma2013 <[email protected]>
Co-authored-by: Fuma2013 <[email protected]> (cherry picked from commit 625045f)
Co-authored-by: Fuma2013 <[email protected]> (cherry picked from commit 625045f) Companion audit: 740dfdb changes UI throughput metrics and c821a8a changes whole-refresh history building; independent of draining consumed inherited projections. Co-authored-by: RomneyDa <[email protected]>
Related: #197430
What Problem This Solves
The background usage refresh can run out of memory on long SQLite chat histories, leaving token and cost totals stale. The paged reader limits decoded payloads, but the worker retains the navigation projection and every parsed billing entry while building the exact-timestamp rollup.
User Impact
Lower peak heap during SQLite usage refresh without widening time buckets, dropping entries, or changing the cache format. No configuration change or migration.
Why This Change Was Made
Resolve billing, latency ancestry and the checkpoint first. Release the navigation projection, then drain the owned billing list in the same order into the existing pricing batches. The latency lookup uses weak keys so it does not keep processed entries alive. Exact buckets still scale with the number of distinct timestamps; this reduces overlapping memory, not the size of the final rollup.
Evidence
End-to-end Gateway proof
Tested the unchanged PR head
91e8b402593a1fbd9ef07a32963d481ca7a3f67d(macOS arm64, Node 24.22.3). Seeded a fresh, isolated agent SQLite store through the existing transcript batch writer with 270,391 synthetic billed messages, each at a distinct millisecond. Started the real loopback Gateway with its usage sidecar enabled, without a heap override or mocks for the worker, SQLite, or cache. Polledsessions.usagefrom an empty cache until fresh, asserted exact expected totals, and checked the persisted SQLite cache after clean shutdown.Redacted terminal evidence (selected fields; the worker measurement uses sampling, not forced GC):
The worker was sampled externally with Node's
Worker.getHeapStatistics()while the Gateway owned the real refresh. This is a candidate-only end-to-end pass; the separate post-GC benchmark above is the before/after comparison. No production logs, personal chat data, or credentials were used.