Repository navigation
perf: reduce large-session compaction and indexing allocations - #174433
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR avoids unused compaction signatures and removes duplicated plain-text fields from memory preparation worker results. Example: Prepare a 64 KiB text source for memory indexing.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it makes useful, narrow allocation reductions that current main does not provide, with no concrete correctness or security finding. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCompaction prepares transcript messages for summarization; Memory Core prepares text chunks in a worker, then passes them to embedding and publication owners. flowchart TD
A[Session transcript] --> B[Compaction retry pruning]
B --> C[Summarization]
A --> D[Memory preparation worker]
D --> E[Embedding consumers]
E --> F[Index publication]
Technical reviewBest possible solution: Retain these optimizations in the existing compaction and preparation owners while preserving transcript, embedding, and publication contracts. Do we have a high-confidence way to reproduce the issue? Current-main source demonstrably constructs discarded retry signatures and returns duplicate plain-text representations; the PR also reports Gateway allocation attribution, but no target code was executed during this review. Is this the best way to solve the issue? The changes address the allocation producers directly, reuse existing consumer fallbacks, and preserve retry boundaries without introducing another owner or pending state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ca53a1553462. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +21. Total +32 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 16, 2026, 1:05 PM ET / 17:05 UTC. |
…158510 * commit 'cff3c307ba6d0ce273abcdaf5cade848d9746d30': feat(decisions): preserve native catalog capabilities and accounting (#157492) fix(ui): avoid reactive read warnings in picker scrolling (#174436) refactor(test): remove unused Nextcloud fixture signing (#174470) refactor(browser): share managed tab eviction fixtures (#174474) fix(update): preserve Windows inspection path identities (#174471) perf: reduce large-session compaction and indexing allocations (#174433) perf(codex): reduce allocations while reading app-server output (#174468) fix(gateway): skip startup publication checks without a target (#174453) refactor: deslop agent harnesses, channel plugins and packages (wave-6 bundle A) (#173531) perf(state): reduce shared SQLite worker heap retention (#174420) refactor: remove routine channel callsite diagnostics (#174402)
…esafe-decision-native * commit 'cff3c307ba6d0ce273abcdaf5cade848d9746d30': feat(decisions): preserve native catalog capabilities and accounting (#157492) fix(ui): avoid reactive read warnings in picker scrolling (#174436) refactor(test): remove unused Nextcloud fixture signing (#174470) refactor(browser): share managed tab eviction fixtures (#174474) fix(update): preserve Windows inspection path identities (#174471) perf: reduce large-session compaction and indexing allocations (#174433) perf(codex): reduce allocations while reading app-server output (#174468) fix(gateway): skip startup publication checks without a target (#174453) refactor: deslop agent harnesses, channel plugins and packages (wave-6 bundle A) (#173531) perf(state): reduce shared SQLite worker heap retention (#174420) refactor: remove routine channel callsite diagnostics (#174402) # Conflicts: # src/agents/decision-inference.integration.test.ts
…/decision-tool-v2-proof-20261016 * commit 'cff3c307ba6d0ce273abcdaf5cade848d9746d30': feat(decisions): preserve native catalog capabilities and accounting (#157492) fix(ui): avoid reactive read warnings in picker scrolling (#174436) refactor(test): remove unused Nextcloud fixture signing (#174470) refactor(browser): share managed tab eviction fixtures (#174474) fix(update): preserve Windows inspection path identities (#174471) perf: reduce large-session compaction and indexing allocations (#174433) perf(codex): reduce allocations while reading app-server output (#174468) fix(gateway): skip startup publication checks without a target (#174453) refactor: deslop agent harnesses, channel plugins and packages (wave-6 bundle A) (#173531) perf(state): reduce shared SQLite worker heap retention (#174420) refactor: remove routine channel callsite diagnostics (#174402) # Conflicts: # docs/plugins/sdk-overview/capabilities.md
…law#174433) Avoid transferring duplicate plain-text embedding input from the memory preparation worker after provider splitting. Skip compaction retry signatures when the empty retry map will be reset before any comparison. Preserve transcript contents, duplicate retry handling, embedding inputs, and publication behavior. Add a serialization-budget regression for plain and provider-split text; existing compaction and native worker/publication tests pass. No SQL, schema, public SDK, or lifecycle change.
What Problem This Solves
Large text sessions allocate unnecessary copies on the Gateway main thread during compaction and memory indexing.
User Impact
Reduces transient compaction allocations and text transferred from the memory preparation worker. Transcript contents, duplicate-retry handling, embedding inputs, and stored results are preserved. No configuration, schema, or public SDK change.
Why This Change Was Made
Text-only memory preparation returned both
chunk.textandchunk.embeddingInput.text; structured cloning copies both strings. Drop the redundant input after provider-size splitting, using the existing plain-text consumer contract. Multimodal preparation is separate and unchanged.Compaction normalized and serialized each user message even when the next assistant immediately discarded that retry signature. Skip that work only when the retry map is empty and the next entry is an assistant or the transcript ends. Existing duplicate, sender, media, and timestamp rules remain unchanged. Singleton users separated from a reply by system/tool-result entries still normalize; the narrower fast path avoids new pending state.
Evidence
A 60,000-message synthetic session was seeded offline in a separate process before Gateway startup (142,957,994 serialized bytes). The Gateway then ran real compaction and memory indexing. This establishes a product allocation path, not seeding memory retained by the Gateway.
Allocation sampling through compaction attributes approximately 908 MiB of cumulative allocations to duplicate-user normalization/signatures. These are allocated bytes, not retained heap. The diagnostic run completed compaction and sent all 120,000 embedding inputs in 24,000 requests, but exceeded the initial shutdown deadline; it is attribution evidence, not a passing lifecycle or latency result. A main-isolate heap snapshot was captured during indexing drain. The snapshot contains 120,000 prepared chunks and 120,000 redundant plain-text embedding inputs: each text-field family references about 157 MiB of strings. The exported source remains reachable through embedding candidates (about 119 MiB). These are snapshot reference totals, not additive dominator sizes.
Four counter-only controls passed compaction, both shutdowns, restart, and continuation, each producing 120,000 embedding inputs/chunks in 24,000 embedding requests and 162,740,680 indexed text characters. Their compaction summary hash and token counts match. One baseline control made one fewer model response request; total provider request counts are not identical. Initial MAIN peaks were 1,473.34 → 1,943.67 MiB in the first pair and 2,313.01 → 1,610.58 MiB in the extra ambiguity pair. Restart MAIN peaks were 487.61 → 383.70 MiB and 376.70 → 436.67 MiB. The direction reverses: no whole-process peak reduction or retained-memory reduction is claimed. All four runs reported the indexing-drain shutdown warning. Two-second samples can miss synchronous peaks, and these are not matched post-collection retention checkpoints. Whole-source preparation and publication still scale with transcript size; this patch removes avoidable copies and signature allocations without changing publication ownership.
The two changed functions issue zero database statements/requests on both sides. No SQL saving is claimed. All six alternating shared-harness v3 runs passed (M,C,M,C,M,C), with 30 warmed turns per side. Raw and turn-caused warmed medians are unchanged. Whole-workload medians increased by 11 statements and two requests; first-turn causal medians increased by seven statements and one request. These totals do not establish all-phase SQL non-regression. The matched compaction-helper probe preserves all 60,000 message identities/order and reduces sampled allocations by about 99.4%. Measurements compare base
0dc31f5f643with candidate9d28e1275b0using the unchanged shared v3 harness and Node 26.12.0 / SQLite 3.54.0. The compile cache is disabled. The loaded host does not support latency claims.The raw warmed MAIN outliers are background
state_leases.expires_atreads from the unchanged lease owner; none is turn-caused. The huge-session controls use a separate bounded-observer harness copy: its protocol and hashes match across those four controls, while the six standard runs all share the unchanged v3 protocol and hashes. Results from these two protocols are not pooled.Raw phase counts below are median [min–max] across three runs. Each cell is statements / requests / MAIN statements; phase placement includes background work.
All six runs report successful compaction. Compaction medians are unchanged; the first baseline window contains 61 statements/22 requests, while the other five contain 95–96 statements/30 requests. In that first baseline, memory-indexing writes land in the following settle window: combined compaction + settle is 113 statements/30 requests versus 97/30 in the first candidate. Eight requests visibly shift between windows, but the entire 34-statement compaction difference is not a pure shift. Across all three runs, combined medians are 97/30 → 96/30. No decrease or increase in SQL is attributed to the allocation-only changes.
Compaction owner: 10 tests pass. Memory preparation serialization and native worker/publication coverage: 12 tests pass. Changed-file format/lint and diff checks pass; isolated Codex review is scoped-clean (one round). Exact-head CI passed, including types, lint, source contracts, Madge, PostgreSQL conformance and T1/dialect ratchets; the explicit Knip scan reports only the same three production and four full-tree findings independently reproduced on the exact main baseline, with identical source/config/runner/lockfile bytes; scripts report zero. The inherited findings are recorded with the main repair owner. Update-driver proof is not applicable.
No authority, freshness, or admission checks are removed. The omitted compaction signature is internal bookkeeping with no consumer before reset/end; duplicate user retries before a reply are still compared. The worker payload change removes a redundant representation, not validation.
Production: +12 net lines. Tests: +20 net lines. Total: +35/−3 across three files.