Skip to content

perf(ai): avoid duplicate normalization of matching Responses inputs - #137617

Merged
steipete merged 1 commit into
mainfrom
codex/perf7-responses-json-equality
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf7-responses-json-equality

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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.

node scripts/check-changed.mjs -- packages/ai/src/transports/openai-responses-continuation.ts

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.

@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 3, 2026
@steipete
steipete marked this pull request as ready for review September 3, 2026 22:38
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 11:50 PM ET / September 4, 2026, 03:50 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: dd76c28ffd9e1e28aae1c12ea7892175b2564939

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, net-neutral optimization that preserves the established fallback and is covered by existing continuation behavior tests.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor real-behavior-proof gate; its body records transport-level validation, while source review confirms the optimization is confined to the shared comparator.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor real-behavior-proof gate; its body records transport-level validation, while source review confirms the optimization is confined to the shared comparator.
Evidence reviewed 6 items Introduced fast path: The only introduced hunk serializes and stable-normalizes the left input first, then returns true immediately only when the right serialization is byte-identical; otherwise it retains the prior stable-key comparison.
Shared owner and callers: The comparator determines request and history continuation at the owner boundary; the HTTP client and WebSocket transport both invoke that same resolver before dispatch.
Existing behavior coverage: Existing owner tests cover successful continuation, changed history, JSON wire semantics, unsafe-number handling, isolation, expiry, and immutability; retained-compaction replay coverage exercises repeated continuation rounds.
Findings None None.
Security None None.

How this fits together

OpenClaw’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
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source 0. Total 0 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 5 5 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 5 5 0

Review metrics

Metric Value Why it matters
Production versus test delta production net 0 (5 added, 5 removed); tests unchanged The optimization adds no configuration, protocol, persistence, or net production surface; existing owner-boundary tests cover continuation semantics.

Stored data model

Persistent data-model change detected: serialized state: packages/ai/src/transports/openai-responses-continuation.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best 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.

Labels

Label justifications:

  • P3: This is a narrowly scoped performance optimization with no user-visible behavior or configuration change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is outside the external-contributor real-behavior-proof gate; its body records transport-level validation, while source review confirms the optimization is confined to the shared comparator.

Evidence

What I checked:

Likely related people:

  • Markus Hartung: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-03T22:51:00.564Z sha 2fe4cf9 :: blocked before merge. :: none
  • reviewed 2026-09-03T23:19:24.840Z sha 2fe4cf9 :: blocked before merge. :: none
  • reviewed 2026-09-04T02:04:23.465Z sha c3f5e6d :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 3, 2026
@steipete
steipete force-pushed the codex/perf7-responses-json-equality branch 2 times, most recently from 27ea07c to c3f5e6d Compare September 4, 2026 01:56
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 4, 2026
@steipete
steipete force-pushed the codex/perf7-responses-json-equality branch from c3f5e6d to dd76c28 Compare September 4, 2026 03:43
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer-directed landing exception for dd76c28ffd9e1e28aae1c12ea7892175b2564939: the npm advisory request exhausted three attempts, ending with a 60-second timeout and no clearance. The maintainer explicitly instructed this campaign to ignore that advisory CI failure. Other selected checks passed in the retained exact-head snapshot; the audit and aggregate remain failed, and no security clearance is claimed.

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 b63ba7748c0d4e6a51c521fa802bd4a4f80f5b55 using the recorded source preflight and intervening changes. The exact merged tree will also be checked after landing.

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.

@steipete
steipete merged commit b6aa285 into main Sep 4, 2026
225 of 229 checks passed
@steipete
steipete deleted the codex/perf7-responses-json-equality branch September 4, 2026 05:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant