Summary
iMessage DM replies echo back to the agent as new inbound messages. The echo cache fails to match because:
- Text TTL too short:
SENT_MESSAGE_TEXT_TTL_MS = 4000 (4s) but echoes arrive 5-10s later
- Corrupted prefix: Echoed text has leading U+FFFD replacement characters that break exact text matching in
normalizeEchoTextKey()
Reproduction
- Agent sends a long reply (500+ chars) via iMessage DM
- Message arrives at recipient
- Within 5-30 seconds, the same message appears as a new inbound message with
is_from_me=0
- Text starts with garbled chars (
\ufffd, shown as �) followed by a truncated copy of the original
- Echo cache lookup fails → message processed as new user input → agent replies → loop
Affected versions
- v2026.3.31 (confirmed)
- v2026.4.2 (confirmed, same code path)
Root cause
normalizeEchoTextKey() in monitor-provider-*.js only strips whitespace/CR. It does not strip leading U+FFFD/U+FFFE/control chars that iMessage adds to reflected copies. Additionally, the 4s text TTL expires before most echoes arrive.
Suggested fix
- Increase
SENT_MESSAGE_TEXT_TTL_MS to 30s (matching the WhatsApp echo fix pattern)
- Strip leading replacement/control characters in
normalizeEchoTextKey():
const normalized = text.replace(/\r\n?/g, '\n').replace(/^[\ufffd\ufffe\uffff\u0000-\u001f]+/, '').trim();
Workaround
Patch ~/.npm-global/lib/node_modules/openclaw/dist/monitor-provider-*.js directly. Gets overwritten on npm update.
Related
/cc @vincentkoc @joelnishanth
Summary
iMessage DM replies echo back to the agent as new inbound messages. The echo cache fails to match because:
SENT_MESSAGE_TEXT_TTL_MS = 4000(4s) but echoes arrive 5-10s laternormalizeEchoTextKey()Reproduction
is_from_me=0\ufffd, shown as�) followed by a truncated copy of the originalAffected versions
Root cause
normalizeEchoTextKey()inmonitor-provider-*.jsonly strips whitespace/CR. It does not strip leading U+FFFD/U+FFFE/control chars that iMessage adds to reflected copies. Additionally, the 4s text TTL expires before most echoes arrive.Suggested fix
SENT_MESSAGE_TEXT_TTL_MSto 30s (matching the WhatsApp echo fix pattern)normalizeEchoTextKey():Workaround
Patch
~/.npm-global/lib/node_modules/openclaw/dist/monitor-provider-*.jsdirectly. Gets overwritten onnpm update.Related
/cc @vincentkoc @joelnishanth