Repository navigation
fix(gateway): reduce memory growth during session lookups - #140499
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 16, 2026, 2:38 AM ET / 06:38 UTC (Revision 13). ClawSweeper reviewWhat this changesGateway session lookups use lightweight session metadata by default, while usage reports and the published plugin transcript helper retain complete saved prompt data. Merge readiness✅ Ready for maintainer review This remains a useful, focused performance fix: current main and v2026.9.4 retain the expensive default, and the related PRs address complementary paths. No introduced correctness defect was found, and the recorded Gateway measurements provide sufficient behavior proof. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway combines session records from agent databases to resolve run identifiers and serve session information. Its projection choice controls whether those reads also decode saved prompts. flowchart TD
A[Agent session databases] --> B[Combined Gateway reader]
C[Lookup or report request] --> B
B --> D{Prompt data needed?}
D -->|No| E[Session metadata]
D -->|Yes| F[Complete session entries]
E --> G[Run and worker lookup]
F --> H[Usage reports and plugin results]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +8, Tests +270. Total +278 across 7 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep projection selection with the combined reader and preserve explicit full reads wherever saved prompt data is part of the consumer contract. Do we have a high-confidence way to reproduce the issue? Yes: an uncached run lookup reaches the full combined-store reader on current main and decodes unrelated saved prompts. Source inspection and the recorded Gateway comparison establish the path; this review did not execute it. Is this the best way to solve the issue? Yes: the patch selects an existing lightweight projection at its owner and preserves full-entry consumers without adding a competing cache, API, or migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6e2b9ea34516. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
7309ac3 to
0569aa4
Compare
|
Thanks for taking this over, and for the test covering the plugin-SDK view — that was the gap I'd left. Red CI looks unrelated to the change: two 120s timeouts in extension tests this branch doesn't touch ( I don't have re-run rights here. Happy to close/reopen to re-trigger, or push an empty commit — whichever you prefer. Anything you need from me? |
…tore-list-projection
…tore-list-projection # Conflicts: # src/gateway/sessions-resolve-projection.test.ts
|
Status update, plus a request for guidance on next steps. @obviyus picked this up on 2026-09-09 — merged main in, rewrote the body with his own Gateway measurements, and added Where it stands:
Separately, #149118 looks complementary to this rather than overlapping — no shared files. Its Could someone advise what's needed from me to get this merged, or re-run CI against current main? I'm glad to rebase, narrow the scope, or split it if that helps. |
|
landpr-approve-admin-merge |
|
landpr-approve-admin-merge |
|
landpr-approve-admin-merge |
|
Thanks @DakshK-02! Proof: Real Gateway requests against 200 stored sessions preserved lookup results, usage reports, and plugin prompt fields. Repeated 48-request samples reduced prompt-bearing parses from 4,804 to four; a shared health refresh contributed ten additional parses when it overlapped a sample.
|
|
Thanks @obviyus !!!! |
…aw#140499) ## What Problem This Solves Run lookups decoded saved prompts from every stored session, causing unnecessary memory growth. ## Why This Change Was Made The combined Gateway reader now defaults to its existing metadata projection. Usage reports and the published plugin transcript helper explicitly retain full entries. The combined reader owns the projection default; existing storage writers and cache ownership are unchanged. ## User Impact Large-store lookups use less memory without changing session selection or saved prompts. ## Evidence A real isolated Gateway held 200 synthetic sessions across two agents. Three matched 48-request samples reduced prompt-bearing parses from 4,814 to 14 in the first sample and from 4,804 to four in each later sample. A shared background health refresh adds ten parses when it overlaps a sample. The largest resident-memory increase sampled after completed requests fell from 357–457 MB to 4.6–21.6 MB. These samples include the Gateway and client in one process and do not measure continuous memory peaks or exact heap allocation. Metadata scans and intentional full-entry reads remain. `node scripts/run-vitest.mjs run src/gateway/sessions-resolve-projection.test.ts` passes after merging current main. Its registered `artifacts.list` regression fails on main because unrelated prompts are decoded. ## Compatibility No schema, configuration, protocol, or public signature changes. Both original contributor commits remain. Separate full-store and startup/selected-entry reads are unchanged. ## Consumers Usage context reports and plugin transcript entries retain both saved prompt fields. ## Invalidation Existing cache invalidation, ownership, and incognito rules remain intact. ## Tests Known, missing, freshest, ambiguous, agent-scoped and incognito controls; usage and plugin preservation; 98 focused owner and sibling tests passed. Production growth is eight lines: combined reader +2, usage +1, plugin wrapper +5. Each retains the projection contract above. Growth accepted under the owner's standing acceptance (2026-09-15). Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Run lookups decoded saved prompts from every stored session, causing unnecessary memory growth.
Why This Change Was Made
The combined Gateway reader now defaults to its existing metadata projection. Usage reports and the published plugin transcript helper explicitly retain full entries. The combined reader owns the projection default; existing storage writers and cache ownership are unchanged.
User Impact
Large-store lookups use less memory without changing session selection or saved prompts.
Evidence
A real isolated Gateway held 200 synthetic sessions across two agents. Three matched 48-request samples reduced prompt-bearing parses from 4,814 to 14 in the first sample and from 4,804 to four in each later sample. A shared background health refresh adds ten parses when it overlaps a sample. The largest resident-memory increase sampled after completed requests fell from 357–457 MB to 4.6–21.6 MB. These samples include the Gateway and client in one process and do not measure continuous memory peaks or exact heap allocation. Metadata scans and intentional full-entry reads remain.
node scripts/run-vitest.mjs run src/gateway/sessions-resolve-projection.test.tspasses after merging current main. Its registeredartifacts.listregression fails on main because unrelated prompts are decoded.Compatibility
No schema, configuration, protocol, or public signature changes. Both original contributor commits remain. Separate full-store and startup/selected-entry reads are unchanged.
Consumers
Usage context reports and plugin transcript entries retain both saved prompt fields.
Invalidation
Existing cache invalidation, ownership, and incognito rules remain intact.
Tests
Known, missing, freshest, ambiguous, agent-scoped and incognito controls; usage and plugin preservation; 98 focused owner and sibling tests passed.
Production growth is eight lines: combined reader +2, usage +1, plugin wrapper +5. Each retains the projection contract above. Growth accepted under the owner's standing acceptance (2026-09-15).