Repository navigation
fix(knowledge): keep display truncation surrogate-safe - #187423
Conversation
Raw UTF-16 slices can leave a lone high surrogate when a title, label, or message is cut at a contract boundary mid-emoji. Route the remaining knowledge display truncations through truncateUtf16Safe, matching the remember-title residual already fixed in openclaw#186986. Co-Authored-By: Claude Code <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Co-Authored-By: Claude Code <[email protected]>
|
Codex review: needs maintainer review before merge. What this changesThis PR uses the existing surrogate-safe truncation helper for Knowledge titles, labels, and diagnostic messages. Example: A session activity title contains 199 A characters followed by 😀.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open for merge: this is a focused Unicode rendering repair, with no actionable findings and green current-head gates. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherKnowledge reads stored records and store diagnostics, bounds their display text, and returns it to session panels, maintenance views, relink results, and prompt context. flowchart LR
A[Knowledge records and diagnostics] --> B[Knowledge output owners]
B --> C[Existing surrogate safe helper]
C --> D[Bounded display text]
D --> E[Gateway session actions]
E --> F[Control UI session panel]
D --> G[Prompt context and tool results]
Technical reviewBest possible solution: Merge the focused helper substitutions and boundary regressions while preserving existing limits, stored records, and authorization behavior. Do we have a high-confidence way to reproduce the issue? Source establishes the reachable split-pair boundary, and supplied real-Gateway before/after logs demonstrate it through the session-action RPC; this read-only review executed no target code. Is this the best way to solve the issue? Reusing truncateUtf16Safe at the existing output owners is the smallest complete repair and preserves ordinary text, width budgets, and existing filtering. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c4ef53398155. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +27. Total +32 across 7 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 29, 2026, 5:53 AM ET / 09:53 UTC (Revision 3). |
…tion case TypeBox maxLength counts code points, not UTF-16 units: 199 A's plus one emoji is exactly 200 code points (201 units) and passes vault scan. The previous fixture appended " trailer" and exceeded the Envelope, so the review correctly flagged it as unreachable. The legal boundary input keeps the red-on-base / green-on-fix invariant while matching production. Co-Authored-By: Claude Code <[email protected]>
|
@clawsweeper re-review Body rewritten for readability. Proof is now on the current head:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Added real Gateway before/after evidence to the PR body (redacted terminal logs from an isolated Gateway serving
The illegal oversized fixture was already replaced with the legal Envelope boundary ( |
|
🦞👀 Re-review progress:
|
|
Ready for maintainer review when convenient.
Happy to rebase or adjust if review prefers a different shape. |
|
Merged via squash.
|
## What Problem This Solves Relevant Knowledge page content still needs an agent retrieval step unless the owner has approved an automatic summary; the standing index supplies labels and selected claim headlines, not page bodies. ## User Impact Operators can opt into per-turn, model-scored recall so useful excerpts are available when the main model starts answering. Existing approved-summary recall and the standing index remain intact. The gate is off without configuration and starts in `shadow` mode; `live` explicitly enables injection. The Decision provider receives the user message and candidate excerpts even in shadow mode. Live injection uses model-selected page text, not owner-approved summaries. Choose a provider trusted with that data, treat excerpts as evidence rather than instructions, and tune model-specific relevance thresholds in shadow before enabling live mode. No latency or tool-call reduction is claimed by the current verification. ## Why This Change Was Made Knowledge owns candidate selection, the shared Decision runtime owns execution, and the bundled `rerank` provider owns endpoint/auth behavior. The core runtime gains an optional caller-authority check so revocable Knowledge grants remain live through preparation, physical dispatch, retries and completion; this is not a plugin-only change. - Default keyword mode shortlists up to ten pages and scores them independently; two relevant pages can both pass. Model-selected label shortlisting remains optional. - The default whole-gate budget is 1,500 ms; injected context is capped at 6,000 characters and added to the current user turn, not the cached system prefix. Pointer and skip-search hints remain off by default. Unavailability, errors and timeouts omit the optional injection. - Rerank supports the common `documents` API and a guarded `texts` retry for TEI. Every document must have one score in `[0,1]`; raw logits are rejected, not rescaled or automatically passed through a sigmoid. Keyless local endpoints do not receive the synthetic auth marker. - Defaults came from the author's private GTE-reranker benchmark. They are not calibrated probabilities or a newly reproduced full-agent benchmark. The latest integration preserves contributor ancestry, retains main's Knowledge recommended prompts and first-install defaults, and regenerates configuration fingerprints rather than choosing either conflicted checksum. ## Evidence Current head: `157b7b2b43cc0e35d30c9ce896806f3f2e8d5d93`, integrating main `349859e09efc56b5191ee6e45aaed1655ea5d1ae`. Tested candidate tree: `f4fa4e603c25d540272c1ca714dad808ed4caefa`. - **79 tests in all eight selected files pass**, across three repository-planned Vitest shards in 129.61 seconds. This includes the six feature files plus current-main retrieval and remember interactions. Coverage includes independent relevance scoring, excerpt budgets, keyless/keyed/TEI transport, Decision-picker advertisement and real hook → Decision runtime → recording HTTP authority boundaries. - Ungranted audiences send nothing. Revocation before dispatch, before the TEI retry and before publication stops further egress/publication as appropriate. These tests use real production components and synthetic vault/HTTP fixtures, not a live provider or full Gateway run. - **Test audit:** removed three mocked cases superseded by that stronger boundary proof: **71 LF removed**. Calibration, protocol, picker and authority controls remain. The justified feature allocation is **1,070 LF**, down from 1,141; the refreshed-base test-line ratchet passes with 29 LF slack, without raising the shared scalar. - Full typecheck, config documentation and the main-relative line-cap guard pass on the refreshed composition. Formatting, plugin boundaries, import cycles, dead-export scan and Knip production/all-export checks also passed on the earlier `9d8bbfbbaf1`-based candidate, with the integration delta qualified below. - Complete local **autoreview / Codex GPT-6.1 Sol, P0–P2** found no actionable findings in one full pass with the required source context on the earlier feature candidate `eabae1322b4cd170becacd2644cea4f09c9e67ce`. After the main refresh, supplied TypeScript review context is unchanged except upstream Boolean-default metadata in `stores-config.ts`; the eligibility definition and dependency manifests are unchanged. The affected tests and full typecheck were rerun. The earlier review is not relabelled as a review of an identical new tree, human approval or executed test proof. - The fresh main checkpoint composed cleanly before publication. [Published-head CI](https://github.com/openclaw/openclaw/pull/188057/checks) is running and remains a separate landing gate. <details> <summary>Preserved failures and verification limits</summary> The unchanged original head `1e1b6766ac6` failed three local Decision-picker assertions; two authority cases passed and the remaining planner groups were not reached. All three assertions pass on the current main composition with its frozen dependencies, without weakening them. The original failure is retained; no specific root-cause repair is claimed. The broad local quality run on the earlier `9d8bbfbbaf1`-based candidate found global max-lines/Solid lint diagnostics and release-changelog thanks-attribution failures in unchanged main files. Reported lint files and the changelog record/checker were blob-compared with that pinned main base: 24 equal blobs, no differences and no changed-file lint diagnostics. The full-tree unused-file guard also reported `src/node-host/node-worker-prepared-workspace.process.test-support.ts`; its file, checker and Knip inputs matched that main base. These outcomes remain recorded rather than deleting another owner's fixture or editing release-owned notes. The later integration reran the affected tests, full typecheck and config/line-cap/test-budget guards, not every repository-wide lint scan. Hosted rerank APIs, a real model-through-Gateway flow, large-vault performance, and full-agent latency/tool-call savings were not verified. UTF-16-safe excerpt/injection clipping is deferred; this PR does not claim that #187423 covers its new cut sites. </details> ## Worked on by - @VACInc - @jalehman ## Work sessions - [Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/52582bc6-0ebb-42ab-a638-fc3adc18b606) Co-authored-by: jalehman <[email protected]> Co-authored-by: VACInc <[email protected]>
* fix(knowledge): keep display truncation surrogate-safe Raw UTF-16 slices can leave a lone high surrogate when a title, label, or message is cut at a contract boundary mid-emoji. Route the remaining knowledge display truncations through truncateUtf16Safe, matching the remember-title residual already fixed in openclaw#186986. * ci: retrigger checks after PR body section fix * test(knowledge): use Envelope-valid boundary title in activity truncation case TypeBox maxLength counts code points, not UTF-16 units: 199 A's plus one emoji is exactly 200 code points (201 units) and passes vault scan. The previous fixture appended " trailer" and exceeded the Envelope, so the review correctly flagged it as unreachable. The legal boundary input keeps the red-on-base / green-on-fix invariant while matching production.
## What Problem This Solves Relevant Knowledge page content still needs an agent retrieval step unless the owner has approved an automatic summary; the standing index supplies labels and selected claim headlines, not page bodies. ## User Impact Operators can opt into per-turn, model-scored recall so useful excerpts are available when the main model starts answering. Existing approved-summary recall and the standing index remain intact. The gate is off without configuration and starts in `shadow` mode; `live` explicitly enables injection. The Decision provider receives the user message and candidate excerpts even in shadow mode. Live injection uses model-selected page text, not owner-approved summaries. Choose a provider trusted with that data, treat excerpts as evidence rather than instructions, and tune model-specific relevance thresholds in shadow before enabling live mode. No latency or tool-call reduction is claimed by the current verification. ## Why This Change Was Made Knowledge owns candidate selection, the shared Decision runtime owns execution, and the bundled `rerank` provider owns endpoint/auth behavior. The core runtime gains an optional caller-authority check so revocable Knowledge grants remain live through preparation, physical dispatch, retries and completion; this is not a plugin-only change. - Default keyword mode shortlists up to ten pages and scores them independently; two relevant pages can both pass. Model-selected label shortlisting remains optional. - The default whole-gate budget is 1,500 ms; injected context is capped at 6,000 characters and added to the current user turn, not the cached system prefix. Pointer and skip-search hints remain off by default. Unavailability, errors and timeouts omit the optional injection. - Rerank supports the common `documents` API and a guarded `texts` retry for TEI. Every document must have one score in `[0,1]`; raw logits are rejected, not rescaled or automatically passed through a sigmoid. Keyless local endpoints do not receive the synthetic auth marker. - Defaults came from the author's private GTE-reranker benchmark. They are not calibrated probabilities or a newly reproduced full-agent benchmark. The latest integration preserves contributor ancestry, retains main's Knowledge recommended prompts and first-install defaults, and regenerates configuration fingerprints rather than choosing either conflicted checksum. ## Evidence Current head: `157b7b2b43cc0e35d30c9ce896806f3f2e8d5d93`, integrating main `d3ab186ab42a88343390860753fdb24cc98ae3a7`. Tested candidate tree: `f4fa4e603c25d540272c1ca714dad808ed4caefa`. - **79 tests in all eight selected files pass**, across three repository-planned Vitest shards in 129.61 seconds. This includes the six feature files plus current-main retrieval and remember interactions. Coverage includes independent relevance scoring, excerpt budgets, keyless/keyed/TEI transport, Decision-picker advertisement and real hook → Decision runtime → recording HTTP authority boundaries. - Ungranted audiences send nothing. Revocation before dispatch, before the TEI retry and before publication stops further egress/publication as appropriate. These tests use real production components and synthetic vault/HTTP fixtures, not a live provider or full Gateway run. - **Test audit:** removed three mocked cases superseded by that stronger boundary proof: **71 LF removed**. Calibration, protocol, picker and authority controls remain. The justified feature allocation is **1,070 LF**, down from 1,141; the refreshed-base test-line ratchet passes with 29 LF slack, without raising the shared scalar. - Full typecheck, config documentation and the main-relative line-cap guard pass on the refreshed composition. Formatting, plugin boundaries, import cycles, dead-export scan and Knip production/all-export checks also passed on the earlier `63c3f8bda7d`-based candidate, with the integration delta qualified below. - Complete local **autoreview / Codex GPT-6.1 Sol, P0–P2** found no actionable findings in one full pass with the required source context on the earlier feature candidate `eabae1322b4cd170becacd2644cea4f09c9e67ce`. After the main refresh, supplied TypeScript review context is unchanged except upstream Boolean-default metadata in `stores-config.ts`; the eligibility definition and dependency manifests are unchanged. The affected tests and full typecheck were rerun. The earlier review is not relabelled as a review of an identical new tree, human approval or executed test proof. - The fresh main checkpoint composed cleanly before publication. [Published-head CI](https://github.com/openclaw/openclaw/pull/188057/checks) is running and remains a separate landing gate. <details> <summary>Preserved failures and verification limits</summary> The unchanged original head `1e1b6766ac6` failed three local Decision-picker assertions; two authority cases passed and the remaining planner groups were not reached. All three assertions pass on the current main composition with its frozen dependencies, without weakening them. The original failure is retained; no specific root-cause repair is claimed. The broad local quality run on the earlier `63c3f8bda7d`-based candidate found global max-lines/Solid lint diagnostics and release-changelog thanks-attribution failures in unchanged main files. Reported lint files and the changelog record/checker were blob-compared with that pinned main base: 24 equal blobs, no differences and no changed-file lint diagnostics. The full-tree unused-file guard also reported `src/node-host/node-worker-prepared-workspace.process.test-support.ts`; its file, checker and Knip inputs matched that main base. These outcomes remain recorded rather than deleting another owner's fixture or editing release-owned notes. The later integration reran the affected tests, full typecheck and config/line-cap/test-budget guards, not every repository-wide lint scan. Hosted rerank APIs, a real model-through-Gateway flow, large-vault performance, and full-agent latency/tool-call savings were not verified. UTF-16-safe excerpt/injection clipping is deferred; this PR does not claim that openclaw#187423 covers its new cut sites. </details> ## Worked on by - @VACInc - @jalehman ## Work sessions - [Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/52582bc6-0ebb-42ab-a638-fc3adc18b606) Co-authored-by: jalehman <[email protected]> Co-authored-by: VACInc <[email protected]>
What Problem This Solves
Knowledge display truncations still use raw UTF-16
slice, so a cut at a contract boundary can leave a lone high surrogate in titles, labels, and messages when an emoji straddles the limit. This is the residual sibling of the remember-title fix in #186986.Affected paths:
promptLabelin the memory index (max - 1+ ellipsis)text(200))text(200))maxLength: 160) and failure messagesnotReadymessages (text(300))User Impact
Knowledge panel labels, session activity titles, relink examples, and maintenance vault labels no longer show a replacement character when the stored string is cut mid-emoji. Session activity titles are user-visible in the Control UI session panel.
Why This Change Was Made
Route those display truncations through the plugin SDK helper
truncateUtf16Safe, matching the existing pattern inremember.ts/ #186986.Evidence
Envelope boundary is reachable
TypeBox
maxLengthcounts code points, not UTF-16 units. Verified with the repo's TypeBox:maxLength: 200So
199 A's + emojiis an Envelope-valid production title. A hardslice(0, 200)leaves a lone high surrogate at unit 200.Real Gateway before/after (redacted terminal logs)
Seeded a real Knowledge store with the Envelope-valid boundary title, started an isolated Gateway with bundled knowledge, then called the same RPC the Control UI session panel uses:
Redacted
PR187423_GATEWAY_PROOFreports from that real Gateway process:Interpretation:
D83D(lone high surrogateU+D83Dfrom the split emoji) →isWellFormed=false.As →isWellFormed=true.Unit / jsdom support
sessionActivityunit test (committed) is red on base / green with the fix for the same boundary input. A jsdom Control UI session-panel proof also shows base199 A's + U+FFFDvs candidate199 A's.Focused tests:
extensions/knowledge/src/memory-index.test.tsextensions/knowledge/src/session-activity.test.tsRelated: #186986