Skip to content

fix(imessage): strip U+FFFD garbage chars from echo text key normalization#2075

Open
BingqingLyu wants to merge 3 commits into
mainfrom
fork-pr-62191-fix-imessage-echo-loop-self-chat
Open

fix(imessage): strip U+FFFD garbage chars from echo text key normalization#2075
BingqingLyu wants to merge 3 commits into
mainfrom
fork-pr-62191-fix-imessage-echo-loop-self-chat

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 28, 2026

Copy link
Copy Markdown
Owner

Summary

U+FFFD replacement characters and C0/C1 control characters injected by imsg when extracting text from NSAttributedString (attributedBody column) break echo cache text-key matching, causing duplicate message delivery.

The echo cache stores clean outbound text, but the reflected inbound copy carries garbage character prefixes — normalizeEchoTextKey() only strips \r\n, so the keys never match and the echo slips through as a new inbound message.

Fix: Strip [\ufffd\ufffe\uffff\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]+ before comparison in normalizeEchoTextKey().

Previously included fixes (now upstream)

The original PR included two additional fixes that have since been merged independently by the OpenClaw team (openclaw#61619, openclaw#63868, openclaw#63980, openclaw#63989, openclaw#64000):

  • TTL 4s → 30s — shipped in 2026.4.10 (SENT_MESSAGE_TEXT_TTL_MS = 30e3)
  • destination_caller_id self-chat detection — shipped in 2026.4.10 with isSelfChat + isAmbiguousSelfThread

This PR now contains only the remaining unmerged fix.

Changes

  • extensions/imessage/src/monitor/echo-cache.ts: Strip U+FFFD/control chars in normalizeEchoTextKey

Related Issues

Fixes openclaw#61312, openclaw#61821

Test Plan

  • Confirmed echo cache miss on messages with U+FFFD prefixes (unpatched)
  • Applied patch to compiled dist — garbage-prefixed echoes now correctly matched and suppressed
  • Clean text (no U+FFFD) still matches normally — no regression

cryptoassest and others added 3 commits April 11, 2026 10:33
…ation

imsg extracts message text from the SQLite attributedBody column via
NSAttributedString, which injects U+FFFD replacement characters and C0/C1
control characters around rich-text spans. The echo cache stores clean
outbound text, but the reflected copy carries these garbage characters,
defeating text-based deduplication. See: openclaw#61312, openclaw#61821.

Fixes openclaw#61312, openclaw#61821
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iMessage echo loop in self-chat: U+FFFD from attributedBody breaks echo cache text matching

2 participants