Repository navigation
improve: reduce memory use for raw-trace diagnostics - #150754
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. Reviewed September 18, 2026, 3:04 AM ET / 07:04 UTC (Revision 7). ClawSweeper reviewWhat this changesThe PR computes raw-trace usage incrementally instead of retaining transcript message arrays and closes test databases before deleting temporary directories. Merge readiness✅ Ready for maintainer review Keep open: the optimization remains necessary on current main, and review found no actionable introduced defect. The supplied component measurements support the bounded performance claim. Priority: P2 Review scores
Verification
How this fits togetherRaw-trace diagnostics read session transcripts to summarize token usage and cost after an authorized agent run. These readers consume SQLite events or JSONL artifacts and supply the diagnostic reply. flowchart TD
A[Authorized raw-trace completion] --> B[Scoped transcript reader]
B --> C[SQLite snapshot visitor]
B --> D[JSONL line reader]
C --> E[Incremental usage summary]
D --> E
E --> F[Diagnostic reply]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +17, Tests -7. Total +10 across 4 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Use the existing transcript iterators with one shared incremental aggregator while preserving diagnostic output and bounded recent reads. Do we have a high-confidence way to reproduce the issue? Yes for the retention mechanism: current-main full-history readers visibly retain message arrays until aggregation finishes. This read-only review did not independently execute a memory benchmark. Is this the best way to solve the issue? Yes. Reusing the existing ordered iterators and aggregation rules removes the unnecessary retention without introducing a competing summarizer or changing stored data. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b4894512c20c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
22c7b99 to
2c6799a
Compare
2c6799a to
0061248
Compare
|
Merged via squash.
|
Closes #150724
What Problem This Solves
Raw-trace diagnostics retain all transcript message bodies while computing a small usage summary, adding memory pressure for long conversations.
User Impact
Authorized raw-trace completion no longer buffers the full transcript for usage aggregation. Reported usage and the bounded recent-usage reader keep their existing behavior. This does not establish a default-request or whole-Gateway speedup.
Why This Change Was Made
Feed the shared aggregation logic incrementally from the existing SQLite snapshot visitor and JSONL line reader. Keep forward ordering, source-specific usage rules, normalization, and cleanup. Each cold-storage retry starts a fresh accumulator. SQLite aggregation now runs inside the existing synchronous read snapshot; there are no schema, configuration, or persistence changes.
The reply tests also close their SQLite state through the existing cleanup helper before removing temporary directories. This repairs a Windows cleanup failure reproduced on the original production code and removes duplicate inline deletion paths.
Evidence
Windows / Node 26.8.2, base
4345deb5dbe89d2e56589f5bbed618a92da36ca0: 16 fresh-process reads in baseline/candidate/candidate/baseline order, covering SQLite and JSONL at 32 and 8,192 messages with 8 KiB of content each. All complete output objects matched, and source, dependency, fixture, and cleanup checks passed.Long SQLite reads had 8.3% and 12.4% lower process peak RSS in the two fixed pairs, with mixed wall time. Long JSONL reads were 8.3% and 14.9% faster, while peak RSS was essentially unchanged. Short reads and CPU results were mixed; both pairs are retained below.
All fixed-pair changes; positive values are regressions
Exactly two comparisons per case on one shared Windows host. Call timing excludes initial imports; process peak RSS includes them, and pre-read memory varies substantially. These are component observations, not GC-normalized retained-heap, cold-cache, or end-to-end guarantees. The initial misplaced JSONL fixture and a zero-measurement Windows Python-launcher rejection were corrected and preserved separately; neither is a performance result.
Original patch validation: 227 selected cases passed (108 Gateway reader cases, all 112 reply cases, three recent-usage cases, and four queued-trace cases). The repository changed-file checks passed, including core and test types, formatting, lint, unused exports, and import cycles. Fresh review of the final four-file patch and the exact-head ClawSweeper review found no actionable issues.
The branch is now at
0061248aeec63571418fe498bc4ab27796bee1dc, with an identical four-file patch after incorporating three landed repairs for inherited CI failures: #150655 (labeler and Doctor test expectations), #151372 (compact-planner worker assertion), and #151417 (duplicate UI test declaration). The prior CI run 35312679421 finished with 134 successful jobs, 17 skipped jobs, and three static-check failures from that same UI declaration plus the aggregate gate. All runtime jobs passed; specific test-case coverage is not inferred from those job results. Exact-head CI run 35315107780 passed with 138 successful jobs and 17 skipped jobs. The current ClawSweeper workflow also completed successfully; its durable published verdict remains attached to the patch-identical prior head, and the native workflow applies its review freshness policy.The refreshed Windows changed-file checks passed the preceding guards, formatting and production typechecking, then failed test typechecking on the same inherited UI declaration. That repair is now included. The additional selected Windows run passed 226 cases and timed out one queued-trace case. Its direct children completed and the scoped process census was empty. The affected fixture supplies an unwritten synthetic transcript, so its artifact lookup normally returns before the changed usage accumulator; the run also showed substantial slowdown in other cases and build preparation. The failure remains recorded. The four-case diagnostic with temporary phase logging passed with the original assertions, order and timeouts. Accounting, including the raw-trace lookup, took 5–28 ms; follow-up delivery took 92.678, 15.020, 12.276 and 9.750 seconds. This locates the reproduced delay after the changed reader, but does not retroactively trace the original timeout. The diagnostic is separate from uninstrumented proof, and the exact original test bytes were restored after its children joined and scoped process checks cleared. All bound reader/caller/helper inputs and dependency metadata remain unchanged across these rebases.
The initial Windows reply run failed while deleting open SQLite files; a two-case control on the original production code reproduced the failure. The first cleanup fix left seven inline-deletion failures; the final patch removes those duplicate paths and passes the full reply file. The first changed-check invocation stopped because the isolated environment unnecessarily selected unavailable Corepack; the successful run used the normal local route with installed pnpm 12.4.0. These failures remain separate from the performance measurements.