Repository navigation
perf(agents): compact retained prompt-cache diagnostics - #178676
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. |
c1a823c to
c7093c6
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR compacts retained prompt-history fingerprints while preserving append-only checks and field-level diagnostics. Example: A Gateway keeps diagnostic baselines for 100 idle sessions with 655 entries each.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored optimization addresses diagnostic memory still retained on main, and inspection found no actionable code defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherBefore model dispatch, the request observer fingerprints conversation history through the existing worker and compares it with bounded session baselines, producing cache-change diagnostics without changing provider messages. flowchart LR
A[Conversation messages] --> B[Request observer]
B --> C[History preparation worker]
C --> D[Compact fingerprints]
D --> E[Session diagnostic baseline]
E --> F[Rewrite and cache diagnostics]
Technical reviewBest possible solution: Compact the existing diagnostic baseline while preserving exact rewrite detection, bounded field details, and session cleanup. Do we have a high-confidence way to reproduce the issue? Main visibly retains per-message diagnostic Maps after runtime disposal, and the linked Gateway attribution reports 118.50 MiB; this review executed no target code and independently verified no memory magnitude. Is this the best way to solve the issue? The change uses the existing fingerprint, worker, tracker, and cleanup owners, removes the superseded equality helper, and preserves diagnostic ordering and redaction without introducing another persistent cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1c4b27072712. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +25, Tests 0, Docs +7, Other +39. Total +71 across 7 files. Added test files: 0. View PR surface stats
Review metrics
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 20, 2026, 3:13 PM ET / 19:13 UTC. |
c7093c6 to
d59a62c
Compare
d59a62c to
0591c41
Compare
0591c41 to
8a5f7bb
Compare
8a5f7bb to
c6b4d2f
Compare
) * perf(agents): compact retained prompt-history diagnostics * perf(agents): share compact diagnostic field hashes * perf(agents): pack diagnostic fingerprints into flat strings * test(perf): separate census from retention samples * fix(claws): avoid retaining the first caller in an error stack * perf(agents): compact provider-request diagnostic fingerprints
Owner acceptance (verbatim)
Result
The two concurrent, swapped-core Gateway pairs reduce retained diagnostic fingerprints by 71.61% and 71.58%, meeting the 70% memory threshold. The owner accepts the measured initial-turn promotion increase against the retained-memory reduction. The complete per-pair measurements and limits remain below.
What Problem This Solves
Prompt-cache diagnostics retain per-message Maps, arrays, and digest objects after runtime sessions are released. The initial 100-session probe attributed 118.50 MiB to this owner after six minutes idle. The current concurrent baselines retain about 127.8 MiB.
User Impact
Idle sessions retain about 90 MiB less diagnostic heap across this 100-session workload, while preserving history-change diagnostics. The owner accepts the measured initial-turn promotion increase; no user action is required.
Why This Change Was Made
Store full SHA-256 history digests in flat Latin-1 strings with a shared field-name layout. Materialize diagnostic Maps only on divergence. Reopened equal messages reuse the previous baseline; the temporary layout index is discarded after each observation. Provider-request prefixes also pack their full ordered message digests into one string, preserving the existing first-32-message field diagnostic window and 512-message digest bound. Field hashes and public wire diagnostics remain hexadecimal. No provider payload, configuration, schema, retention limit, or cleanup policy changes.
The measured Gateway flow also exposed a separate import-time lifetime: the module-level uninitialized-state Error in
src/claws/tool-policy-runtime.tscaptured the importing session through lazy stack frames. Construct that Error only in the existing failure branch. The message, cause, consent decision, and fail-closed behavior are unchanged. Both measured sides include this prerequisite, isolating compact fingerprint storage from the independent retention repair.Runtime production delta: +41 lines. Full hashes, ordered field diagnostics, and lossless compact encoding/decoding account for the growth; the retained object graphs are replaced rather than supplemented by another cache. Related: #178536, #178602.
Evidence
Both concurrent Gateway pairs passed all transcript checks and session-disposal censuses. The tables below retain the measured memory, latency, promotion, and GC tradeoffs.
Measurement
Baseline:
4a4d1e330fdfe92de7fe464d25a6bdf8fd033849. Candidate:c6b4d2f8e2c1a3412b3eec6a5d1d472e161872a2. Both sides receive identical measurement instrumentation and the Error-lifetime prerequisite. Source-performance builds were generated sequentially, with 227 source hashes per tree verified before and after builds. Existing identical dependency installations were reused on both sides (including typebox 1.3.36 and zod 4.6.6).The committed synthetic Gateway workload uses 100 sessions in cohorts of ten, 655 seeded entries per session, 128 KiB prompts, and six minutes idle before reopening. The roster has 5,000 sessions and 6,000 retained runs. Each pair runs simultaneously under the exclusive measurement lock: baseline on cores 96–111 and candidate on 112–127, then swapped. Separate state directories and loopback ports; outside load recorded. Each side supplies 100 reopen and first-text samples.
After timed reopening, a second six-minute disposal interval precedes fingerprint attribution. Every run passed all 100 append-only transcript checks and had zero reachable SessionManager, AgentSession, and Agent instances. Separate plain forced-GC samples before and after clearing diagnostic observations measure retained fingerprints; this clear never precedes timed reopening. External-memory and array-buffer attribution deltas were zero. Natural main-isolate promotion excludes worker isolates and forced census collections.
Workload command, with separately generated matching synthetic state:
Pair 1: -71.61% retained fingerprint change (-91.48 MiB).
Pair 2: -71.58% retained fingerprint change (-91.50 MiB).
Initial-turn GC, outside the reopen window:
The promotion increase is not explained by the current aggregate operation counters. A read-only source audit found no added timer, event, or persistence call in compact diagnostics; the generic patch counter includes no-op attempts and the transcript-worker counter combines request kinds. Those counts are diagnostic clues, not grounds to normalize away or waive the promotion gate.
Focused proof and limits
c6b4d2f8e2c1a3412b3eec6a5d1d472e161872a2, including the aggregate CI gate. The PR context check initially rejected nonstandard body headings; restoring the repository template headings fixed that body-only failure. No manual CI rerun, broad local suite, extra local install, or additional typecheck lane was used for this follow-up.