Skip to content

perf(codex): reuse unchanged inference request bytes - #155987

Merged
steipete merged 1 commit into
mainfrom
codex/team-r3-inference-20260922
Sep 22, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-r3-inference-20260922

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large native Codex requests were serialized again by the inference relay even when no parent-local instructions changed, and zstd HTTP bodies were recompressed unnecessarily.

User Impact

Unchanged requests use less allocation and CPU in the relay. Parent-local instruction injection, request validation, current-generation checks, the 32 MiB body limit, admission, backpressure, and transport ownership remain intact. No configuration or migration is required.

Why This Change Was Made

The context owner already returns the original parsed object when no injection is needed. The relay now uses that decision to retain valid native UTF-8 bytes and, for unchanged HTTP requests, the original compressed wire body. Malformed UTF-8 retains the previous decode-and-serialize replacement behavior. Injected requests still take the existing encoding path.

Native source inspection verified typed Responses request encoding and typed tool schemas before raw JSON wrapping. Byte preservation keeps native number and escape representations intact instead of normalizing them through JavaScript.

Evidence

  • 62 focused HTTP/TLS, reusable WebSocket, context, capacity, and cancellation tests passed. Both new plain/zstd wire-preservation regressions fail on the original owner and pass with this change; empty-context parents still revalidate authority before forwarding.
  • Synthetic real-proxy benchmark: 64 KiB, 4 MiB, and 24 MiB requests over HTTP, zstd HTTP, and reusable WebSockets, unchanged and injected. Every output and native metadata matched. At 24 MiB, sampled JS allocation per unchanged request fell by about 24 MiB: HTTP 77.0 → 52.8 MiB, zstd 78.7 → 53.3 MiB, WebSocket 73.0 → 49.0 MiB. Injected allocation stayed approximately flat.
  • Separate unprofiled paired run at 24 MiB: unchanged zstd main-thread CPU 282.5 → 208.3 ms/request, total process CPU 685.0 → 467.8 ms/request. HTTP and WebSocket main-thread changes were smaller (158.6 → 152.9 ms and 289.4 → 270.5 ms). Measurements include the synthetic client/upstream, use a busy shared host, and do not establish production-wide savings. Unfavorable cells remain in the measurement record: injected HTTP main CPU 185.0 → 189.2 ms; injected WebSocket roundtrip 387.9 → 418.4 ms.
  • Test cost with pnpm test <file> --maxWorkers=1: HTTP file 7 tests, 75.56 s wall including cold worker compilation (~0.6 s test bodies); proxy file 19 tests, 6.07 s wall (~0.5 s test bodies). Exact-run CI grouped Codex selection: 81.27 s Vitest duration; 203 s for the full checks-node-changed-extensions-config-1 job, including setup and other selected files. These are grouped timings, not per-file timings.
  • Real provider acceptance: the empty-context branch completed an isolated native Codex 0.154.0 turn against gpt-5.5 and returned exact RELAY_OK (7.974 s). The broad live invocation was interrupted after that completed case; a second injected-context provider case did not complete. This is acceptance evidence, not provider performance evidence.
  • Bun 1.4.2 real HTTP/TLS transport suite: all 7 tests passed, including the new node:buffer UTF-8 path, zstd forwarding, capacity and backpressured cancellation.
  • Chosen changed-file gates passed: extension production/test types, targeted lint/format, and repository boundary guards. Local production/full-tree Knip scans reached their 600 s deadline on the contended host; all three scans then passed on the exact candidate tree on Linux Blacksmith Testbox, with wrapper exit 0. The completed one-shot lease was stopped cleanly, which marks its backing Actions run canceled.
  • Independent managed P0–P2 review: no actionable findings.

@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: S maintainer Maintainer-authored PR labels Sep 22, 2026
@steipete
steipete marked this pull request as ready for review September 22, 2026 22:28
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 7:23 PM ET / 23:23 UTC (Revision 2).

ClawSweeper review

What this changes

The Codex inference relay preserves unchanged request bytes and HTTP compression, with transport regression coverage and updated documentation.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful: current main still reserializes unchanged requests. The focused patch preserves validation and instruction injection, and no actionable correctness or security defect was found.

Priority: P2
Reviewed head: 57e13937042164ca4eb2738d81fb8d2924dbf55c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful transport regressions and sufficient reported runtime evidence; performance conclusions remain appropriately bounded.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured PR evidence connects the relay fast path to a completed native provider turn returning RELAY_OK and real-proxy HTTP/zstd/WebSocket measurements with matching outputs. The unfinished injected-provider case is disclosed; existing injection coverage remains supplemental. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR evidence connects the relay fast path to a completed native provider turn returning RELAY_OK and real-proxy HTTP/zstd/WebSocket measurements with matching outputs. The unfinished injected-provider case is disclosed; existing injection coverage remains supplemental. No stored-data contract changes.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head diff. Production changes are confined to retaining valid UTF-8 bytes when context preparation returns the original object and retaining HTTP wire bytes when no transformation occurred.
Context and authority remain owned: Context preparation returns the original object for exempt native purposes and empty parent context; injected instructions produce a new object. Empty-context parent requests still validate registration and generation and retain their cancellation signal. HTTP beforeRequest and WebSocket forwarding still revalidate before I/O.
Meaningful transport regressions: The HTTP tests assert exact plain and zstd wire bytes across six native request contexts, including empty-context parents, and retain malformed UTF-8 replacement behavior. WebSocket coverage checks exact frames and cancellation; the admission test now includes empty context. Tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw’s private Codex relay receives native model requests, validates their context, and adds parent-only instructions when needed. It forwards those requests to the provider over HTTP or WebSockets.

flowchart TD
  A[Native Codex request] --> B[Private inference relay]
  B --> C[Validate request and context]
  C --> D{Instructions need injection?}
  D -->|Yes| E[Inject and encode]
  D -->|No| F[Reuse valid original bytes]
  E --> G[Revalidate and forward to provider]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +9, Tests +88, Docs +4. Total +101 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 2 +9
Tests 2 113 25 +88
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 129 28 +101

Review metrics

Metric Value Why it matters
Reported allocation improvement About 24 MiB less JS allocation per unchanged 24 MiB request The paired real-proxy measurements support the optimization’s purpose, with shared-host and synthetic-workload limitations disclosed.

Technical review

Best possible solution:

Keep context preparation as the sole instruction owner and reuse native bytes whenever it leaves the request unchanged.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug reproduction: this is a performance optimization. Current-main source confirms the redundant serialization and recompression; supplied measurements exercise that cost.

Is this the best way to solve the issue?

Yes. Reusing the existing context owner’s unchanged-object result avoids duplicate policy and preserves the established injection and validation paths.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 370e17484d58.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded CPU and allocation improvement for large Codex requests, without an established urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR evidence connects the relay fast path to a completed native provider turn returning RELAY_OK and real-proxy HTTP/zstd/WebSocket measurements with matching outputs. The unfinished injected-provider case is disclosed; existing injection coverage remains supplemental. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR evidence connects the relay fast path to a completed native provider turn returning RELAY_OK and real-proxy HTTP/zstd/WebSocket measurements with matching outputs. The unfinished injected-provider case is disclosed; existing injection coverage remains supplemental. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: 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 (1 earlier review cycle)
  • reviewed 2026-09-22T22:51:04.303Z sha 57e1393 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 714ff41 into main Sep 22, 2026
175 checks passed
@steipete
steipete deleted the codex/team-r3-inference-20260922 branch September 22, 2026 23:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 22, 2026
* commit '7d7f977ccfc1ac177526232e4f4960febd010015': (91 commits)
  test: avoid unused target setup in package profile fixtures (#155972)
  fix(worktrees): batch snapshot metadata reads
  test(plugin-state): distinguish borrowed and foreign lifecycle owners
  refactor(agents): share external harness session and attempt machinery (#152181)
  chore(i18n): refresh native locales (#156006)
  chore(test): retain Doctor fixture settlement diagnostics (#155944)
  perf(codex): reuse unchanged inference request bytes (#155987)
  perf(test): prepare snapshot ownership subprocess imports (#155973)
  perf(test): consolidate channel registry coverage (#155014)
  fix(runtime): preserve Node worker dependencies and cleanup diagnostics (#155292)
  perf(test): prepare worktree GC child runtime (#155928)
  fix(ui): open browser cards after delayed panel renders (#153253)
  fix(update): retain the running updater by hard link instead of copying the package (#155977)
  feat(decisions): add explicit evaluation and Labs opt-in foundation (#155134)
  fix(state): preserve lifecycle custody across worker dispatch
  improve: reuse shared tooling fixtures and defer legacy updater proof (#155731)
  improve(ui): reduce real-Gateway test preparation (#155979)
  perf(state): move session RPC SQL off the Gateway main thread (#155740)
  docs(freebsd): explain native Codex runtime limits (#155980)
  fix(qa): count Code Mode nested tool activity as transcript tool evidence (#155976)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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