Repository navigation
fix(ai): keep OpenAI tool call id truncation UTF-16 safe - #110471
Conversation
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
1 similar comment
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 6:23 PM ET / 22:23 UTC. ClawSweeper reviewWhat this changesReplaces raw 40-code-unit OpenAI tool-call ID truncation with the existing UTF-16-safe helper and adds a paired assistant/tool-result regression test. Merge readinessKeep open: current main still raw-slices OpenAI replay tool-call IDs at the surrogate boundary, while this PR applies the established safe truncator at the owning converter and preserves paired result IDs. Priority: P2 Review scores
Verification
How this fits togetherThe AI package converts stored agent transcripts into OpenAI Chat Completions request messages. Cross-model replay normalizes tool-call IDs before the OpenAI SDK sends matching assistant and tool-result IDs to the provider. flowchart LR
A[Stored assistant transcript] --> B[OpenAI replay converter]
B --> C[Cross-model ID normalization]
C --> D[Assistant tool-call ID]
C --> E[Paired tool-result ID]
D --> F[OpenAI SDK request]
E --> F
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1, Tests +48. Total +49 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the narrow converter-boundary repair after refreshing its clean merge against current main. Do we have a high-confidence way to reproduce the issue? Yes: on current main, cross-model replay of a 41-code-unit ID with a surrogate pair at units 40–41 reaches the raw slice and yields a dangling high surrogate; the focused PR test encodes this path. Is this the best way to solve the issue? Yes: the existing safe truncator belongs exactly in the OpenAI converter's 40-unit branch, rather than in shared transcript normalization where the limit is not universal. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 57a1cbbeee48. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (19 earlier review cycles; latest 8 shown)
|
e1f904a to
15fd8cb
Compare
Rebased + real behavior proof1. Rebased onto current
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Mutation proof: before/after terminal outputBEFORE fix (
|
|
@clawsweeper re-review |
1 similar comment
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
8e0ad4c to
1b9a961
Compare
1b9a961 to
2259aa2
Compare
2259aa2 to
49d715b
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
Merged via squash.
|
* 'main' of https://github.com/openclaw/openclaw: test(qa): cover sandboxed exec behavior (#119053) test(qa): prove shared-channel memory recall (#119111) fix(telegram): keep request deadlines through response bodies test(qa): cover gateway plugin approvals (#119128) fix(ai): keep OpenAI tool call id truncation UTF-16 safe (#110471) fix: preserve live updater failure diagnostics (#119096) fix: recover new-session models through Gateway startup (#119120) test(qa): cover instruction profile artifacts (#119078) fix(telegram): record automatic delivery message ids test(qa): cover memory promotion safety (#119093) test(qa): prove overflow compaction pruning (#119033) fix(tool-search): preserve deferred MCP failures (#118363) fix(macos): keep setup activation within app checks test(setup): type provider kind fixture fix(setup): complete prepared model activation fix(protocol): regenerate Swift wizard models fix(ollama): activate the model selected during setup fix(setup): preserve the prepared model handoff
* 'main' of https://github.com/openclaw/openclaw: test(qa): cover sandboxed exec behavior (openclaw#119053) test(qa): prove shared-channel memory recall (openclaw#119111) fix(telegram): keep request deadlines through response bodies test(qa): cover gateway plugin approvals (openclaw#119128) fix(ai): keep OpenAI tool call id truncation UTF-16 safe (openclaw#110471) fix: preserve live updater failure diagnostics (openclaw#119096) fix: recover new-session models through Gateway startup (openclaw#119120) test(qa): cover instruction profile artifacts (openclaw#119078) fix(telegram): record automatic delivery message ids test(qa): cover memory promotion safety (openclaw#119093) test(qa): prove overflow compaction pruning (openclaw#119033) fix(tool-search): preserve deferred MCP failures (openclaw#118363) fix(macos): keep setup activation within app checks test(setup): type provider kind fixture fix(setup): complete prepared model activation fix(protocol): regenerate Swift wizard models fix(ollama): activate the model selected during setup fix(setup): preserve the prepared model handoff
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
OpenAI-compatible tool-call IDs are limited to OpenClaw's existing 40 UTF-16
code-unit policy. A raw
slice(0, 40)could split a valid surrogate pair,leaving a lone high surrogate in both the assistant tool-call ID and its paired
tool-result ID.
Fix
Use the existing
truncateUtf16Safenormalization helper at the current@openclaw/aiowner boundary. The pipe-separated ID branch already sanitizesto ASCII before slicing and is unchanged.
This is a maintainer rewrite of the contributor's original fix after the owner
moved from
src/agentsintopackages/ai. Contributor authorship is preservedon the commit.
User Impact
tool_calls[].idand matching tool-resulttool_call_idremain identical.Evidence
Exact head:
49d715bfafa2545abfa367fb74a7495eb766a45aThe owner-local regression was also repeated three times and passed each run.
After the final rebase, the exact-head owner suite passed again: 1 file, 2 tests.
Autoreview reported no findings with 0.99 confidence. Formatting and
git diff --checkare clean.The local changed gate passed formatting, lint, dependency, dead-code, and
other classified lanes. Its typecheck stopped on an unrelated unchanged
packages/terminal-core/src/ansi.tsshared-install mismatch; exact-head CI isthe dependency-resolved typecheck proof.
Exact-head OpenAI SDK loopback proof
A temporary untracked proof called production
streamOpenAICompletionsthroughOpenAI SDK 6.49.0 and captured the actual JSON posted to a local loopback
/v1/chat/completionsendpoint. It used cross-model replay so the productiontranscript normalization path processed a 41-code-unit tool-call ID whose
40th code unit was a lone high surrogate under the old raw slice.
The proof passed three bounded repeats; a maintainer independently reran it once:
The proof exercised the real SDK request path without a paid provider call,
credential, private endpoint, or tracked proof-only file. The temporary file was
deleted after verification and the exact PR head remains unchanged.
Real Behavior Proof
The regression test drives the production message converter with an assistant
tool call and paired tool result whose valid surrogate pair crosses the
40-code-unit boundary. The SDK loopback proof additionally captures the actual
outbound request JSON and proves the repaired assistant ID and paired
tool-result ID are identical, equal the expected 39-character safe prefix, and
contain no orphan surrogate.