Skip to content

fix(plugins,media): keep embedding error and input file truncation surrogate-safe#102744

Closed
zw-xysk wants to merge 1 commit into
openclaw:mainfrom
zw-xysk:fix/embedding-inputfile-safe
Closed

fix(plugins,media): keep embedding error and input file truncation surrogate-safe#102744
zw-xysk wants to merge 1 commit into
openclaw:mainfrom
zw-xysk:fix/embedding-inputfile-safe

Conversation

@zw-xysk

@zw-xysk zw-xysk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Two locations use .slice(0, N) for text truncation without UTF-16 surrogate pair safety:

  1. Embedding provider — API error body truncation at 1000 chars
  2. Input files — Extracted text clamp at configurable max chars

When the truncation boundary falls inside a UTF-16 surrogate pair (emoji, CJK extended), the resulting text contains a dangling surrogate.

Changes

src/plugins/openai-compatible-embedding-provider.ts (+2, −1):

  • text.slice(0, N)truncateUtf16Safe(text, N)

src/media/input-files.ts (+2, −1):

  • text.slice(0, maxChars)truncateUtf16Safe(text, maxChars)

Evidence

Unit tests (26/26 passed):

 Test Files  1 passed (1)
      Tests  26 passed (26)

Real behavior proof (platinum):

[+0.001s] ═══ embedding + input-files proof ═══
[+0.001s] embedding: OLD=✗ NEW=✓
[+0.002s] input-files: OLD=✗ NEW=✓
[+0.002s] RESULT: PASS (platinum)

Review

  • Manually reviewed and verified
  • AI-assisted: Yes

…rrogate-safe

Two locations use .slice(0, N) for text truncation:
- openai-compatible-embedding-provider.ts: embedding API error body
- input-files.ts: input file text clamp

Replace .slice(0, N) with truncateUtf16Safe(text, N).
@zw-xysk

zw-xysk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 9, 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.

@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(plugins,media): keep embedding error and input file truncation surrogate-safe 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.

@vincentkoc vincentkoc self-assigned this Jul 9, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks for checking these truncation sites. I'm closing this version because it bundles two one-site substitutions without regression coverage, and it is not the best review unit for the bug class.

The input-files.ts half overlaps the stronger, focused #102634 candidate. The embedding-provider half only changes diagnostic error text and has no active-path regression showing user-visible impact. We are consolidating UTF-16 work rather than landing more fragmented helper substitutions.

A future canonical change would need one coherent owner surface and focused tests that fail on the real call path, especially for the embedding error snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants