Repository navigation
fix(knowledge): truncate memory index labels without splitting surrogate pairs - #186996
wangmiao0668000666 wants to merge 2 commits into
Conversation
…ate pairs The standing Knowledge index clips long record labels with String.slice at TITLE_MAX/CLAIM_MAX. A clip that lands inside an emoji leaves a lone UTF-16 high surrogate in the rendered index, which the memory hook pins and injects into the system prompt for the whole session; JSON/prompt serialization then turns it into U+FFFD. Use the existing truncateUtf16Safe helper so the clip stops one unit before the cap, as other Knowledge projections already do.
|
🦞👀 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. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR uses the existing Unicode-safe truncation helper when clipping Knowledge index labels. Example: A page title contains 78 lowercase p characters followed by 🎯 review.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: current main still splits surrogate pairs in Knowledge index labels, and this PR provides a focused repair with no identified correctness defect. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherKnowledge renders stored record labels into a bounded memory index, which its prompt hook pins and appends to authorized sessions' system context. flowchart LR
A[Stored Knowledge records] --> B[Storage memory index]
B --> C[Label rendering]
C --> D[Unicode safe truncation]
D --> E[Pinned session index]
E --> F[System prompt context]
Technical reviewBest possible solution: Keep the focused helper substitution and regression at the existing Knowledge index owner. Do we have a high-confidence way to reproduce the issue? Source confirms that 78 p characters followed by 🎯 review produce a split pair at the 80-unit page-label cap; the contributor supplies a matching real-storage red/green trace, which was not independently executed during this read-only review. Is this the best way to solve the issue? The patch is the smallest complete rendering repair: it preserves clipping limits and filtering while reusing the established surrogate-safe helper. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against db6efe4ecc2b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests +27. Total +28 across 2 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 28, 2026, 4:04 PM ET / 20:04 UTC. |
NO-REPRO: shipped Gateway → OpenClaw/OpenAI standing-index pathContributor head Both revisions installed/built in secretless After one corrected capture retry, main twice and candidate twice completed normally. Each run used 13 real Knowledge tool calls, verified all eight original stored titles/bodies, then completed a separate prompt-probe turn. Both revisions supplied identical, well-formed labels to the provider: All 32 final observed labels were well-formed, with no U+FFFD in a UTF-8 round trip. This did not reproduce corruption in the provider-bound prompt, including both real clipping budgets (page80, claim110). The 60-unit lookup-handle path prefilters values above60 and therefore does not perform a truncating call. Why the storage-renderer regression and this shipped path differ: the source renderer on main does use raw slice, but the existing model transport sanitizes unpaired surrogates before sending prompt text. The first harness attempt incorrectly asserted that the provider must receive malformed main text. It observed the already-safe page label and generated its own HTTP500 assertion failure; that is not product failure evidence. The corrected capture completed all four runs and retained exact provider requests, full standing-index context, original record reads, wire frames and final outcomes. Evidence retained under Scope of this NO-REPRO: the shipped OpenClaw harness with OpenAI Responses transport. It does not establish behavior for native CLI runtimes or other unexercised consumers, nor deny that raw pre-transport index text can contain a surrogate. I am not treating the storage-renderer-only difference as a demonstrated user-visible fix on this path; the maintainer can decide whether the raw-context invariant independently warrants the repair or a different shipped consumer needs proof. |
…dex cases Fold the regression into the prompt-label clip case and the byte-stable hook case instead of adding a standalone test, so the PR's test-line delta stays non-positive. The hook case now saves the label whose 80-unit clip falls between the surrogate halves and asserts the serialized hook result contains the clipped label with no lone surrogate.
|
Closing after the NO-REPRO on the previous head, which matches the source: The branch keeps the fold into the two existing cases ( |
What Problem This Solves
The standing Knowledge index clips long record labels with raw UTF-16
String.prototype.sliceinmemory-index.ts:promptLabelowns prompt-facing Knowledge labels (TITLE_MAX = 80,CLAIM_MAX = 110,HANDLE_MAX = 60), all below the 200-unit record-title contract, so valid labels really are clipped; when the clip falls between an astral character's halves the label ends with a lone high surrogate.memory-index-hook.ts(readMemoryIndex->pinIndex->appendSystemContext: text) pins this index and appends it to the system prompt every turn, so the lone surrogate enters the prompt bytes and becomes U+FFFD at serialization for the session.User Impact
A page or claim label whose 79/109/59-unit clip lands inside an emoji or other astral character is rendered to the model corrupted: its last visible character becomes U+FFFD while the trailing ellipsis still appears, so the model cannot match the label back to
knowledge_lookupinput. The pinned index repeats this every turn until compaction or a new session.Why This Change Was Made
truncateUtf16Safeis already the truncation owner across this plugin and keeps the width contract: the clip may stop one UTF-16 unit before the cap and the ellipsis still fits insidemax. ASCII and in-cap labels are byte-identical to before. Behavior-preserving for well-formed input, behavior-completing for split pairs (Precedent: #186707).Evidence
Pinned base:
7c87e3a892dffa9280b9618dc01792c955ad20d1; candidate head:f991ffeb00a342fc6082702fbbb6008c98cbed07.The regression folds into two existing cases, adding no test lines (delta 0, as the test-lines ratchet requires):
memory-index-hook.test.ts(existing byte-stable index case) saves its second label as${"p".repeat(78)}<U+1F3AF> review(87 units, valid under the 200-unit contract) and asserts the serialized hook result carries the clipped label. Real path:memoryFixturestore, realnode:sqlite, realbefore_prompt_buildhook ->readMemoryIndex->buildMemoryIndex. No mocks.BEFORE (base tree, de-hardlinked so link counts are 1; original
memory-index.tsmd5909910d99edef67babadf437d69909bf):The base JSON shows the split literally: the clipped label is 79 units ending in U+D83C, the high half of U+1F3AF, so the serialized result contains
\ud83cbefore the ellipsis and is not well-formed.AFTER (candidate tree, same command, same tree contents otherwise):
Candidate: the serialized hook result has
- note:+ 78 xp+ U+2026 (pair dropped, not half-kept) and no\ud8escape;promptLabelreturnsxxxxxxxx+ ellipsis, notxxxxxxxx+ U+D83C + ellipsis.Controls still green in the same cases: the in-cap
Brightpath analysis playbookand renamed labels are unchanged, and instruction-like or markup labels still returnnull.Merge Danger
maxcontract, markup/instruction rejection, and empty-labelnullreturn untouched.openpr_files-1028.tsvmap touchesmemory-index.ts,memory-index-hook.ts, ormemory-index.test.ts; fix(cron): include untruncated agent output in webhook delivery #186366 only editsdocs/plugins/knowledge/*.md.