Skip to content

fix(skills): bound evaluator text without splitting surrogate pairs - #117673

Merged
steipete merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/skill-evaluation-utf16-bounds
Aug 2, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/skill-evaluation-utf16-bounds

Conversation

@zenglingbiao

Copy link
Copy Markdown
Contributor

Summary

Bound evaluator-produced text in the Skill Workshop evaluation pipeline with truncateUtf16Safe instead of UTF-16 code-unit slice, so emoji/CJK characters straddling a cap are no longer persisted to the proposal store as a lone surrogate (tofu).

What Problem This Solves

src/skills/workshop/service-evaluation.ts normalizes third-party evaluator output before persisting it. Four user-visible text paths are bounded by raw code-unit slicing:

  • boundedRequired (service-evaluation.ts:355-357) — used for the evaluator error message (2000) and attribution ids.
  • boundedOptional (service-evaluation.ts:360-361) — used for summary (8000), decisionReason (2000), evaluatorVersion, mode, and finding file.
  • normalizeMetrics (service-evaluation.ts:350) — string metric values (value.slice(0, 4_000)).

Any character outside the Basic Multilingual Plane (emoji, CJK ext-B) occupies two UTF-16 code units. When such a character straddles a cap, slice keeps only the leading high surrogate, and that lone surrogate is written into the durable proposal store (SQLite) — surfacing later as tofu/invalid glyphs wherever the evaluation summary, decision reason, error, or metric is displayed.

Code evidence: service-evaluation.ts:350, :356, :360 bounded evaluator-controlled text with slice(0, n) on UTF-16 code units.

Root Cause

  • Introduced by commit 14940edf15f ("feat(skills): add Skill Workshop lifecycle hooks", 2026-07-29, feat(skills): add Skill Workshop lifecycle hooks #115606), which added the evaluation normalization helpers with code-unit slicing.
  • Violated invariant: "bound to N characters" only holds for BMP text when implemented as slice(0, N); astral characters occupy two UTF-16 units, so the cut can persist half a character.
  • Trigger: an evaluator plugin returns a summary/decisionReason/error/metric whose character at the cap boundary is an emoji (e.g. 7999 ASCII chars + 🙂 at the 8000-unit summary cap) — a normal occurrence for LLM-backed evaluators that decorate output with emoji.

Why This Fix

  • Use truncateUtf16Safe from @openclaw/normalization-core/utf16-slice — the repo's established convention for this bug class (src/skills/lifecycle/install-output.ts, src/skills/loading/workspace.ts, ACP control plane, and fix(terminal): keep Unicode cron columns aligned #117062 all use it).
  • Drop-in replacement with the same length contract (length <= n unchanged; oversized input truncated to n units) except a dangling surrogate at the cut is dropped instead of persisted.
  • Alternative considered: rejecting over-cap text containing surrogates — changes the evaluator contract and can turn benign emoji output into hard failures; clean truncation preserves the existing non-fatal bounding behavior.

User Impact

  • Affected operations: Skill Workshop proposal evaluations whose evaluator output is clipped at a boundary falling inside an emoji — the persisted summary / decision reason / error / metric values end with a broken glyph in the workshop UI, event log, and any downstream consumer of the store.
  • Before: store holds e.g. "ssss…\uD83D" — a dangling high surrogate.
  • After: store holds the same text clipped cleanly before the emoji.

Evidence

  • Before: on main, a real evaluator hook registered through the real global hook runner returns text with 🙂 straddling each cap; the record re-read from the real store ends summary/decisionReason/metrics.note with U+D83D (lone high surrogate) → FAIL.
  • After: on this branch, the same run persists all three fields with clean tails (U+0073/U+0072/U+006D) → PASS.

Real Behavior Proof

The proof registers a real skill_proposal_evaluate hook through the real initializeGlobalHookRunner (exactly the dispatch path a third-party evaluator plugin uses), then runs the real proposeCreateSkill → evaluateSkillProposal pipeline and re-reads the persisted record from the real SQLite store via inspectSkillProposal.

Before (on main)

$ node --import tsx proof.mjs
summary_units=8000 tail=U+73 U+d83d lone_surrogate=true
decisionReason_units=2000 tail=U+72 U+d83d lone_surrogate=true
metrics.note_units=4000 tail=U+6d U+d83d lone_surrogate=true
FAIL: store persists evaluator text ending in a lone UTF-16 surrogate (tofu)

After (with fix)

$ node --import tsx proof.mjs
summary_units=7999 tail=U+73 U+73 lone_surrogate=false
decisionReason_units=1999 tail=U+72 U+72 lone_surrogate=false
metrics.note_units=3999 tail=U+6d U+6d lone_surrogate=false
PASS: evaluator text bounded without splitting surrogate pairs

Tests and Validation

  • Added a regression test in src/skills/workshop/service-evaluation.test.ts: a completed outcome (summary/decisionReason/metric with 🙂 straddling the 8000/2000/4000 caps) and an error outcome (error with 🙂 straddling the 2000 cap) must persist with each emoji dropped whole. The test fails on main and passes with the fix; the other 20 tests are unchanged.
  • node scripts/run-vitest.mjs src/skills/workshop/service-evaluation.test.ts — 21/21 tests passed.
  • oxfmt --check and oxlint clean on both changed files; git diff --check clean.
  • Sibling audit: all bounded-text paths in this file funnel through the three helpers changed here (attribution ids, evaluatorVersion/mode, finding file/ruleId, metrics); no other code-unit slice remains in the evaluation normalization path. The same truncateUtf16Safe convention was applied to the beam mirror in a companion PR.

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

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 6:56 PM ET / 22:56 UTC.

ClawSweeper review

What this changes

The PR makes Skill Workshop truncate evaluator summaries, errors, metrics, and related bounded fields without splitting UTF-16 surrogate pairs, with a regression test for emoji at each relevant boundary.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for merge review: current main still truncates evaluator-controlled strings with UTF-16 code-unit slice, and the patch replaces all three normalization funnels with the repository’s established surrogate-safe helper. The branch is cleanly mergeable but behind main, with CI still in progress; no actionable correctness or security defect was found in the patch.

Priority: P2
Reviewed head: d452c87c045648aa26ad1a90cdd4f93910ba21d4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused root-cause repair with credible real-pipeline evidence and direct regression coverage; remaining work is normal exact-head CI and maintainer merge review.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body provides before/after terminal output from the real evaluator-hook-to-SQLite proposal pipeline, and the supplied checks include a successful Real behavior proof run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides before/after terminal output from the real evaluator-hook-to-SQLite proposal pipeline, and the supplied checks include a successful Real behavior proof run.
Evidence reviewed 7 items Current-main defect: Current main uses String.slice for metric values and the required and optional evaluator-text bounds. A supplementary-plane character starting at the final allowed code unit leaves a dangling high surrogate.
Persistence owner boundary: Evaluation outcomes are normalized before the evaluation is attached to the proposal record and passed to recordSkillProposalEvaluation, so repairing normalization is at the producing boundary rather than in downstream readers.
Established helper contract: truncateUtf16Safe keeps input unchanged within the limit and otherwise delegates to a slice that backs away from a surrogate-pair boundary, matching the needed bounded-text contract without adding a parallel implementation.
Findings None None.
Security None None.

How this fits together

Skill Workshop runs optional evaluator plugins against a proposed skill, normalizes their output, and stores the resulting evaluation in the proposal record and event log. Those stored results are subsequently returned to CLI, API, and UI consumers.

flowchart LR
  A[Evaluator plugin output] --> B[Skill Workshop evaluation]
  B --> C[Bounded field normalization]
  C --> D[Proposal record and event store]
  D --> E[CLI, API, and UI readers]
Loading

Before merge

  • Resolve merge risk (P1) - GitHub reports a clean merge but the branch is behind current main and several required checks remain in progress; refresh the exact merge head and require green CI before landing.
  • Complete next step (P2) - No repair lane is needed because this PR already contains the narrow implementation; wait for exact-head CI and maintainer merge review.
Agent review details

Security

None.

PR surface

Source +2, Tests +55. Total +57 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 3 +2
Tests 1 55 0 +55
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 60 3 +57

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused producer-boundary repair after the current merge head is validated, retaining truncateUtf16Safe as the single shared implementation for surrogate-safe bounded text.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land this focused producer-boundary repair after the current merge head is validated, retaining truncateUtf16Safe as the single shared implementation for surrogate-safe bounded text.

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

Yes, from source: an evaluator can return 7,999 BMP code units followed by an emoji at the 8,000-unit summary cap, and current main retains the emoji’s leading surrogate through slice. The PR body also supplies before/after real-pipeline terminal output, though this read-only review did not execute the contributor branch.

Is this the best way to solve the issue?

Yes. Reusing truncateUtf16Safe at the common normalization funnels is the narrowest maintainable fix; rejecting evaluator output or adding reader-side replacement would alter the evaluator contract or leave invalid state at its source.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded persistence/display correctness bug in an optional Skill Workshop evaluator flow, with no evidence of data loss, security impact, or broad runtime unavailability.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after terminal output from the real evaluator-hook-to-SQLite proposal pipeline, and the supplied checks include a successful Real behavior proof run.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides before/after terminal output from the real evaluator-hook-to-SQLite proposal pipeline, and the supplied checks include a successful Real behavior proof run.

Label justifications:

  • P2: This is a bounded persistence/display correctness bug in an optional Skill Workshop evaluator flow, with no evidence of data loss, security impact, or broad runtime unavailability.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides before/after terminal output from the real evaluator-hook-to-SQLite proposal pipeline, and the supplied checks include a successful Real behavior proof run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after terminal output from the real evaluator-hook-to-SQLite proposal pipeline, and the supplied checks include a successful Real behavior proof run.

Evidence

What I checked:

  • Current-main defect: Current main uses String.slice for metric values and the required and optional evaluator-text bounds. A supplementary-plane character starting at the final allowed code unit leaves a dangling high surrogate. (src/skills/workshop/service-evaluation.ts:349, eb8c22ed13f9)
  • Persistence owner boundary: Evaluation outcomes are normalized before the evaluation is attached to the proposal record and passed to recordSkillProposalEvaluation, so repairing normalization is at the producing boundary rather than in downstream readers. (src/skills/workshop/service-evaluation.ts:133, eb8c22ed13f9)
  • Established helper contract: truncateUtf16Safe keeps input unchanged within the limit and otherwise delegates to a slice that backs away from a surrogate-pair boundary, matching the needed bounded-text contract without adding a parallel implementation. (packages/normalization-core/src/utf16-slice.ts:57, eb8c22ed13f9)
  • Patch coverage: The PR applies that helper to metric strings, required fields, and optional fields, covering the shared funnels used by summaries, decision reasons, errors, attribution, finding fields, and evaluator metadata. (src/skills/workshop/service-evaluation.ts:350, d452c87c0456)
  • Regression coverage: The added test supplies emoji exactly across the summary, decision-reason, metric, and error caps through evaluateSkillProposal and asserts that each whole emoji is omitted rather than stored as a half pair. (src/skills/workshop/service-evaluation.test.ts:762, d452c87c0456)
  • Release and current-main status: The PR head is not contained by local release tags and is not on current main; the latest supplied release is v2026.7.1 at 2d2ddc43d0dcf71f31283d780f9fe9ff4cc04fe4, so this repair is not already shipped or implemented on main. (d452c87c0456)

Likely related people:

  • vincentkoc: The related merged lifecycle-hooks PR introduced the Skill Workshop evaluator lifecycle and the normalization surface this PR repairs. (role: feature introducer; confidence: high; commits: 14940edf15f6; files: src/skills/workshop/service-evaluation.ts, src/skills/workshop/service-evaluation.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch against current main if required by the merge queue, then require the still-running checks to pass on the final merge head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Maintainer verification for exact contributor head d452c87c045648aa26ad1a90cdd4f93910ba21d4:

  • Root cause: three shared Skill Workshop evaluator producer-normalization paths (boundedRequired, boundedOptional, string metrics) used raw UTF-16 slicing, affecting all 12 bounded evaluator fields before durable proposal/event writes. The fix uses the existing canonical truncateUtf16Safe helper at those ownership boundaries.
  • Independently exercised actual registered plugin evaluator → production proposal create/evaluate → isolated shared SQLite proposal and append-only event → inspect/events readback → real HTTP/model-visible output: before, boundary-straddling emoji persisted malformed escaped lone surrogates; after, all 12 fields remain well-formed. Existing per-field/aggregate byte caps, optional-field semantics, evaluator policy, SQLite schema, and event ordering are unchanged.
  • Focused production-owner regression proof: node scripts/run-vitest.mjs src/skills/workshop/service-evaluation.test.ts — 21/21 passed. Canonical helper coverage: node scripts/run-vitest.mjs packages/normalization-core/src/utf16-slice.test.ts — 21/21 passed. Fresh gpt-5.6-sol xhigh autoreview: clean, confidence 0.99. Exact-head CI 30722166225 and Workflow Sanity 30722166239 succeeded.
  • The optional bot suggestion to refresh only if required does not apply: the merge queue permits this exact green contributor head, so no unnecessary rebase.

Thanks @zenglingbiao for fixing the complete producer-owned invariant and adding focused regression coverage.

@steipete
steipete merged commit 3469225 into openclaw:main Aug 2, 2026
127 of 134 checks passed
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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: S 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.

2 participants