Repository navigation
Conversation
Avoid deep projected-JSON comparison of unchanged compacted prefixes by consuming the immutable identity already published by the compaction owner. Preserve persisted hashes and mutable hook semantics. Synthetic reasoning/tool histories retain identical continuation decisions while reducing per-turn CPU and allocation.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please review final head d45ad4d. Focus on the existing compaction publication identity preserving continuation decisions, mutable/toJSON/sparse fallback behavior, and the synthetic benchmark's byte-identical persisted contextUsage proof. Local tests, check:changed, and Codex P2 autoreview are complete. |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis 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 reuses compaction-published immutable identities to avoid repeatedly comparing unchanged Responses history. Example: An unchanged compacted conversation receives eight appended turns at a 2,000-entry scale.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a useful, focused performance improvement with no concrete correctness or security findings; exact-head CI is still incomplete. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherResponses conversion publishes immutable request items; continuation validation compares prior and current histories and emits either a delta referencing the previous response or the full request. flowchart TD
A[Conversation history] --> B[Conversion and compaction]
B --> C[Immutable input identities]
C --> D[Continuation validation]
D --> E[Delta or full request]
B --> F[Context usage fingerprint]
Technical reviewBest possible solution: Retain the existing compaction identity owner and consume its immutable publication facts while preserving the complete mutable-history fallback. Do we have a high-confidence way to reproduce the issue? Source confirms that reparsed compaction items miss the prior reference-only shortcut; the supplied A/A/B measurements exercise that owner path, but no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete approach: reuse the producer's existing immutable identities, retain historical comparison when identity cannot establish equality, and leave persisted hashing unchanged. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9aed3620c57f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +19, Tests +41, Other +313. Total +373 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
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 November 17, 2026, 12:30 PM ET / 17:30 UTC. |
|
Merged via squash.
|
Avoid deep projected-JSON comparison of unchanged compacted prefixes by consuming the immutable identity already published by the compaction owner. Preserve persisted hashes and mutable hook semantics. Synthetic reasoning/tool histories retain identical continuation decisions while reducing per-turn CPU and allocation.
What Problem This Solves
Long OpenAI Responses conversations repeatedly deep-compare unchanged history after compaction. A reparsed checkpoint forces the entire prefix through normalization and projected JSON comparison, creating avoidable allocation and CPU work on every turn.
User Impact
Responses turns after compaction require less local CPU and allocation. Request bytes, continuation decisions, persisted context hashes, and mutable payload-hook behavior remain unchanged. No configuration or migration is required.
Why This Change Was Made
Compaction already publishes immutable per-item identities, which incremental prefix hashing consumes. Continuation comparison now consumes the same owner-provided fact. Ordinary frozen items retain reference comparison; edits, opaque/toJSON values, and sparse arrays retain full validation. The comparison lives in the existing JSON projection module to keep the continuation owner within its file-size limit.
No new cache or fingerprint algorithm. Production delta: +19 lines; focused test delta: +41 lines. The remaining growth implements the immutable identity check and its comparison boundary. This change does not claim to remove full hashing on cold or mutable inputs.
Evidence
A/A/B acceptance was declared in the committed workload before measurement: identical continuation decisions, request deltas and persisted contextUsage/prefixHash; candidate beats both A controls for CPU and allocation on compacted histories, without regressing ordinary history.
Four synthetic histories, eight appended assistant/user turns each, 2,000-entry scale, including reasoning and tool-call/results. Five counterbalanced samples per arm; 640 timed decisions and 96 allocation decisions per sample. V8 sampling includes objects collected by both major and minor GC. Conversion is outside owner timing; these are owner measurements, not Gateway latency or provider cache-hit claims.
| History | Metric per request | A1 | A2 | B |
|---|---|---:|---:|---:|---:|
| Plain | CPU ms, median | 0.17225 | 0.16628 | 0.13627 |
| Plain | Allocation MB, median | 0.00577 | 0.00577 | 0.00651 |
| Checkpoint | CPU ms, median | 2.17330 | 2.14643 | 0.32075 |
| Checkpoint | Allocation MB, median | 2.81234 | 2.80931 | 0.09547 |
| Complete window | CPU ms, median | 1.59184 | 1.57363 | 0.31657 |
| Complete window | Allocation MB, median | 0.78802 | 0.78789 | 0.06439 |
All arms had identical 100% continuation decision hits. Per 32 requests, recursive equality calls fell from 300,384 to 512 for checkpoint histories and from 450,464 to 512 for complete windows. Plain history stayed at 512. Warm historical prefix serialization was already avoided on the baseline; only new response output is encoded by the prefix hasher. Persisted hash parity includes compaction, reasoning and tool history; existing tests cover toJSON evaluation ordering.
The committed workload is
scripts/perf/responses-continuation-equality-measure.ts(run undernode --expose-gc --import ./scripts/tsx.mjs, with adjacent baseline continuation and context-usage modules supplied through--baselineand--baseline-context). The context baseline must import the baseline continuation module. The allocation/work-count guard fails on the original owner and passes with this change. CPU profiling was also collected.pnpm check:changedpassed. Exact-head CI attempt 2 passed; attempt 1 failed before tests because the Git PPA returned HTTP 503, and one failed-only retry succeeded. The strengthened fixture also passed its targeted script typecheck and lint.Five-sample spread and host load
Nearest-rank p95 is the maximum for five samples. Node v26.12.1; observed one-minute load 9.81–12.04
The final workload supplies provider replay provenance for synthetic reasoning and asserts that reasoning survives conversion; its final A/A/B results above supersede the earlier fixture.
Ordinary-history sampled allocation moved from 5.77/5.77 KB to 6.51 KB per request (+0.74 KB, with overlapping five-sample control ranges); work counts stayed identical and CPU improved. No ordinary-history allocation reduction is claimed. Compacted-history B beats both A controls by a wide margin.