Skip to content

fix(auto-reply): keep memory flush error truncation surrogate-safe#102713

Closed
zw-xysk wants to merge 1 commit into
openclaw:mainfrom
zw-xysk:fix/agent-runner-memory-safe
Closed

fix(auto-reply): keep memory flush error truncation surrogate-safe#102713
zw-xysk wants to merge 1 commit into
openclaw:mainfrom
zw-xysk:fix/agent-runner-memory-safe

Conversation

@zw-xysk

@zw-xysk zw-xysk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Two functions in agent-runner-memory.ts truncate error text using .slice(0, N):

  • formatMemoryFlushVisibleError() (600-char limit)
  • truncateMemoryFlushErrorMessage() (200-char limit)

When the truncation boundary falls inside a UTF-16 surrogate pair (emoji, CJK extended), the resulting error text contains a dangling surrogate that can corrupt session state diagnostics.

Changes

src/auto-reply/reply/agent-runner-memory.ts (+2, −2):

  • Import truncateUtf16Safe from @openclaw/normalization-core/utf16-slice
  • Both truncation points: .slice(0, N)truncateUtf16Safe(text, N)

Evidence

Unit tests (47/47 passed):

 Test Files  1 passed (1)
      Tests  47 passed (47)

Real behavior proof (platinum):

[+0.001s] ═══ agent-runner-memory proof ═══
[+0.001s] visibleText: OLD=✗ NEW=✓
[+0.001s] errorMsg:   OLD=✗ NEW=✓
[+0.001s] RESULT: PASS (platinum)

Review

  • Manually reviewed and verified
  • AI-assisted: Yes

formatMemoryFlushVisibleError and truncateMemoryFlushErrorMessage use
.slice(0, N) to truncate error text. When the truncation boundary falls
inside a UTF-16 surrogate pair, the resulting text contains a dangling
surrogate that can corrupt session state diagnostics.

Replace .slice(0, N) with truncateUtf16Safe(text, N).
@zw-xysk

zw-xysk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 9, 2026, 7:28 AM ET / 11:28 UTC.

Summary
The branch imports truncateUtf16Safe and replaces the 600-character visible memory-flush error truncation and 200-character stored/logged error truncation with the shared UTF-16-safe helper.

PR surface: Source +1. Total +1 across 1 file.

Reproducibility: yes. Current main uses raw UTF-16 slice at the 199- and 599-code-unit truncation boundaries, and the PR’s live-output proof shows OLD fails and NEW passes for both affected paths.

Review metrics: none identified.

Root-cause cluster
Relationship: canonical
Canonical: #102713
Summary: This PR and #102685 target the same two memory-flush error truncation lines; this PR is the better canonical candidate because it has positive live-output proof.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
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

  • [P2] No repair lane is needed because this PR already contains the narrow fix; the remaining maintainer action is normal review or landing of this canonical branch while retiring the duplicate.

Security
Cleared: The diff only imports an existing internal normalization helper and changes two string truncation calls; no dependency, workflow, credential, or supply-chain surface changed.

Review details

Best possible solution:

Land one proof-positive narrow PR for this memory-flush truncation fix, then close the duplicate open PR so maintainers do not carry two equivalent branches.

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

Yes. Current main uses raw UTF-16 slice at the 199- and 599-code-unit truncation boundaries, and the PR’s live-output proof shows OLD fails and NEW passes for both affected paths.

Is this the best way to solve the issue?

Yes. Replacing only the two implicated slices with the existing truncateUtf16Safe helper is the narrowest maintainable fix; the duplicate PR is less ready because it is still marked as needing proof.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2806195e1127.

Label changes

Label changes:

  • add P2: This is a normal limited-blast-radius bug fix for malformed Unicode in memory-flush diagnostic text, not an urgent runtime outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live output comparing old and new behavior for both affected truncation paths, and the Real behavior proof workflow succeeded on the PR head SHA.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output comparing old and new behavior for both affected truncation paths, and the Real behavior proof workflow succeeded on the PR head SHA.

Label justifications:

  • P2: This is a normal limited-blast-radius bug fix for malformed Unicode in memory-flush diagnostic text, not an urgent runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output comparing old and new behavior for both affected truncation paths, and the Real behavior proof workflow succeeded on the PR head SHA.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live output comparing old and new behavior for both affected truncation paths, and the Real behavior proof workflow succeeded on the PR head SHA.
Evidence reviewed

PR surface:

Source +1. Total +1 across 1 file.

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

What I checked:

Likely related people:

  • steipete: Blame shows the current raw-slice error formatting in the latest main snapshot, and recent merged memory-flush exhaustion work touched the same failure-handling path. (role: recent area contributor and merger; confidence: high; commits: fc5a4defaf62, dd972b8bf775, 062f88e3e3af; files: src/auto-reply/reply/agent-runner-memory.ts, packages/normalization-core/src/utf16-slice.ts)
  • TurboTheTurtle: Authored the merged PR that moved memory flush before preflight compaction, which owns the affected helper path. (role: feature contributor; confidence: medium; commits: e24d4426fe8c; files: src/auto-reply/reply/agent-runner-memory.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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix. I’m closing this as a duplicate of the earlier #102685, which changes the same two memory-flush error surfaces without relocating the module documentation into the import block. We’ll keep that cleaner branch as the canonical review.

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

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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