Skip to content

fix(codex): use truncateUtf16Safe in trajectory and client parse log truncation#102576

Merged
steipete merged 2 commits into
openclaw:mainfrom
lsr911:fix/utf16-codex-trajectory
Jul 9, 2026
Merged

fix(codex): use truncateUtf16Safe in trajectory and client parse log truncation#102576
steipete merged 2 commits into
openclaw:mainfrom
lsr911:fix/utf16-codex-trajectory

Conversation

@lsr911

@lsr911 lsr911 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Codex app-server malformed-message previews and trajectory string values used raw UTF-16 slices. Arbitrary app-server output containing an emoji at either cutoff could therefore leave an unpaired surrogate in diagnostic logs or trajectory JSON.

Why This Change Was Made

Use the existing truncateUtf16Safe plugin-SDK helper at both Codex-owned diagnostic boundaries. The current 500- and 20,000-code-unit limits, redaction order, and suffixes remain unchanged.

User Impact

Codex app-server diagnostics and trajectory sidecars remain valid Unicode when supplementary characters cross their size limits.

Evidence

  • Added malformed-message preview coverage at the 500-code-unit boundary.
  • Added recorder-level trajectory coverage at the 20,000-code-unit boundary.
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/client.test.ts extensions/codex/src/app-server/trajectory.test.ts — 2 files, 45 tests passed.
  • Targeted oxfmt and git diff --check passed.
  • Fresh autoreview: clean, no accepted/actionable findings (0.99).
  • Direct Codex contract check at db887d03e1f907467e33271572dffb73bceecd6b: app-server serializes arbitrary outgoing JSON to stdout in stdio.rs, command output deltas are arbitrary strings in item.rs, and diagnostics use stderr in lib.rs.

Files Changed

File Change
extensions/codex/src/app-server/client.ts Keep parse-log previews UTF-16 safe.
extensions/codex/src/app-server/client.test.ts Add preview boundary regression coverage.
extensions/codex/src/app-server/trajectory.ts Keep sanitized trajectory strings UTF-16 safe.
extensions/codex/src/app-server/trajectory.test.ts Add recorder-level boundary coverage.

🤖 Generated with Claude Code

…truncation

Replace naive .slice(0, N) with truncateUtf16Safe() in:
- trajectory.ts: payload redaction display (20k char limit)
- client.ts: parse error log truncation

Co-Authored-By: Claude <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added extensions: codex size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the patch is narrow and appears functionally correct, but this external PR lacks after-fix real behavior proof, so it is not ready for cleanup-close or merge.

Canonical path: Close this PR as superseded by #102542.

So I’m closing this here and keeping the remaining discussion on #102542.

Review details

Best possible solution:

Close this PR as superseded by #102542.

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

Yes from source: current main's raw slice calls can cut a UTF-16 surrogate pair when an emoji crosses the 500-character parse-preview or 20,000-character trajectory boundary. I did not run a live Codex app-server repro, so this is source-reproducible rather than fully reproduced.

Is this the best way to solve the issue?

Yes, the code shape is the best narrow fix: it stays inside the plugin SDK boundary and reuses the existing surrogate-safe helper already used by sibling Codex app-server paths. The merge path still needs contributor real behavior proof and ideally focused regression coverage.

Security review:

Security review cleared: The diff only reuses an existing text helper after existing redaction logic and does not change dependencies, permissions, credentials, or secret handling.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • miorbnli: git blame on current main attributes the touched Codex app-server client, trajectory, and UTF-16 helper lines to e6a2136. (role: recent area contributor; confidence: medium; commits: e6a2136c3a0b; files: extensions/codex/src/app-server/client.ts, extensions/codex/src/app-server/trajectory.ts, packages/normalization-core/src/utf16-slice.ts)
  • vincentkoc: git log -S shows e085fa1 added earlier versions of the Codex app-server client and trajectory files containing the same raw-slice truncation sites. (role: introduced earlier shipped Codex app-server copy; confidence: medium; commits: e085fa1a3ffd; files: extensions/codex/src/app-server/client.ts, extensions/codex/src/app-server/trajectory.ts)
  • steipete: git log -S traces the surrogate-safe UTF-16 helper family back to 63f5fa4, authored by Peter Steinberger. (role: adjacent helper owner; confidence: medium; commits: 63f5fa47deb6; files: packages/normalization-core/src/utf16-slice.ts, src/utils.ts, src/plugin-sdk/text-utility-runtime.ts)
  • wings1029: Current main's latest related PR, fix(agent-core,memory-core): keep compaction summary and memory snippet truncation UTF-16 safe #102542, fixed the same UTF-16-safe truncation invariant for compaction and memory snippets. (role: recent adjacent contributor; confidence: medium; commits: f7cc6ebe1e0b; files: packages/agent-core/src/harness/compaction/utils.ts, extensions/memory-core/src/short-term-promotion.ts)

Codex review notes: model internal, reasoning high; reviewed against f7cc6ebe1e0b.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Land-ready verification at exact head 2d90ae635e4017024de6e58a608b7a2eac5adddb:

  • Improved the patch with recorder-level and client-log boundary regressions. The tests cover emoji straddling both production limits and assert the complete output, including the expected ellipsis.
  • node scripts/run-vitest.mjs extensions/codex/src/app-server/client.test.ts extensions/codex/src/app-server/trajectory.test.ts — 45 tests passed.
  • oxfmt and git diff --check passed.
  • Fresh autoreview: clean, 0.99 confidence; no accepted/actionable findings.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 102576 passed exact-head hosted CI/Testbox gates.
  • Direct dependency contract check: upstream Codex app-server emits one JSON message per stdout line in stdio.rs, and command output deltas carry arbitrary strings in item.rs. That makes the two changed OpenClaw truncation boundaries the correct owner surface.

No docs, config, protocol, or dependency changes. Ready to merge.

@steipete
steipete merged commit f650d64 into openclaw:main Jul 9, 2026
97 of 98 checks passed
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
…truncation (openclaw#102576)

* fix(codex): use truncateUtf16Safe in trajectory and client parse log truncation

Replace naive .slice(0, N) with truncateUtf16Safe() in:
- trajectory.ts: payload redaction display (20k char limit)
- client.ts: parse error log truncation

Co-Authored-By: Claude <[email protected]>

* test(codex): cover UTF-16 truncation boundaries

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants