Skip to content

fix(knowledge): keep emoji whole at free-text caps in cards, statements and excerpts - #186083

Merged
obviyus merged 4 commits into
openclaw:mainfrom
xialonglee:fix/gap-knowledge-utf16-truncation
Oct 27, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
xialonglee:fix/gap-knowledge-utf16-truncation

Conversation

@xialonglee

@xialonglee xialonglee commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Related: #181741, #182776

What Problem This Solves

Knowledge claim cards, related statements and evidence excerpts can end with a lone UTF-16 surrogate when an existing free-text cap lands inside an emoji. The streaming evidence path can also fill the unused unit with a later newline, producing text that is no longer a source prefix.

User Impact

These bounded previews now preserve surrogate pairs and remain contiguous source prefixes. Existing caps and truncation flags remain; complete claim bodies and retained originals are unchanged.

Why This Change Was Made

openclaw/plugin-sdk/text-utility-runtime already exports truncateUtf16Safe. The changed projections consume that supported helper directly; the duplicated truncateWhole implementation is removed. No SDK source or export is changed.

Once a streaming piece is shortened, a request-local flag stops further preview accumulation. Hashing, locator verification and full-source character counting continue normally. This avoids appending later lines into the one unused UTF-16 unit.

Evidence

Independent built-Gateway before/after trace: ordinary Gateway agent turns execute the registered Knowledge tools through a deterministic local tool-calling provider. Sources are attached and claims/continuity links authored through public tools, not raw vault edits or private service calls. Actual tool results forwarded to the provider are captured.

  • Main twice: claim cards, related statements and default evidence previews end with U+D83D at 4,000 units.
  • Repaired candidate twice: those outputs are valid 3,999-unit prefixes; stored bodies remain unchanged.
  • Buffered and over-17-MiB streaming sources exercise the real inspector threshold. At the larger 20,000-unit preview cap, the intermediate contributor implementation returns a later newline only on the streaming path. Repaired buffered/streamed excerpts are identical valid 19,999-unit prefixes.
  • Full source hashes, sizes, a locator quote after the cut, and truncation flags remain verified.
  • The multiline inspector regression fails before the latch repair. Four focused files pass 24/24 after it; touched lint and formatting pass.

Existing ASCII, complete-emoji, hash, locator, pagination, lifecycle and batching coverage remains. Regression cases share existing owner fixtures rather than adding duplicate suites: the complete change has net zero test-line growth. Production is net +8 lines; the existing Knowledge tool reference documents the preview behavior.

Not Fixed Here

Short-field caps on titles, labels and diagnostic messages in other Knowledge owners are outside this repair. This preserves UTF-16 surrogate pairs; it does not introduce grapheme-cluster truncation or rewrite previously stored text.

Merge Risk

Two-way door: a revert restores the prior preview projections. No configuration, SDK API, stored-record format or schema migration changes. Blast radius is Knowledge card, related-statement and evidence-preview output.

Source-worker dependency verification

The existing Knowledge worker SDK alias table now declares the reused text-utility facade. This fixes the Bun source-mode child import without changing any SDK export. On b6c10e0e60080882e240bc534f94d063bf093dd7, the two affected child-process test files pass 18/18 on Node and 18/18 on the pinned Bun fork, and the rebuilt shipped Knowledge flow passes twice again: #186083 (comment).

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves UTF-16 surrogate pairs in Knowledge previews and prevents streaming excerpts from appending later text after truncation.

Example: A claim contains 3,999 x characters followed by 😀tail at a 4,000-unit preview cap.

  • Before: The preview contains 3,999 x characters followed by the lone surrogate U+D83D.
  • After: The preview contains exactly 3,999 x characters and remains a valid source prefix.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair with shipped-entry-point before/after evidence, preserved verification behavior, and both prior findings resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Collaborator-provided built-Gateway output exercises public Knowledge attachment, claim, annotation, listing, and record tools with boundary-crossing emoji in buffered and real-threshold streaming sources; repaired previews are valid contiguous 3,999/19,999-unit prefixes, hashes and locators remain verified, and stored bodies remain unchanged, with the shipped flow repeated on the current head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Knowledge cards, related statements, and evidence previews can end with broken emoji characters.
Reason: The change repairs bounded text projections without adding configuration, changing storage, or expanding the public SDK.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a concrete current-main preview defect with sufficient Gateway proof and no actionable findings; exact-head CI is still running.

Priority: P2
Reviewed head: b6c10e0e60080882e240bc534f94d063bf093dd7

Before merge

None.

Findings

None.

Agent review details

How this fits together

Knowledge projects authorized vault records and verified retained evidence into bounded tool responses consumed by agents and the UI.

flowchart LR
  A[Gateway tool invocation] --> B[Knowledge service]
  B --> C[Storage worker]
  C --> D[Vault records and retained evidence]
  D --> E[Card and excerpt projections]
  E --> F[Shared UTF16 truncation helper]
  F --> G[Bounded tool response]
Loading

Technical review

Best possible solution:

Merge the focused shared-helper repair once the existing checks pass.

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

Current-main source exposes the split-surrogate path, and the supplied built-Gateway trace reproduces it on pinned main; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch uses the existing truncation owner and the smallest necessary streaming latch while preserving full-file verification and existing caps.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 50911e24e57a.

Provenance checked

  • Knowledge bounded card, statement, and evidence projections keeps the original intent (65ad180: The merged bundling PR brought the existing Knowledge implementation into OpenClaw with bounded read projections; it records no requirement to split surrogate pairs.)
  • Knowledge source-worker SDK alias table keeps the original intent (65ad180: The existing table resolves SDK modules reachable from worker code; declaring the newly consumed facade follows that ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit 65ad180 adds extensions/knowledge/src/claim-card.ts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 65ad18005286; files: extensions/knowledge/src/claim-card.ts)
  • Peter Steinberger: Raw commit a4cfee8 adds extensions/knowledge/src/storage-client.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: a4cfee8af58a; files: extensions/knowledge/src/storage-client.ts)

PR surface

Source +8, Tests 0, Docs +4. Total +12 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 15 7 +8
Tests 4 52 52 0
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 71 59 +12

Review metrics

Metric Value Why it matters
Production versus test LOC Production +15/-7; tests +52/-52 Net production growth of eight lines supplies the streaming latch and SDK binding; existing fixtures absorb the regressions without net test growth.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded Knowledge preview can contain malformed Unicode; complete stored records and original evidence remain intact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-27T15:42:06.930Z sha c7961dc :: needs real behavior proof before merge. :: [P2] Stop collecting preview text after the first truncated piece | [P1] Reuse the existing SDK UTF-16 truncation helper
  • reviewed 2026-10-27T18:35:34.797Z sha dde113d :: needs maintainer review before merge. :: none

Reviewed October 27, 2026, 2:52 PM ET / 18:52 UTC (Revision 3).

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Independent built-Gateway Knowledge proof

Built pinned main eb78444932faeff3e6ab23d082e6c02dc0ddcb2b and repaired production tree dde113d530305ede26b45aefe247e431f78ff34a in isolated Node 24.22.1 Docker. Normal Gateway agent turns execute the registered Knowledge tools using a deterministic local Responses tool-calling fixture, with the host-selected memory audience. Captures observe the actual tool results forwarded back to that provider, not private service calls or seeded vault records. No real provider key, raw record edits, or SDK changes.

Each repetition attaches source files with knowledge_attach_file, creates evidence-backed claims with knowledge_create_claim, links a related statement with knowledge_annotate, then reads knowledge_records cards and knowledge_record detail/evidence. Both main and the repaired candidate run twice. Sources place 😀 at UTF-16 offset 3999; the streaming fixture also places it at offset 19999, the inspector's larger internal preview cap. The large source is over 17 MiB, exceeding the real 16 MiB buffered-inspector threshold; no threshold was changed.

Surface (both repetitions)          main                       repaired candidate
Claim card, 4000-unit cap           4000 units, ends U+D83D    3999 units, valid prefix
Related statement                  4000 units, ends U+D83D    3999 units, valid prefix
Buffered evidence, default cap     4000 units, ends U+D83D    3999 units, valid prefix
Large streamed evidence, default   4000 units, ends U+D83D    3999 units, valid prefix
Buffered evidence, 20000-unit cap  20000 units, ends U+D83D   19999 units, valid prefix
Streamed evidence, 20000-unit cap  20000 units, ends U+D83D   19999 units, same prefix
Stored claim body                  unchanged                 unchanged
Original evidence hashes/locators  verified                  verified

The intermediate contributor tree also reproduced the separate latch defect twice through these tools: its buffered 20,000-unit preview returned the valid 19,999-unit prefix, but its streaming preview appended a later newline into the unused slot (20,000 units, not a source prefix). The repaired previews are byte-for-byte equal and contiguous. The full original hash, size and a quote after the cut remain verified, and truncation flags remain true.

The existing openclaw/plugin-sdk/text-utility-runtime facade already exports truncateUtf16Safe; the repair consumes it unchanged and removes truncateWhole. Streaming preview collection now latches only text accumulation after truncation; hashing, locator validation and total counting continue.

Regression proof: the consolidated multiline streaming/buffered inspector test fails on the intermediate source, then the four focused files pass 24/24 after repair. Touched lint reports 0 errors/warnings; formatting passes, including the Knowledge tool documentation. Existing ASCII, complete-emoji, hash, locator, paging, lifecycle and batching checks remain. Tests are consolidated into existing owner cases with net zero test-line growth against the integration base, without raising a baseline. The PR's earlier missing-SDK-facade rationale has been corrected.

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Oct 27, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Fixed the attributable changed-extensions-config CI failure on b6c10e0. The new supported SDK import also needs declaring in Knowledge’s existing storage-worker SDK alias table; otherwise Bun source-mode child processes cannot resolve it. Added that one existing dependency binding, with no SDK source/export change and no test suppression. The two failed files (evidence-inspector.test.ts and git-history.test.ts) now pass 18/18 on Node and 18/18 on the exact pinned Bun fork in Linux Docker. Rebuilt the candidate and repeated the shipped Knowledge tool flow twice again: all 3999/19999-unit previews are valid contiguous prefixes, buffered/streamed excerpts match, full hashes remain verified and stored bodies are unchanged. Complete test-line delta remains zero.

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus
obviyus merged commit 2724b2c into openclaw:main Oct 27, 2026
103 of 104 checks passed
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Landed in 2724b2c. Thanks @xialonglee. Knowledge caps no longer split emoji.

@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Merged as 2724b2c. Thanks @xialonglee for finding the Knowledge Unicode boundary gaps and adding regression coverage.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…ts and excerpts (openclaw#186083)

fix(knowledge): keep emoji whole at free-text caps in cards, statements and excerpts

Knowledge free-text caps cut text by UTF-16 units without respecting surrogate pairs, so an emoji at the cap left a lone high surrogate (U+D83D) in cards, statements and excerpts. Caps now use the existing truncateUtf16Safe through its supported facade, the duplicate local helper is removed, and streaming preview accumulation is latched.

Evidence: shipped Knowledge attachment, claim, annotation, listing and record tools on a built Gateway, with emoji placed at the caps. On main the results ended in a lone U+D83D (twice); with this change they were valid 3,999 and 19,999-unit prefixes (twice). Buffered and over-17 MiB streaming excerpts agree, and stored bodies and source verification are unchanged. Details: openclaw#186083 (comment).

Thanks @xialonglee.

Co-authored-by: Ayaan Zaidi <[email protected]>
@xialonglee
xialonglee deleted the fix/gap-knowledge-utf16-truncation branch November 4, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. plugin: knowledge proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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