Repository navigation
fix(codex): reduce CPU cost of large catalog previews - #150514
Conversation
Use a certified plain prefix for oversized native catalog previews while preserving full parsing for ambiguous input, UTF-16 truncation, detached string storage, and request settlement. Related: #150112
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 10:38 PM ET / September 17, 2026, 02:38 UTC. ClawSweeper reviewWhat this changesThe Codex plugin uses a bounded, control-free prefix to reduce formatting work for large session previews while preserving the existing fallback and displayed text. Merge readiness✅ Ready for maintainer review This remains a useful optimization beyond the merged catalog-memory fix: current main still processes full previews before truncation. No introduced correctness or security defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe Codex session catalog receives native thread-list responses and prepares short previews for session browsing. This change reduces text processing inside the response dispatcher before catalog consumers receive those previews. flowchart TD
A[Native thread response] --> B{Catalog request?}
B -->|No| C[Unchanged response]
B -->|Yes| D{Safe prefix exceeds display limit?}
D -->|Yes| E[Use bounded prefix]
D -->|No| F[Use full preview]
E --> G[Sanitize and truncate]
F --> G
G --> H[Deliver catalog response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +18, Tests +118. Total +136 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the optimization in the catalog dispatcher, preserving full-input fallback, the canonical sanitizer, detached preview storage, and ordinary response behavior. Do we have a high-confidence way to reproduce the issue? Yes, at source level: a catalog response containing a 1 MiB preview reaches full-input normalization and sanitization on current main before its 500-unit truncation. This review did not execute a benchmark. Is this the best way to solve the issue? Yes. The guarded prefix optimization reuses existing formatting ownership and preserves the full path wherever prefix equivalence cannot be established. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c7436e77ca81. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Use a certified plain prefix for oversized native catalog previews while preserving full parsing for ambiguous input, UTF-16 truncation, detached string storage, and request settlement. Related: openclaw#150112
Related: #150112
What Problem This Solves
Large native session previews spend CPU formatting text that the catalog discards beyond its 500-unit display limit.
User Impact
Eligible large previews require substantially less dispatcher CPU while preserving their exact displayed text and request behavior. Differences between measured medians were +0.354 µs for one short preview, +4.469 µs for 64 short previews, and +0.187 ms for the whitespace-heavy fallback. These remain explicit tradeoffs.
Why This Change Was Made
For oversized inputs, the new selector first checks a 2,048-unit UTF-16 prefix. It uses that prefix only when whitespace normalization and trimming leave more than 500 units and no terminal controls; otherwise the existing full-text path runs. Those conditions preserve the output boundary and make the canonical sanitizer an identity operation over the relevant prefix.
Only the canonical response dispatcher selects this shortcut. The injected sanitizer path and lazy imports remain intact, as do repeated projection, surrogate-safe truncation, UTF-8 detachment for long and already-short strings, ordinary response handling, and request settlement.
Evidence
Main-thread CPU per synchronous dispatcher call is shown below. CPU columns are medians of the four process medians; the final column is the median change within the four matched pairs.
The spans include the dispatcher loop, synchronous request settlement, adjacent counter-read overhead, and natural allocator/GC effects. They exclude input and attempt creation, JSON parsing, transport, and awaiting and validating the resolved result. These are component results; they do not establish overall Gateway CPU savings or the cause of the control regressions.
The backing-string check retained 128 previews from a 32 MiB corpus. Retained heap grew by 95,896 bytes for long inputs and 92,272 bytes for already-short slices; the same-runtime synthetic no-detachment control retained 33,564,480 bytes. Both positive cases passed the 8 MiB bulk-retention guard and the negative exceeded its 24 MiB calibration floor. This checks bulk parent-string release, not zero retained parents.
The configured Blacksmith changed-file gate passed: production and extension-test types, typed lint, doctor contracts, plugin and loader guards, and zero runtime import cycles. The one-shot Testbox stopped successfully after the command completed.