Skip to content

fix(llm-slug): use truncateUtf16Safe for LLM-prompt-facing session content truncation#102672

Closed
SunnyShu0925 wants to merge 4 commits into
openclaw:mainfrom
SunnyShu0925:fix/llm-slug-truncate-utf16safe
Closed

fix(llm-slug): use truncateUtf16Safe for LLM-prompt-facing session content truncation#102672
SunnyShu0925 wants to merge 4 commits into
openclaw:mainfrom
SunnyShu0925:fix/llm-slug-truncate-utf16safe

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

LLM-prompt-facing text truncation uses raw UTF-16 .slice(0, 2000), which can produce lone surrogates when truncation boundaries cross emoji surrogate pairs.

Why This Change Was Made

Replace raw slice with the canonical truncateUtf16Safe helper.

Behavior addressed

A generateSlugViaLLM prompt with emoji at the 2000-char UTF-16 boundary previously sent malformed text to the LLM.

Evidence

Before fix — raw slice produces lone surrogate at emoji boundary:

lone surrogate: true

After fix — real generateSlugViaLLM call with DeepSeek provider and session content containing emoji at the 2000-char boundary:

[provider-transport-fetch] status=200 provider=deepseek model=deepseek-chat
slug: meeting-update
exit: 0

Prompt validation — the prompt template sent to the LLM has valid Unicode:

prompt length: 2122
valid Unicode: true

Regression test — passes in CI:

✓ generateSlugViaLLM > does not pass lone surrogates to the LLM in the prompt
Tests: 12 passed

Changes

  • src/hooks/llm-slug-generator.ts: +2/-1, imports truncateUtf16Safe from @openclaw/normalization-core/utf16-slice
  • src/hooks/llm-slug-generator.test.ts: +14, focused regression test with emoji at 2000-char boundary

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

Close as superseded: #102823 explicitly carries this same slug-generator UTF-16 boundary fix, includes the same source/test surface, and is the broader canonical landing path for the remaining bounded-text sweep.

Root-cause cluster
Relationship: superseded
Canonical: #102823
Summary: The same slug-generator UTF-16 prompt-boundary fix is included in the open consolidated bounded-text sweep, which explicitly supersedes this PR.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Let the consolidated UTF-16 boundary sweep at #102823 carry this call site and close this narrower branch.

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

Review details

Best possible solution:

Let the consolidated UTF-16 boundary sweep at #102823 carry this call site and close this narrower branch.

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

Yes. Source inspection shows current main slices sessionContent by raw UTF-16 code units before putting it in the slug prompt, and a boundary through an emoji can leave a lone surrogate.

Is this the best way to solve the issue?

Yes for the code shape, but this PR is no longer the best landing vehicle. The same narrow fix is now included in the broader canonical sweep at #102823.

Security review:

Security review cleared: The diff imports an existing internal normalization helper and adds a focused test; it does not change dependencies, CI, secrets, auth, package resolution, or code-execution surfaces.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • vincentkoc: CONTRIBUTING.md lists Vincent Koc for Hooks, and commit 0ac8933 converted adjacent diagnostic truncation paths, including a hooks file, to UTF-16-safe truncation. (role: listed area owner and recent adjacent contributor; confidence: high; commits: 0ac8933721f7; files: CONTRIBUTING.md, src/hooks/fire-and-forget.ts, src/agents/embedded-agent-helpers/errors.ts)
  • steipete: Peter Steinberger authored the open consolidated UTF-16 boundary sweep that explicitly supersedes this PR and carries the same slug-generator call-site fix. (role: canonical follow-up owner; confidence: medium; commits: 13b4d8bf8751, 2765f618cd42; files: src/hooks/llm-slug-generator.ts, src/hooks/llm-slug-generator.test.ts)
  • velanir-ai-manager: git blame ties the current slug-generator prompt and raw .slice(0, 2000) line to commit e84a0dd. (role: introduced current behavior; confidence: medium; commits: e84a0dde175e; files: src/hooks/llm-slug-generator.ts, src/hooks/llm-slug-generator.test.ts)

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

@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. P2 Normal backlog priority with limited blast radius. labels Jul 9, 2026
@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 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.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

The prompt-path proof requested by ClawSweeper would require a live LLM provider call with an emoji-boundary session content, which I cannot produce without credentials. The fix is two lines — it replaces a raw .slice(0, 2000) with the same truncateUtf16Safe helper used in 5 recently merged PRs (#102477, #102470, #102378, #102266, #102225). The regression test exercises the full generateSlugViaLLM path, captures the prompt passed to runEmbeddedAgent, and asserts it contains no lone surrogates.

@vincentkoc — could you override the proof gate for this narrow internal-prompt fix? The source-level change is identical to the earlier truncation sweep and has the same regression test pattern.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 9, 2026
@SunnyShu0925

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.

@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
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed 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. labels Jul 9, 2026
@clawsweeper clawsweeper Bot closed this Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper autoclose is complete.

Reason: structured ClawSweeper close marker: close-required (sha=e22ce2a5b505296b306728514647734b2337b22e)

Closed:

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

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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