Skip to content

fix(active-memory): use truncateUtf16Safe for log value truncation#102551

Merged
steipete merged 3 commits into
openclaw:mainfrom
lsr911:fix/utf16-active-memory
Jul 9, 2026
Merged

fix(active-memory): use truncateUtf16Safe for log value truncation#102551
steipete merged 3 commits into
openclaw:mainfrom
lsr911:fix/utf16-active-memory

Conversation

@lsr911

@lsr911 lsr911 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Active Memory sanitizes session identifiers, model references, and failure messages into bounded single-line log values. The existing 300-code-unit cap used slice, so an astral character crossing the boundary could leave malformed UTF-16 in those logs.

Why This Change Was Made

Replace the final fixed-width slice with the existing shared truncateUtf16Safe utility. New local logic is unnecessary: the utility preserves the established cap while dropping only a high surrogate that would otherwise be split.

The follow-up regression improves the existing public hook-level log-limit test. It supplies a real session key with an emoji straddling the 300-code-unit boundary and verifies the complete session field plus the absence of unpaired surrogates in the emitted start log.

User Impact

Active Memory diagnostics remain single-line and bounded, but no longer contain malformed Unicode at the length limit. No config, recall, cache, or API behavior changes.

Evidence

  • node ../../node_modules/vitest/vitest.mjs run --config test/vitest/vitest.extension-active-memory.config.ts extensions/active-memory/index.test.ts -t 'caps active-memory log field lengths' — 1 passed, 156 skipped.
  • oxfmt completed for the changed test.
  • git diff --check passed.
  • Relevant callers and sibling log rendering were inspected; every toSingleLineLogValue consumer benefits from the same canonical boundary.
  • Exact tested head: 94fb898bd4d1aca94648d717687973bc745ec0ac.

Risk

Low. One internal log renderer now uses the shared truncation invariant; text not splitting a surrogate pair is unchanged.

AI-assisted

This PR was generated with Claude Code and improved/reviewed by a maintainer agent.

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 6:05 AM ET / 10:05 UTC.

Summary
This PR replaces active-memory log-value raw slicing with truncateUtf16Safe and updates the existing log length test to cover surrogate-pair boundaries.

PR surface: Source 0, Tests +2. Total +2 across 2 files.

Reproducibility: yes. Current main uses raw UTF-16 code-unit slicing for active-memory log values, and a session key with an emoji high surrogate at the 300-code-unit boundary would leave a dangling surrogate before the ellipsis; I did not run a live active-memory process in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦞 diamond lobster
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Add redacted terminal output, runtime logs, copied live output, or a validation transcript showing active-memory log truncation no longer emits a split surrogate.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Mock-only: the PR body lists Vitest, formatting, and diff checks but no redacted runtime log, terminal output, or live transcript showing after-fix active-memory logging; the contributor should add proof and update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] Contributor real-behavior proof is still missing: the PR body evidence is test and formatting output, not a redacted runtime log, terminal transcript, or live output showing the after-fix active-memory logging path.

Maintainer options:

  1. Decide the mitigation before merge
    Land this narrow log-value helper substitution after redacted real-behavior proof is added; keep the separate search-query truncation discussion on a better-proven related PR.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] The remaining blocker is contributor real-behavior proof and ordinary maintainer review; ClawSweeper should not open a repair PR for missing evidence that must come from a real run.

Security
Cleared: The diff only changes local string truncation and a focused test, with no dependency, workflow, secret, package, or code-execution surface change.

Review details

Best possible solution:

Land this narrow log-value helper substitution after redacted real-behavior proof is added; keep the separate search-query truncation discussion on a better-proven related PR.

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

Yes. Current main uses raw UTF-16 code-unit slicing for active-memory log values, and a session key with an emoji high surrogate at the 300-code-unit boundary would leave a dangling surrogate before the ellipsis; I did not run a live active-memory process in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing UTF-16-safe helper at the local log truncation point, plus the new hook-level regression, is the narrow maintainable fix for log values; the broader search-query slice should remain separate.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4be6fa7413af.

Label changes

Label justifications:

  • P3: This is a very small diagnostic log correctness fix with limited blast radius and no evidence of a broken core workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Mock-only: the PR body lists Vitest, formatting, and diff checks but no redacted runtime log, terminal output, or live transcript showing after-fix active-memory logging; the contributor should add proof and update the PR body to trigger re-review, or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source 0, Tests +2. Total +2 across 2 files.

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

What I checked:

  • Repository policy applied: Root AGENTS.md and the scoped extensions policy were read; the review applied the plugin-boundary and deep PR review requirements. (AGENTS.md:1, 4be6fa7413af)
  • Current main still has raw log slicing: toSingleLineLogValue still uses singleLine.slice(0, MAX_LOG_VALUE_CHARS) before appending the ellipsis, so a split surrogate at the cap remains source-reproducible on current main. (extensions/active-memory/index.ts:1437, 4be6fa7413af)
  • Helper contract matches the intended fix: truncateUtf16Safe clamps and floors the limit, then delegates to sliceUtf16Safe, which avoids returning dangling surrogate halves at slice edges. (packages/normalization-core/src/utf16-slice.ts:44, 4be6fa7413af)
  • Affected callers are log-only: The helper is used for active-memory error, start, provider/model, and failure log fields; the PR does not change recall, cache, config, or API behavior. (extensions/active-memory/index.ts:3127, 4be6fa7413af)
  • PR head adds focused regression coverage: The live PR diff swaps the production log truncation call and changes the existing log-limit test so an emoji straddles the 300-code-unit boundary and the emitted line is checked for unpaired surrogates. (extensions/active-memory/index.test.ts:4815, 94fb898bd4d1)
  • Real behavior proof remains absent: The PR body lists focused Vitest, formatting, and diff checks, while the live status: 📣 needs proof label remains and the latest Real behavior proof check failed; tests are useful but not contributor real-behavior proof. (94fb898bd4d1)

Likely related people:

  • steipete: Peter Steinberger authored or merged the consolidated UTF-16 truncation work in fix: keep bounded text truncation UTF-16 safe #101654 and added this PR's focused active-memory regression commit. (role: recent reviewer and UTF-16 truncation owner; confidence: high; commits: a9582a1bb62a, 94fb898bd4d1; files: extensions/active-memory/index.ts, extensions/active-memory/index.test.ts, packages/normalization-core/src/utf16-slice.ts)
  • Takhoffman: Tak Hoffman appears repeatedly in active-memory feature and follow-up history, including custom recall tools and several co-authored active-memory behavior fixes. (role: active-memory feature owner; confidence: high; commits: 2f2602508511, f256eeba431b, 16906780fd2c; files: extensions/active-memory/index.ts, extensions/active-memory/index.test.ts)
  • vincentkoc: Vincent Koc merged and narrowed related active-memory UTF-16-safe truncation work in fix(core): keep backend truncation UTF-16 safe #100244 and has multiple recent active-memory commits. (role: recent active-memory maintainer and merger; confidence: medium; commits: 66081c09ee50, 530658dc29cd, 59b5058cdb40; files: extensions/active-memory/index.ts, extensions/active-memory/index.test.ts)
  • lsr911: This contributor is also a co-author on the merged consolidated UTF-16 truncation PR, so their relevance is not only from opening this PR. (role: related UTF-16 truncation contributor; confidence: medium; commits: a9582a1bb62a, b9ca1b043c23; files: extensions/active-memory/index.ts, packages/normalization-core/src/utf16-slice.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-09T08:52:57.919Z sha b800454 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Land-ready verification at exact head 94fb898bd4d1aca94648d717687973bc745ec0ac:

  • Improved the existing hook-level log-limit regression so a real session key places an emoji across Active Memory's 300-code-unit boundary; the test asserts the exact emitted session field and no dangling surrogate.
  • Focused Active Memory Vitest — 1 passed, 156 skipped.
  • oxfmt and git diff --check passed.
  • Fresh autoreview: clean, 0.99 confidence; no accepted/actionable findings.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 102551 passed exact-head hosted CI/Testbox gates.
  • Whole-surface review covered every toSingleLineLogValue caller. Whitespace normalization, log-injection protection, the existing limit, and ellipsis are unchanged.

No docs, config, recall, cache, API, or dependency changes. Ready to merge.

@steipete
steipete merged commit e39e628 into openclaw:main Jul 9, 2026
102 of 105 checks passed
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants