Skip to content

fix(codex): preserve Unicode diagnostics boundaries - #103740

Merged
steipete merged 3 commits into
openclaw:mainfrom
wings1029:fix/utf16-safe-codex-diagnostics-error-v2
Jul 10, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
wings1029:fix/utf16-safe-codex-diagnostics-error-v2

Conversation

@wings1029

@wings1029 wings1029 commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Codex diagnostics command used raw UTF-16 prefix slices for both the optional feedback reason (2,048 units) and failed-upload error text shown in chat (500 units). If either boundary lands between an emoji's surrogate halves, OpenClaw can send or display malformed text.

Why This Change Was Made

  • Use the supported plugin SDK UTF-16 truncator at both owner-local boundaries.
  • Keep the formatting helpers private instead of expanding production API only for tests.
  • Exercise both defects through the real handleCodexCommand request/confirm path.
  • Assert the exact confirmation note, complete feedback/upload payload, and complete failed-upload reply.

Upstream Codex commit c4318c386de365bd0dd9595a08d55a30bb142d11 defines feedback/upload.reason as an optional string and forwards it unchanged to the feedback uploader, so OpenClaw owns its local 2,048-unit policy.

User Impact

Long diagnostics notes and failed-upload messages no longer acquire replacement glyphs or lone surrogates when an emoji crosses an OpenClaw boundary. Existing limits, escaping, confirmation, cooldown, and upload behavior remain unchanged.

Evidence

  • Command-path coverage places an emoji across the 2,048-unit reason boundary and checks the exact preview line and outbound request.
  • Command-path coverage places an emoji across the 500-unit error boundary and checks the exact user-visible reply.
  • Contributor credit is preserved in the replacement commit.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 10, 2026, 7:43 PM ET / 23:43 UTC.

Summary
The PR replaces raw UTF-16 prefix slicing at the Codex diagnostics reason and failed-upload error limits with the public surrogate-safe truncator and adds command-path boundary tests.

PR surface: Source +4, Tests +40. Total +44 across 2 files.

Reproducibility: yes. Current-main source provides a high-confidence reproduction: place an emoji so its surrogate pair crosses either raw prefix limit, and the result retains a lone high surrogate.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Post a redacted terminal transcript, live output, or logs showing the after-fix diagnostics reason or failed-upload boundary in a real setup.
  • Correct the PR body’s upstream citation; updating the body should trigger a fresh ClawSweeper review, otherwise ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The external PR provides mocked command-path tests and a synthetic JavaScript comparison, but no redacted after-fix run from a real Codex diagnostics setup; terminal output, live output, or logs are required before merge, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The PR body currently names an unrelated upstream Codex commit as contract evidence; although current upstream source supports the implementation, the citation should be corrected before landing.

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused owner-local safe truncation after the contributor supplies redacted real diagnostics output and corrects the upstream evidence citation, while preserving the existing limits and avoiding new API surface.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] No mechanical code repair is needed; the contributor must add real behavior proof and correct the PR-body source citation before maintainers consider merging.

Security
Cleared: The source-and-test-only patch adds no dependency, package-resolution, workflow, permission, secret, downloaded artifact, or executable supply-chain surface.

Review details

Best possible solution:

Land the focused owner-local safe truncation after the contributor supplies redacted real diagnostics output and corrects the upstream evidence citation, while preserving the existing limits and avoiding new API surface.

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

Yes. Current-main source provides a high-confidence reproduction: place an emoji so its surrogate pair crosses either raw prefix limit, and the result retains a lone high surrogate.

Is this the best way to solve the issue?

Yes. Reusing the established public plugin SDK truncator at the two Codex-owned limits is the narrowest maintainable fix; changing upstream Codex or adding another helper would be broader and unnecessary.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The external PR provides mocked command-path tests and a synthetic JavaScript comparison, but no redacted after-fix run from a real Codex diagnostics setup; terminal output, live output, or logs are required before merge, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: The PR fixes malformed Unicode in a limited optional Codex diagnostics workflow without changing configuration, defaults, or protocol behavior.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The external PR provides mocked command-path tests and a synthetic JavaScript comparison, but no redacted after-fix run from a real Codex diagnostics setup; terminal output, live output, or logs are required before merge, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +4, Tests +40. Total +44 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 2 +4
Tests 1 44 4 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 50 6 +44

What I checked:

Likely related people:

  • pashpashpash: Authored and merged the diagnostics command work that introduced the reason and error-display boundaries and their initial tests. (role: introduced behavior; confidence: high; commits: 6ce1058296cc; files: extensions/codex/src/command-handlers.ts, extensions/codex/src/commands.test.ts)
  • steipete: Authored and merged several recent Codex command-handler and app-server refactors, making him the strongest current routing candidate for this boundary fix. (role: recent area contributor; confidence: high; commits: 69566e43cb8b, 0d981095d430, e5798e547770; files: extensions/codex/src/command-handlers.ts, extensions/codex/src/commands.test.ts, extensions/codex/src/app-server/client.ts)
  • vincentkoc: Authored merged Codex harness control-surface and auth-order work adjacent to the diagnostics app-server request boundary. (role: adjacent owner; confidence: medium; commits: ac3cd1a0ca8c, eb1a0aa574b5; files: extensions/codex/src/command-handlers.ts, extensions/codex/src/app-server)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (2 earlier review cycles)
  • reviewed 2026-07-10T14:57:32.866Z sha 51e6db2cbe1862818f4747aef72ded62e999230e :: needs real behavior proof before merge. :: [P1] Import truncation through the packaged plugin SDK | [P2] Detect the orphan surrogate in the error regression
  • reviewed 2026-07-10T16:17:44.086Z sha 920ecc3282ae23cba4c0d0cbc7d608c2db931da4 :: needs real behavior proof before merge. :: none

@wings1029
wings1029 force-pushed the fix/utf16-safe-codex-diagnostics-error-v2 branch from 51e6db2 to 920ecc3 Compare July 10, 2026 15:42
@wings1029

Copy link
Copy Markdown
Contributor Author

Changes from review feedback

P1: Fixed import path

Switched from undeclared @openclaw/normalization-core/utf16-slice to openclaw/plugin-sdk/text-utility-runtime. The @openclaw/codex package has bundleRuntimeDependencies: false and does not declare @openclaw/normalization-core, so standalone installs would fail module resolution.

P2: Fixed boundary test

Replaced not.toContain("�") with a code-point scan that actually detects orphan surrogates. The original assertion could not distinguish the fix from broken behavior because JS stores orphan surrogates as their raw code unit (e.g. \ud83d), not as the replacement character � (U+FFFD).

Proof: boundary split verified

Input: "x".repeat(499) + "🚀" (501 code units)
After formatCodexTextForDisplay: 501 code units

MAIN  .slice(0, 500):
  length: 500
  has orphan surrogate: true ← BUG

BRANCH truncateUtf16Safe(result, 500):
  length: 499  (backed off by 1)
  has orphan surrogate: false ← FIXED

Tests: 6 tests pass (4 normalizeDiagnosticsReason + 2 formatCodexErrorForDisplay) ✓

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 10, 2026
@steipete
steipete force-pushed the fix/utf16-safe-codex-diagnostics-error-v2 branch from 920ecc3 to bbea243 Compare July 10, 2026 23:14
@steipete steipete changed the title fix(codex): keep diagnostics error message truncation UTF-16 safe fix(codex): preserve Unicode diagnostics boundaries Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(codex): preserve Unicode diagnostics boundaries This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. labels Jul 10, 2026
@steipete

Copy link
Copy Markdown
Contributor

Land-ready at exact head 912f2d8aabf9c1f2661df6ecd1c9abd3cba7ca8e.

  • Rebuilt the contributor patch as the combined best fix: both diagnostics bounds use the supported openclaw/plugin-sdk/text-utility-runtime helper, both helpers remain private, and the regressions exercise the real command handler rather than test-only exports.
  • Exact command-path evidence covers the 2,048-unit note boundary in the confirmation preview and feedback/upload payload, plus the 500-unit upload-error boundary in the user-visible failed-upload reply.
  • Hosted CI run 29130573132 completed successfully at the exact head, including build, lint, production/test types, contracts, guards, QA smoke, and every selected test shard.
  • Sanitized public AWS run run_a755ec2d15f4 passed 593 focused Codex command and plugin-contract tests at the immediately preceding runtime-equivalent head; run_7cc7107c7b5a passed the full production build. The final one-line test typing correction is covered by exact-head hosted CI.
  • Targeted oxfmt --check and git diff --check passed. Fresh Codex autoreview is clean with 0.99 correctness confidence.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 103740 passed its exact-head hosted gates.

Dependency contract checked directly in OpenAI Codex at c4318c386de365bd0dd9595a08d55a30bb142d11: codex-rs/app-server-protocol/src/protocol/v2/feedback.rs:11-22 accepts the optional free-form reason, codex-rs/app-server/src/request_processors/feedback_processor.rs:55-62,229 forwards it unchanged, and codex-rs/app-server-protocol/src/protocol/common.rs:1050-1053 owns feedback/upload. No upstream length contract conflicts with OpenClaw's presentation limits.

Known proof gap: no real feedback upload was triggered because doing so would send diagnostic logs to OpenAI servers solely for test evidence.

@steipete
steipete merged commit 63859f7 into openclaw:main Jul 10, 2026
109 of 113 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 11, 2026
* fix(codex): preserve Unicode diagnostics boundaries

Co-authored-by: 陈志强0668000989 <[email protected]>

* test(codex): assert diagnostics preview boundary

* test(codex): narrow diagnostics result text

---------

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 P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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