Repository navigation
perf(agents): compact primitive fingerprint revisions - #183137
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: blocked before merge. What this changesThis PR replaces mutable history fingerprint Maps with ordered field tuples and extends the existing measurement script. Example: A projected tool result for call-1 shares frozen text content while its message envelope remains mutable.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this maintainer-authored PR open: it makes a focused change within the existing fingerprint owner, and source review found no definite correctness or security defect. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe request observer fingerprints converted conversation messages before model dispatch and retains compact baselines for subsequent history-rewrite diagnostics. flowchart LR
A[Transcript view] --> B[Message projection]
B --> C[Request observer]
C --> D[History fingerprints]
D --> E[Diagnostic baseline]
E --> F[Rewrite diagnostics]
Technical reviewBest possible solution: Retain the focused representation change only if comparative owner measurements satisfy the declared acceptance rule while preserving fingerprint bytes and rewrite diagnostics. Do we have a high-confidence way to reproduce the issue? Source confirms that mutable projected envelopes retain two Maps on main; the proposed performance benefit has not been demonstrated by a completed comparative run. Is this the best way to solve the issue? The tuple representation is a small, coherent change within the existing owner, but its linear field lookup must earn its cost through the declared measurements. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a3f44fb8a9f6. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +6, Other +79. Total +85 across 2 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 24, 2026, 10:19 PM ET / October 25, 2026, 02:19 UTC. |
4b43b17 to
a37e890
Compare
Keep ordered field digests in their existing Map and store primitive revisions in a small object. Preserve own-key semantics and hash reuse for arbitrary extension fields. Five alternating owner samples reduce projected-context retained heap by 7.0% and promotion by 24.5%, with near-neutral CPU on that path. Fully mutable histories trade 9.2% CPU for 12.2% less retained heap.
a37e890 to
d0ed200
Compare
|
@clawsweeper re-review The final head is |
|
🦞👀 Re-review progress:
|
* perf(agents): compact mutable history fingerprint records * perf(agents): reuse fingerprint revision lookup indices * perf(agents): compact primitive fingerprint revisions Keep ordered field digests in their existing Map and store primitive revisions in a small object. Preserve own-key semantics and hash reuse for arbitrary extension fields. Five alternating owner samples reduce projected-context retained heap by 7.0% and promotion by 24.5%, with near-neutral CPU on that path. Fully mutable histories trade 9.2% CPU for 12.2% less retained heap.
What Problem This Solves
Prompt-cache diagnostics retain two revision Maps for mutable message envelopes even when a request projection shares already-frozen content. This changes the primitive-revision Map to a small object, retaining the existing ordered digest Map and weak-key owner. Large primitive text still hashes only when its value changes; nested objects still rehash. Fingerprint bytes, diagnostic ordering, mutation detection, and immutable compaction stay identical. No hydration, provider-request, configuration, or schema changes.
The initial hydration hypothesis was incomplete:
cloneTranscriptViewshares deeply frozen messages unchanged. Tool-result detail removal and custom-message conversion produce mutable wrappers over frozen content later in request preparation. Those wrappers are collectable after replacement; their current-view revision memos are the retained cost addressed here.Measurement
Five alternating base/candidate owner samples per mode on Node 26.12.1, each with 16 sessions × 128 messages and 21 observations per session: 1,680 model calls per side per mode, including 80 cold and 1,600 repeated observations. Synthetic fixtures use
cloneTranscriptView→ real tool-result projection where selected →convertToLlm→ request observer →beginPromptCacheObservation. Every comparison matched fixture and fingerprint/diagnostic digests. Force GC before/after retained-heap observations. Current views are replaced, not accumulated.Runs hold one shared quiet-slot lock, use interleaved CPUs with alternating placement/order, and use the shared production guard. These are sequential owner comparisons, not concurrent whole-Gateway A/B runs. CPU/GC runs are untraced; collected-object allocation sampling (512-byte interval) and main-isolate promotion tracing are separate passes. Benchmark usage is documented in the script header.
Base source archive:
80ee015d2a4c4748b4f4ecb14d7063617390c459, with the later default-preserving hydration option synchronized on both sides. The fingerprint baseline blob and all measured request owners are unchanged in final rebase target68b73bf9cabdfcf4f3e355df78585c9a141415d0.For projected fresh views, retained heap normalized by all measured model calls is 7,145.62 → 6,647.60 bytes/call (−6.97%). This is amortized retained occupancy after forced GC, not allocated bytes or memory that accumulates on every call. The per-session figure above avoids dependence on the number of repeated rounds.
Acceptance: projected retained heap improves consistently by about 7%, with near-neutral CPU; promotion falls 24.5%. Append CPU and allocation also improve. The fully mutable clone control trades +0.150 ms (+9.2%) repeated CPU for −12.2% retained heap; all five CPU deltas are positive, so this is an explicit tradeoff, not claimed as a speedup. The CPU mean remains below the predeclared adverse threshold, with paired CPU deltas of +10.3%, +7.6%, +8.0%, +12.3%, and +7.8% (three of five below 10%). No GC/promotion/max-pause rejection signal requires an A/A control campaign.
GC and lifetime evidence
All observed timed untraced collections were minor; zero major collections were observed, so major-GC tails are unmeasured. Collection counts below 200 per side per run do not support p95/p99 gates. The table reports every pair's count and both maximum single pauses instead. Maxima are well below the 50 ms safeguard; the only GC increase is +0.000123 ms/observation in retained-view mode, below the 1 ms/op materiality threshold.
Each projected request contains 64 deeply frozen messages and 64 mutable envelopes with frozen content; append contains 128 mutable envelopes with frozen content; the clone control contains 32 mutable envelopes with frozen content and 96 fully mutable messages. No owned envelope roots occur in these fixtures. All modes use 2,048 resident messages. In fresh projected mode, 1,025 initial envelopes remain after replacement (1,024 intentionally retained frozen originals plus one fixture reference), and 1,024 current envelopes remain after releasing model contexts (the frozen originals). Append and fully mutable modes retain one initial fixture reference and zero current envelopes after release. The weak memo owner does not extend envelope lifetime; these are source/lifetime observations, not a production leak claim.
Proof and tradeoffs
prompt-cache-observability.history.test.ts(48),prompt-cache-observability.test.ts(30),prompt-cache-request-observer.test.tsandprovider-prompt-state.test.ts(41 combined), andagent-tools.prefix-stability.test.ts(11). Existing tests remain unchanged; three added special-key cases cover__proto__,constructor, andtoString, including one-hash reuse, undefined/null, nested transitions, and deletion.git diff --checkpassed. No full local suite/build/typecheck or Testbox lease. Final headd0ed20097db483374074b5e989f42c8b65b0d774passed the aggregate CI gate: 59 successful checks, 54 skipped, one neutral CodeQL result, no failures or reruns.undefined,__proto__remains a writable/deletable data key, and immutable records still allocate no revision object. No new cache, alternate fast path, or compatibility shim.After deployment, compare matched-phase fingerprint-family allocation and retained diagnostic heap per model call/context; primitive Map backing stores should decrease while primitive hash counts and rewrite diagnostics stay stable. Watch observation CPU for unusually mutable histories. Owner-level synthetic measurements do not establish a whole-Gateway CPU or latency improvement, and diverse extension-key shapes can reduce object-shape sharing. Production profiling remains with the coordinating maintainer.
Ready for the lead to verify and merge; this lane does not merge.