Skip to content

fix(knowledge): truncate chronicle summary without splitting surrogate pairs - #186707

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/knowledge-chronicle-summary-surrogate-250
Oct 28, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/knowledge-chronicle-summary-surrogate-250

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: Knowledge timeline summaries contain a lone surrogate when an emoji or other astral character straddles the 1000-unit summary boundary.

User Impact

Timeline summaries remain valid UTF-16 instead of producing a replacement character during UTF-8 encoding. For "x".repeat(999) + "😀", the preview stops at 999 x characters rather than keeping half an emoji. ASCII and short-text output remain unchanged. The complete stored body is preserved.

Why This Change Was Made

Keep SunnyShu0925's focused owner repair: replace the bare slice(0, 1000) in chronicle.ts with the existing SDK truncateUtf16Safe helper. The bound remains at most 1000 UTF-16 units; storage, indexing, dates, metadata, pagination and authority are unchanged.

The added maintainer commit folds the regression into the existing Unicode response-budget/pagination fixture without dropping its original assertions, removes the duplicated standalone test and documents timeline preview behavior. Whole-PR production delta +1, test-line delta 0. No new parser, SDK surface or compatibility path was introduced.

Evidence

Built Gateway before/after terminal evidence.

Secretless Linux Docker, Node 24.22.1, complete baseline and candidate builds. A real Gateway agent turn used a deterministic local Responses fixture and the shipped dispatch_action route to invoke registered knowledge_save_page, knowledge_record and knowledge_timeline tools. No paid provider or direct service replay.

  • Main eb82abff…, twice: a published 1001-unit body (999 x + 😀) returns a 1000-unit summary ending in lone high surrogate D83D; isWellFormed() is false and normal UTF-8 encoding yields U+FFFD.
  • Candidate production, twice: returns exactly 999 x, valid UTF-16 and no replacement character. Production code is identical between compiled contributor head f55c0319… and current repair head 7d95f7e9…; only tests/docs changed afterward.
  • Controls, twice each on both builds: 1001 ASCII characters truncate to 1000; an emoji entirely within the bound remains intact; short emoji text is unchanged. All complete stored bodies remain unchanged and valid.
  • Two paginated timeline passes per build returned all four published IDs once, retaining recorded_at/instant metadata and stable snapshots. Both agent turns completed normally, with 12 real Knowledge tool calls each.
  • The final consolidated regression fails on main at summary.isWellFormed(); the candidate's complete chronicle suite passes 12 tests. Targeted formatting and Oxlint pass with zero warnings/errors.

Direct HTTP tool-invoke setup attempts lacked a host-issued Knowledge memory audience and are not counted as proof. The successful evidence uses the normal authorized agent-tool path. No browser screenshot or real-provider inference claim is made.

Merge danger: two-way door. Reverting restores the broken preview boundary without a migration or stored-data change. Blast radius is Knowledge's shared temporal-result summary renderer; unchanged ordinary text and pagination are controlled above.

…e pairs

chronicle.ts sliced record.body at 1000 UTF-16 units with a bare slice(),
which can split an astral-plane character (emoji) in half and emit a lone
surrogate / U+FFFD in the timeline summary. Use truncateUtf16Safe (the same
UTF-16-safe truncation already applied to record.body in claim-card.ts,
vault.ts, evidence-files.ts, and inspection.ts) so summaries never carry a
dangling surrogate. Regression test covers an astral char on the boundary.
@clawsweeper

clawsweeper Bot commented Oct 28, 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. 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. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves surrogate pairs when truncating Knowledge timeline summaries at 1,000 UTF-16 units.

Example: A Knowledge record contains 999 x characters followed by 😀.

  • Before: The summary contains 999 x characters and a lone high surrogate, which becomes � during UTF-8 encoding.
  • After: The summary contains exactly 999 x characters, and the complete stored body remains unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal, useful repair with shipped-entry-point before/after evidence and a consolidated regression; broad CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): obviyus's linked terminal trace exercises registered Knowledge tools through real built-Gateway agent turns in secretless Linux Docker, records the malformed baseline and valid candidate boundary summaries, and checks ordinary text, complete bodies, and pagination; production code is unchanged between the exercised candidate and reviewed 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: An emoji crossing a timeline summary boundary becomes a malformed surrogate and can display as a replacement character.
Reason: A narrow renderer correction restores valid preview text using an established helper without changing storage, configuration, permissions, or public APIs.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete Unicode truncation bug still present on current main; the focused patch has no actionable findings and CI remains pending.

Priority: P2
Reviewed head: 7d95f7e99f7e41906e08bd9b2861e68b6469b3ca

Before merge

None.

Findings

None.

Agent review details

How this fits together

Knowledge temporal tools pass authorized records through a shared chronicle renderer, which returns bounded summaries with dates, source references, and pagination metadata.

flowchart TD
  A[Knowledge temporal tools] --> B[Authorized storage read]
  B --> C[Scoped record snapshot]
  C --> D[Shared chronicle renderer]
  D --> E[UTF16 safe summary truncation]
  E --> F[Bounded paginated tool response]
Loading

Technical review

Best possible solution:

Use the existing UTF-16-safe SDK helper in the shared chronicle renderer, as this PR does.

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

Current-main source deterministically splits the supplied boundary emoji, and obviyus's built-Gateway trace records that failure and its correction; no target code was executed during this review.

Is this the best way to solve the issue?

The patch is the smallest complete repair: reuse the established truncation owner, retain the existing cap, and extend an existing behavioral regression without adding machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Knowledge chronicle summary cap keeps the original intent (65ad180: The bundled import carries a compact temporal-result renderer with a 1,000-unit summary cap; it records no reason to split surrogate pairs, and earlier standalone introduction remains unestablished.)
  • Knowledge Unicode preview contract keeps the original intent (2724b2c: The merged preview repair deliberately preserves surrogate pairs through the existing SDK helper while retaining caps and complete source data.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit 65ad180 adds extensions/knowledge/src/chronicle.ts:34 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/chronicle.ts)

PR surface

Source +1, Tests 0, Docs 0. Total +1 across 3 files. Added test files: 0.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The bug corrupts bounded timeline previews for astral characters at the truncation boundary while preserving complete stored records.
  • 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-28T11:31:26.807Z sha f55c031 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-28T11:50:59.008Z sha f55c031 :: needs maintainer review before merge. :: none

Reviewed October 28, 2026, 8:07 AM ET / 12:07 UTC (Revision 3).

@clawsweeper

clawsweeper Bot commented Oct 28, 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-environment 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 28, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 28, 2026
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Built Gateway / registered Knowledge tool proof

Current-main baseline: eb82abff66950b74a4da99903b7c2e5e6ee60082
Candidate production source: f55c0319d1e90d099234b919c4cd4b371ecd1e61, unchanged in repair head 7d95f7e99f7e41906e08bd9b2861e68b6469b3ca (the added commit only consolidates tests and updates documentation).

Both complete builds succeeded in secretless Linux Docker on Node 24.22.1. Each built Gateway used task-owned profile/config/state and token authentication, with binary-resolved config/database paths checked before startup. A deterministic local Responses SSE fixture drove a real Gateway chat.send agent turn, invoking the shipped dispatch_action tool and the real registered Knowledge tools. No paid model, parser replay, direct service call, storage mock or source-file seeding was used.

Each turn performed 12 registered Knowledge calls:

  1. Four knowledge_save_page publications, each returning state: published and a record ID.
  2. Four knowledge_record reads, asserting the complete stored body was unchanged and valid UTF-16.
  3. Four knowledge_timeline calls: two complete passes, each paginated with limit: 2, timeField: recorded_at and a stable snapshot. Every pass returned all four IDs exactly once.

Observed terminal capture:

fixture                        main pass1/pass2             candidate pass1/pass2
999 x + emoji (1001 units)      1000 / 1000 units            999 / 999 units
  final code unit              D83D / D83D                  0078 / 0078
  isWellFormed                 false / false                true / true
  UTF-8 encoding yields U+FFFD  true / true                  false / false

998 y + emoji (1000 units)      1000 units, valid both       1000 units, valid both
1001 ASCII a                   1000 units, valid both       1000 units, valid both
Short emoji text               15 units, unchanged both     15 units, unchanged both

per pass: 4 records, 4 unique IDs, recorded_at/instant metadata retained
per build: 12 completed Knowledge tool calls; agent turn completed normally

The boundary summary on main contains an actual lone high surrogate \ud83d, not merely a display mismatch. The candidate returns exactly 999 x characters. This prevents corruption in normal UTF-8 encoding; no browser-rendering or screenshot claim is made.

Direct HTTP /tools/invoke setup attempts were not counted as proof: Knowledge correctly lacked a host-issued memory audience on that surface. The successful comparison used the normal authorized agent-tool path instead. Gateways and fixture servers were stopped after the runs.

Regression and test budget

The contributor's regression is consolidated into the existing full-response-budget/pagination test, using 499 × 🌱 + x + 😀 so the same 1000-unit boundary splits the last pair on main. All original response-budget, source association and 35-row uniqueness/count assertions remain.

main + final regression: FAIL at summary.isWellFormed(), expected false to be truthy
candidate chronicle suite: 12 passed
oxfmt: all matched files use correct format
oxlint: 0 warnings, 0 errors
whole-PR test-line delta: 0

The owner-level production repair remains the contributor's existing truncateUtf16Safe call; no stored-body, index, schema, permission, pagination or metadata behavior was changed.

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus
obviyus merged commit b0966db into openclaw:main Oct 28, 2026
111 of 112 checks passed
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Landed in b0966db. Thanks @SunnyShu0925. Knowledge timeline summaries no longer end in a broken emoji.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks!

github-actions Bot pushed a commit to SharonZ92901/openclaw that referenced this pull request Oct 28, 2026
…e pairs (#186707)

fix(knowledge): keep timeline summaries from splitting surrogate pairs

knowledge_timeline cut each entry's summary at a fixed UTF-16 length. When an emoji or other astral character sat at the cut, the summary ended in a lone surrogate. Summaries now go through the existing truncateUtf16Safe owner, as claim cards and excerpts already do, and the docs list timeline summaries with them.

Evidence: built Gateway agent turns with a deterministic local provider, calling the registered Knowledge publish, read and timeline tools (12 calls per build). Main returned a 1000-unit summary ending in a lone D83D (twice); with this change it returned 999 units of valid UTF-16 (twice). ASCII, short emoji and fully in-bound emoji controls behave the same on both refs. Stored bodies are unchanged, and pagination returned every entry once. Details: openclaw/openclaw#186707 (comment).

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 28, 2026
#186986)

fix(knowledge): keep remembered claim titles from splitting surrogate pairs

knowledge_remember derived a stored claim title by cutting the text at 199 UTF-16 units, so an emoji or other astral character at the cut left a lone surrogate in the stored title. The title now goes through the existing truncateUtf16Safe owner, as timeline summaries do since #186707. Full claim bodies are unchanged.

Evidence: real built Gateway agent turns calling knowledge_remember and knowledge_record. On main the stored title ended in a lone high surrogate at the 199-unit boundary (not well-formed, shown as a replacement character) (twice); with this change it stored 198 units plus an ellipsis, well-formed (twice), and every full claim body was kept. ASCII, intact-pair and short-Unicode controls behave the same on both refs. Details: #186986 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…e pairs (openclaw#186707)

fix(knowledge): keep timeline summaries from splitting surrogate pairs

knowledge_timeline cut each entry's summary at a fixed UTF-16 length. When an emoji or other astral character sat at the cut, the summary ended in a lone surrogate. Summaries now go through the existing truncateUtf16Safe owner, as claim cards and excerpts already do, and the docs list timeline summaries with them.

Evidence: built Gateway agent turns with a deterministic local provider, calling the registered Knowledge publish, read and timeline tools (12 calls per build). Main returned a 1000-unit summary ending in a lone D83D (twice); with this change it returned 999 units of valid UTF-16 (twice). ASCII, short emoji and fully in-bound emoji controls behave the same on both refs. Stored bodies are unchanged, and pagination returned every entry once. Details: openclaw#186707 (comment).

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
openclaw#186986)

fix(knowledge): keep remembered claim titles from splitting surrogate pairs

knowledge_remember derived a stored claim title by cutting the text at 199 UTF-16 units, so an emoji or other astral character at the cut left a lone surrogate in the stored title. The title now goes through the existing truncateUtf16Safe owner, as timeline summaries do since openclaw#186707. Full claim bodies are unchanged.

Evidence: real built Gateway agent turns calling knowledge_remember and knowledge_record. On main the stored title ended in a lone high surrogate at the 199-unit boundary (not well-formed, shown as a replacement character) (twice); with this change it stored 198 units plus an ellipsis, well-formed (twice), and every full claim body was kept. ASCII, intact-pair and short-Unicode controls behave the same on both refs. Details: openclaw#186986 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: Ayaan Zaidi <[email protected]>
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: XS 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