Repository navigation
perf(ai): avoid duplicate normalization of matching Responses inputs - #137617
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 3, 2026, 11:50 PM ET / September 4, 2026, 03:50 UTC. ClawSweeper reviewWhat this changesThe PR avoids stable-normalizing the right-hand OpenAI Responses input when its JSON serialization already exactly matches the left-hand input. Merge readiness⛔ Blocked before merge - 1 item remains The patch is correct: exact serialized equality is a strict fast path, while reordered JSON still reaches the existing stable-key comparison. Current main retains the older comparator, so this PR remains necessary and should stay open for normal maintainer handling. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw’s AI transport compares a new Responses request with the prior request and response history to decide whether it can continue a remote response. That shared decision feeds both HTTP and WebSocket request preparation. flowchart LR
A[Prior Responses request] --> C[Continuation comparison]
B[Current Responses request] --> C
C --> D{Inputs equivalent?}
D -->|yes| E[Reuse prior response]
D -->|no| F[Start changed request]
E --> G[HTTP or WebSocket transport]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource 0. Total 0 across 1 file. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Retain this single fast path in the shared continuation comparator so identical wire inputs avoid redundant normalization while all non-identical serializations keep the established fallback. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a performance optimization rather than a report of a user-facing failure; source inspection establishes the preserved continuation decision path. Is this the best way to solve the issue? Yes. Raw JSON equality can only bypass work for inputs the prior normalizing comparison would also consider equal, and the existing stable-key path remains for reordered serialized objects. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8b7a1bba2bd2. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
27ea07c to
c3f5e6d
Compare
c3f5e6d to
dd76c28
Compare
|
Maintainer-directed landing exception for Latest ClawSweeper review: The automated persistent-data classification does not apply: this equality fast path operates on a process-local continuation Map and changes no persisted representation, schema, migration or wire contract. The existing public compatibility disposition is retained. Exact serialized equality uses the existing shared comparator; non-identical serialization still uses stable-key comparison. Retained owner/transport proof and managed P0–P2 review cover the change. Production is net 0; tests unchanged. Current-main source composition is accepted through Landing uses the documented protected, exact-head squash operation. Native preparation is not claimed to have passed under this exception. GitHub remains responsible for enforcing repository rules. |
…penclaw#137617) perf: skip redundant Responses input normalization Maintainer-directed CI exception: ignore the confirmed npm advisory request timeout for this landing. Other selected exact-head checks passed in the retained snapshot. The audit and aggregate remain failed; no security clearance or successful native preparation is claimed.
What Problem This Solves
Repeated Responses turns normalized both sides of each replay comparison even when their serialized JSON was already identical. Long matching histories repeatedly allocated the same parsed and sorted representation.
Why This Change Was Made
Compare the serialized forms before normalizing the right operand. The left operand still completes normalization first, preserving serialization failures and getter/toJSON ordering. Different JSON retains the existing stable-key comparison, including reordered objects and JSON wire semantics.
User Impact
HTTP and WebSocket continuation decisions and outgoing requests remain unchanged. The matching long-history workload reduced sampled comparison allocations by 49.89% and paired median comparison time by 33.43%. Reordered and changed-history cases showed small median slowdowns; all results were retained. These are owner-level measurements, not a Gateway RSS claim.
Evidence
A 35-case before/after corpus matched complete results and error/ordering observations. Five existing transport suites passed 86 tests, including real SDK HTTP/WebSocket loopback coverage and tool changes. The complete changed gate passed, and independent Codex review found no actionable P0–P2 findings.
Production +5/−5 (net 0); tests unchanged. The fixed eight-leg timing series retains its reordered-input outlier and overlapping host load.
The fixed four-change composite passed 10 admitted real OpenAI Gateway turns across Code Mode and Tool Search, including web fetches, synthetic file reads, Unicode output, session/history reads, and clean shutdown. Independent offline audit accepted the full saved evidence. One baseline/composite pair showed post-idle RSS −2.34 MiB for Code Mode and +5.16 MiB for Tool Search; it does not establish a consistent Gateway RSS reduction or attribute changes to this PR.
Review follow-through
Review disposition: this changes only the equality comparator in the process-local continuation Map. It changes no persisted data, schema, migration, request representation or protocol, so the automated persistent-data-model classification does not apply. Complete JSON/ordering parity and HTTP/WebSocket owner coverage are recorded above.
Combined live verification
The final isolated twenty-change composite passed ten admitted real OpenAI Gateway turns across Code Mode and Tool Search, with web fetches, exact synthetic file reads, bounded Unicode output, four persisted-history checks and clean unforced shutdown. Independent audit accepted all fourteen stages, fifty memory observations and sixty saved command captures. One fixed run per revision showed post-idle RSS of 492.375 MiB (Code Mode) and 478.297 MiB (Tool Search), versus baseline 497.453125 and 481.53125 MiB. Main-isolate heap differed by only −107,976 and −264,016 bytes. Against the earlier twelve-change composite, Code Mode RSS rose 7.4375 MiB; sampled allocation results were mixed. These observations describe the composition and do not establish per-PR or consistent overall memory savings. The individual owner proofs above carry the effect claim. Exact-head required CI remains a landing gate.