Skip to content

fix(memory): preserve Unicode in QMD search snippets - #103996

Merged
steipete merged 1 commit into
mainfrom
codex/fix-qmd-utf16-truncation
Jul 11, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-qmd-utf16-truncation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where QMD memory results could contain malformed Unicode when an emoji crossed a configured snippet or prompt-injection budget. The corruption could surface in memory_search, prompts, and CLI output, including after source citations were appended.

Why This Change Was Made

All three QMD-owned prefix limits now use the existing surrogate-safe text helper: the per-result snippet limit, the manager's aggregate injected-character budget, and the post-citation aggregate budget. Both aggregate clamps remain because the CLI consumes manager results directly while the memory tool appends citations afterward.

User Impact

QMD memory snippets remain valid Unicode at configured size boundaries. Existing result sizes, ordering, source metadata, citations, and ASCII behavior are unchanged.

Evidence

  • Regression input @@ -1,1\nabc😀tail at a 12-unit boundary now yields exactly @@ -1,1\nabc for both the per-result and aggregate manager paths instead of ending in a lone high surrogate.
  • Post-citation input abc😀tail at a 4-unit budget now yields exactly abc through the public memory-search tool path.
  • Blacksmith Testbox-through-Crabbox tbx_01kx76v3wggn4091s5shmsdan3: 176 focused tests passed across qmd-manager.test.ts and tools.citations.test.ts.
  • The same Testbox passed path-scoped check:changed, including extension production/test typechecks, lint, dependency/package guards, database-first guard, and runtime import-cycle checks.
  • Targeted oxfmt, git diff --check, and fresh Codex autoreview passed; autoreview reported no actionable findings with 0.98 correctness confidence.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: S maintainer Maintainer-authored PR labels Jul 10, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 10, 2026, 8:05 PM ET / July 11, 2026, 00:05 UTC.

Summary
The PR replaces three QMD UTF-16-unsafe prefix slices with the shared surrogate-safe truncator and adds manager and public-tool boundary regression tests.

PR surface: Source +2, Tests +79. Total +81 across 4 files.

Reproducibility: yes. Current main directly slices UTF-16 code units at all three affected QMD limits, and the supplied emoji cases deterministically exercise the malformed boundary.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/memory-core/src/memory/qmd-manager.test.ts, unknown-data-model-change: extensions/memory-core/src/memory/qmd-manager.test.ts, vector/embedding metadata: extensions/memory-core/src/memory/qmd-manager.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • none.

Next step before merge

  • [P1] No automated repair is needed; route the clean patch through its protected maintainer review and exact-head merge checks.

Security
Cleared: The diff is limited to local string truncation calls and tests, with no dependency, permission, secret, persistence, download, workflow, or executable supply-chain change.

Review details

Best possible solution:

Land the shared-helper replacement at all three QMD-owned character limits while retaining the manager and public memory-tool regression coverage.

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

Yes. Current main directly slices UTF-16 code units at all three affected QMD limits, and the supplied emoji cases deterministically exercise the malformed boundary.

Is this the best way to solve the issue?

Yes. Reusing the established UTF-16-safe helper at each owner-specific clamp fixes the root cause without changing budgets, ordering, metadata, configuration, or introducing a parallel truncation abstraction.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 63859f73e6ae.

Label changes

Label justifications:

  • P2: Malformed Unicode can reach memory search, prompts, and CLI output at exact configured boundaries, but the affected surface is limited to memory-core truncation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The live maintainer label makes this maintainer-handled PR exempt from the external-contributor real-behavior proof gate; its exact-output tests and Testbox run remain useful supplemental evidence.
Evidence reviewed

PR surface:

Source +2, Tests +79. Total +81 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 5 3 +2
Tests 2 81 2 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 86 5 +81

What I checked:

Likely related people:

  • steipete: Merged commits refactored the memory plugin host boundary and extracted the memory host SDK across the affected manager, citation, and SDK export surfaces. (role: feature owner and recent boundary refactor contributor; confidence: high; commits: b96fccadb95a, bd6c7969ea9c; files: extensions/memory-core/src/memory/qmd-manager.ts, extensions/memory-core/src/tools.citations.ts, packages/memory-host-sdk/src/engine-foundation.ts)
  • miorbnli: Recently hardened mcporter result parsing and error handling in the same QMD manager and its focused tests. (role: recent QMD area contributor; confidence: medium; commits: 7d939b645645; files: extensions/memory-core/src/memory/qmd-manager.ts, extensions/memory-core/src/memory/qmd-manager.test.ts)
  • potterdigital: Recently changed QMD search-mode and reranker behavior in the same manager with targeted regression coverage. (role: recent QMD result-processing contributor; confidence: medium; commits: cd31cbcd17df; files: extensions/memory-core/src/memory/qmd-manager.ts, extensions/memory-core/src/memory/qmd-manager.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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-10T23:58:09.072Z sha ac7290928f61c64e86ec6e11935a9b543f977084 :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the codex/fix-qmd-utf16-truncation branch from ac72909 to 9213d93 Compare July 11, 2026 00:19
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at exact head 9213d93c854cee1ac9897f6baedfc3c6e1509d94.

  • All three QMD-owned prefix limits use the existing surrogate-safe helper: per-result snippets, the manager aggregate budget, and the post-citation aggregate budget.
  • Exact public-path regressions prove @@ -1,1\nabc😀tail becomes @@ -1,1\nabc at both manager boundaries and abc😀tail becomes abc after citation decoration at a 4-unit budget.
  • Blacksmith Testbox-through-Crabbox tbx_01kx76v3wggn4091s5shmsdan3: 176 focused manager/tool tests passed, followed by path-scoped check:changed with extension production/test types, lint, guards, and runtime import-cycle checks.
  • The unrelated current-main mock failure was repaired separately in test(crestodian): preserve model input exports in mocks #103999 (920b29bdd5d8bec68f83948b8cce22fe372ca997); this PR was rebased afterward.
  • Exact-head hosted CI run 29132375212 completed successfully with every selected job green.
  • Targeted oxfmt, git diff --check, and fresh final-head Codex autoreview passed; autoreview reported no actionable findings with 0.98 correctness confidence.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 103996 passed.

No config, ordering, citation policy, result metadata, docs, or changelog contract changes.

@steipete
steipete merged commit b7d6291 into main Jul 11, 2026
98 checks passed
@steipete
steipete deleted the codex/fix-qmd-utf16-truncation branch July 11, 2026 00:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant