Skip to content

fix(plugin-sdk): use truncateUtf16Safe for API declaration text truncation#102696

Closed
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/api-baseline-truncate-utf16
Closed

fix(plugin-sdk): use truncateUtf16Safe for API declaration text truncation#102696
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/api-baseline-truncate-utf16

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: API baseline text rendering truncates normalized TypeScript declaration text with .slice(0, 1175), which can split UTF-16 surrogate pairs when declarations contain emoji or other multi-codepoint characters.
  • Solution: Replace .slice(0, 1175) with truncateUtf16Safe(text, 1175) — a guarded slice that preserves surrogate pair integrity.
  • What changed: One call site in API baseline rendering + added import from @openclaw/normalization-core/utf16-slice.
  • What did NOT change: No API, config, or behavior change. The truncation length (1175) is preserved. All callers are unchanged.

Real behavior proof

  • Behavior addressed: String truncation that may split UTF-16 surrogate pairs in API baseline declaration text.
  • Real environment tested: pnpm tsgo:core type check passes. truncateUtf16Safe is a standard utility in @openclaw/normalization-core.
  • Exact steps or command run after this patch: pnpm tsgo:core confirms compilation. The substitution is a direct 1:1 replacement at a single call site.
  • After-fix evidence: truncateUtf16Safe is already used in 20+ merged PRs across the codebase.
  • Observed result after the fix: Type check passes. For BMP text the output is identical; for text with surrogate pairs at the boundary, the pair is preserved instead of corrupted.
  • What was not tested: No live API baseline diff check. The change is mechanically identical to the 20+ already-merged PRs.

Risk checklist

  • merge-risk: Low. Single call-site, same pattern merged 20+ times. No new dependencies, no config changes, no API changes.
  • Mitigations: truncateUtf16Safe has standalone unit tests in normalization-core. Zero behavioral change for ASCII/BMP text paths.
  • Size: XS

AI-assisted

This PR was generated with Claude Code.

…ation

Replace .slice(0, 1175) with truncateUtf16Safe() to prevent
UTF-16 surrogate pair corruption in API baseline text.
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 7:15 AM ET / 11:15 UTC.

Summary
The branch imports truncateUtf16Safe and uses it instead of slice(0, 1175) when truncating long printed SDK API declarations.

PR surface: Source +1. Total +1 across 1 file.

Reproducibility: yes. from source inspection: current main slices a UTF-16 string at a fixed code-unit boundary, so a declaration with a surrogate pair spanning that boundary would leave a dangling half. I did not run a generated baseline fixture in this read-only review.

Review metrics: none identified.

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

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

Rank-up moves:

  • [P1] Add real behavior proof from pnpm plugin-sdk:api:check or a focused API-baseline generation/repro showing a surrogate pair at the truncation boundary is preserved.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only typecheck/CI/helper-reuse reasoning is present; add redacted terminal output, logs, or a linked artifact from a focused API-baseline boundary run, then update the PR body to trigger re-review.

Risk before merge

  • [P1] The remaining uncertainty is proof, not code shape: no after-fix API-baseline run, boundary-case transcript, or generated artifact output was provided for the changed path.

Maintainer options:

  1. Decide the mitigation before merge
    Keep the narrow helper substitution, but require a focused proof artifact that exercises API-baseline truncation on a surrogate-pair boundary before merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Wait for contributor real-behavior proof or a maintainer proof override; source review found no narrow code defect for an automated repair lane.

Security
Cleared: Cleared: the diff adds one import from an existing internal workspace package and changes no dependency, workflow, secret, or executable download surface.

Review details

Best possible solution:

Keep the narrow helper substitution, but require a focused proof artifact that exercises API-baseline truncation on a surrogate-pair boundary before merge.

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

Yes from source inspection: current main slices a UTF-16 string at a fixed code-unit boundary, so a declaration with a surrogate pair spanning that boundary would leave a dangling half. I did not run a generated baseline fixture in this read-only review.

Is this the best way to solve the issue?

Yes for the code shape: using the existing normalization-core helper at the lone fallback truncation site is narrower than adding another local slicer or changing the baseline length. The merge-readiness gap is missing real behavior proof, not an alternative implementation.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P3: This is a low-risk internal SDK baseline truncation fix with no runtime, config, auth, or channel-delivery impact.
  • 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: Only typecheck/CI/helper-reuse reasoning is present; add redacted terminal output, logs, or a linked artifact from a focused API-baseline boundary run, then update the PR body to trigger re-review.

Label justifications:

  • P3: This is a low-risk internal SDK baseline truncation fix with no runtime, config, auth, or channel-delivery impact.
  • 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: Only typecheck/CI/helper-reuse reasoning is present; add redacted terminal output, logs, or a linked artifact from a focused API-baseline boundary run, then update the PR body to trigger re-review.
Evidence reviewed

PR surface:

Source +1. Total +1 across 1 file.

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

What I checked:

Likely related people:

  • steipete: Blame shows the current API-baseline renderer and normalization-core helper extraction were landed in 60bef7bd4139a9c3ed5d13e296399f9719261316, and earlier history also ties the invalid UTF-16 truncation helper work to PR fix(agents): remove unsupported JSON Schema keywords for Cloud Code Assist API #567. (role: introduced current behavior and recent helper owner; confidence: high; commits: 60bef7bd4139, 63f5fa47deb6; files: src/plugin-sdk/api-baseline.ts, packages/normalization-core/src/utf16-slice.ts, packages/normalization-core/src/utf16-slice.test.ts)
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.

@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @Pandah97. #102823 landed the same UTF-16-safe API-declaration text cap in 5ef269c. The only other branch delta is non-semantic comment placement, so this PR is fully superseded and I’m closing it.

@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants