Repository navigation
improve: reuse UTF-8 encoding while fitting Code Mode output - #137132
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Real Gateway follow-up: all four fixed real OpenAI turns and 57 RPC checks passed on the immutable candidate composite containing this PR. The PR body now records web fetch, oversized Unicode, MCP schema/default/dispatch and session/subscription/reconnect evidence, plus the source identity and clean shutdown limits. This supersedes the earlier pending integration note. |
|
Codex review: blocked before merge. Reviewed September 3, 2026, 5:09 AM ET / 09:09 UTC. ClawSweeper reviewWhat this changesThe PR prepares one bounded UTF-8 encoding for Code Mode’s JSON-prefix search and adds contract coverage for reusable prefix reads. Merge readiness⛔ Blocked before merge - 2 items remain Keep this maintainer-authored PR open for normal maintainer approval. The current-main base repeatedly re-encodes each binary-search prefix; the introduced bounded encoder preserves the documented UTF-8 and serialized-budget contract, with no actionable correctness or security finding. Priority: P3 Review scores
Verification
How this fits togetherCode Mode bounds tool-result JSON before it returns to the agent. The execution and headless paths use the output-state owner to fit Unicode-safe prefixes within the shared result budget. flowchart LR
A[Tool or guest output] --> B[Code Mode execution]
B --> C[Output-state owner]
C --> D[Prepared UTF-8 prefix]
D --> E[JSON budget check]
E --> F[Bounded agent result]
Decision needed
Why: Repository policy keeps MEMBER-authored and Before merge
Agent review detailsSecurityNone. PR surfaceSource +18, Tests +13. Total +31 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Preserve the existing bounded-result contract and merge the focused optimization once a listed maintainer accepts the measured trade-off and exact-head checks are green. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes an internal existing path rather than reporting a user-visible defect; source comparison identifies the repeated encoding at the current-main owner. Is this the best way to solve the issue? Yes. Preparing the encoding at the existing binary-search owner avoids repeated conversion without changing the caller’s JSON-budget decision or one-shot truncation callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 590ee376ad0c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
82cdb01 to
81bed82
Compare
|
Addressed the benchmark finding and rank-up request in the PR body. Fixed ABBA runs of 100 oversized-Unicode projections measured baseline 1291.46/1286.85 ms and 145.06/145.97 MiB peak process RSS, versus candidate 904.45/896.91 ms and 131.33/130.73 MiB. Every result digest matched; all four processes cleaned up. These scoped observations do not establish a general Gateway or retained-memory improvement. The branch includes the upstream main lint fix #137149 with reviewed source hashes unchanged; required CI is running. |
81bed82 to
6685a28
Compare
|
Final composite Oversized Unicode output retained a well-formed prefix, its byte budget and exact omitted-byte accounting. The separate encoded-buffer counters remain the direct prefix-preparation evidence. The composite’s sampled reduction, predominantly in an anonymous/non-arm group, cannot be assigned specifically to this PR. One fixed pair: main-isolate Unicode allocation estimates −35.0037%/−31.3677%; idle post-GC RSS/heap deltas +4.203125/−0.125908 MiB (Code Mode), −3.718750/−0.012688 MiB (Tool Search). RSS covers the Gateway process; heap covers its main isolate. This supports no per-PR attribution or general RSS claim. Exact-head CI and native landing gates remain required. |
|
Maintainer disposition: accepting the prepared UTF-8 optimization for landing now that exact-head CI is green. The additional 18 production lines establish one bounded reusable encoding while preserving the serialized output contract. The fixed ABBA fixture measured 1,291/1,287 ms before and 904/897 ms after; the contract comparisons and 169 focused tests passed. The composite live Unicode allocation reduction is supporting integration evidence, not a per-PR RSS or latency claim. |
|
Merged via squash.
|
What Problem This Solves
Fitting Code Mode output to a JSON budget repeatedly encoded the same string during binary-search trials.
Why This Change Was Made
The result owner now prepares one bounded UTF-8 encoding per synchronous prefix search and shares the existing boundary decoder. One-shot truncation retains its allocation-free full-fit path. Nonpositive bounds return before encoding; prepared limits cannot exceed the bound used to create the helper.
User Impact
Output, error text, Unicode handling and byte/context budgets remain unchanged. Production +18 LOC expresses the bound-owned prepared encoding and shared decoder; tests +13. No cache, public option or plugin SDK export is added.
Evidence
The first hosted CI run failed on unchanged
src/node-host/runner.test.tsexceeding the repository line limit (1,006 versus 1,000). That main-branch test cleanup is being repaired separately; this PR will not land until its checks pass.Real Gateway integration (2026-09-03)
A prebuilt, isolated Gateway with a real OpenAI API key passed four fixed turns: ordinary completion, real
web_fetchof example.com, a 1.31 MB Unicode return through Code Mode, and a real MCP stdio tool with default and explicit arguments. Fifty-seven Gateway RPCs verified three session identities, full/repeated/paginated/subscribed list rows, descriptions and final previews, transcript completion, an explicit reconnect, empty approval replay and unsubscribe.The MCP server observed the default
id: alphabefore server-side validation, followed by explicitid: beta; both nested call identities/order, structured results and metadata projection matched. The Unicode prefix remained well formed and within its byte budget with exact omitted-byte accounting. All four turns completed without retries.The local immutable composite
3bb6e3164a06e5c35fb50b368cc63cbb05826384contains the twelve published campaign changes through #137148, including this PR’s reviewed source. Source/build/dependency identity was checked before and after. Both clients closed, the Gateway exited successfully without escalation, all recorded MCP processes exited, and private state/port cleanup passed. This is functional integration proof; it does not attribute memory or latency differences to this PR.Scoped wall-time and RSS benchmark
A fixed ABBA run used fresh Node 26.8.1 processes, 10 warmup projections and 100 measured projections of the same oversized Unicode output/value through the actual Code Mode JSON owner. Every timed result digest matched across all four processes; source hashes were checked before and after. No Inspector sampling or forced GC was used.
Peak RSS is the macOS
/usr/bin/time -lwhole-process high-water mark, including imports and warmup. This narrow workload improved in both pairs, but two observations per arm do not establish a general throughput or retained-memory improvement. The separate real Gateway comparison is a different multi-change experiment and is not attributed to this PR. Earlier allocation samples, including the initial candidate's adverse result, remain recorded.Benchmark source SHA-256:
9bb9264d3f749689961ee0f5ea960ca96097ec34361b5ff45c720490b34c7585. Fixed output digest:3419d9fdb044f9ddbe4a1fd92251b66a4275a2c0f8b3d25715de56c9a3c7ef24. All four supervised processes exited zero; their process groups and private runtime directories were removed.