Skip to content

fix(codex): reduce CPU cost of large catalog previews - #150514

Merged
steipete merged 1 commit into
mainfrom
codex/team-catalog-preview-bounded-20260916
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-catalog-preview-bounded-20260916

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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

  • The regression goes through the real client and failed on the original code because 1,048,576 units reached the sanitizer. The candidate passes 119 tests across the client, catalog request lifetime, and catalog listing files, including whitespace, ANSI/C1, surrogate, fallback, and settlement cases. Independent review through P2 is clean.
  • A fixed fresh-process ABBA followed by BAAB comparison used the real response dispatcher and request attempts on macOS arm64, Node 26.8.2. Inputs were flattened before timing, with fresh response rows and written request attempts prepared outside each span. Every process ran all five cells with two warmup and eight measured batches. All output pages matched; source, runtime, loader, and installed dependency identities were verified. Every sample was retained.

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.

Synthetic response Baseline CPU Candidate CPU Median paired change
64 × 1 MiB plain previews 67.931 ms 0.381 ms −99.44%
64 × 1 MiB multiline previews 514.759 ms 1.693 ms −99.66%
One short preview 1.671 µs 2.025 µs +19.69%
64 short previews 50.125 µs 54.594 µs +4.96%
One 1 MiB whitespace-leading fallback 0.655 ms 0.843 ms +26.88%

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.

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
@clawsweeper

clawsweeper Bot commented Sep 17, 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.

@steipete
steipete marked this pull request as ready for review September 17, 2026 02:31
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 10:38 PM ET / September 17, 2026, 02:38 UTC.

ClawSweeper review

What this changes

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct optimization with strong boundary coverage and useful component measurements whose limitations are clearly stated.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor gate does not apply to this maintainer-authored PR. Its supplied macOS measurements exercise the changed production dispatcher with synthetic responses and report matching outputs and reduced large-preview CPU; they do not establish transport or whole-Gateway savings.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this maintainer-authored PR. Its supplied macOS measurements exercise the changed production dispatcher with synthetic responses and report matching outputs and reduced large-preview CPU; they do not establish transport or whole-Gateway savings.
Evidence reviewed 10 items Introduced optimization: The selector uses at most 2,048 input units only when normalization leaves more than 500 units without control characters. The existing sanitizer, surrogate-safe truncation, and UTF-8 string detachment remain authoritative.
Current main still needs the optimization: At the supplied main revision, catalog responses pass the entire preview directly into truncateCodexCatalogPreview. The branch's prefix selection is absent.
Sanitizer contract: The canonical sanitizer removes ANSI sequences and processes C0/C1 controls; a prefix without control characters is unchanged. The selector still calls this sanitizer and does not bypass sanitization.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +18, Tests +118. Total +136 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 20 2 +18
Tests 1 119 1 +118
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 139 3 +136

Review metrics

Metric Value Why it matters
Measured dispatcher CPU 64 × 1 MiB plain previews: 67.931 → 0.381 ms The supplied component benchmark supports substantial savings on eligible large previews, with small-input and fallback costs separately disclosed.

Technical review

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

Labels

Label changes:

  • add P2: This is a focused performance improvement for large native session previews, with no demonstrated urgent outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor gate does not apply to this maintainer-authored PR. Its supplied macOS measurements exercise the changed production dispatcher with synthetic responses and report matching outputs and reduced large-preview CPU; they do not establish transport or whole-Gateway savings.

Label justifications:

  • P2: This is a focused performance improvement for large native session previews, with no demonstrated 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. Not applicable: The external-contributor gate does not apply to this maintainer-authored PR. Its supplied macOS measurements exercise the changed production dispatcher with synthetic responses and report matching outputs and reduced large-preview CPU; they do not establish transport or whole-Gateway savings.

Evidence

What I checked:

Likely related people:

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

@steipete
steipete merged commit 5d1389f into main Sep 17, 2026
170 checks passed
@steipete
steipete deleted the codex/team-catalog-preview-bounded-20260916 branch September 17, 2026 02:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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