openclaw - ✅(Solved) Fix iMessage echo detection fails when echoed message has NUL (\0) prefix [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63544Fetched 2026-04-10 03:42:50
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Since upgrading to 4.2, outbound delivery messages sent via iMessage are echoing back as inbound messages, causing the main agent to reply with an acknowledgement (e.g., "收到。") after every cron-delivered notification.

Root Cause

normalizeEchoTextKey() in monitor-CkCMHJdv.js uses .trim() but does not strip NUL (\0) characters. When iMessage echoes an outbound message back into chat.db, the text is prefixed with one or more NUL bytes. This causes the echo cache lookup to fail because \0<original text> !== <original text>.

// Current (broken)
function normalizeEchoTextKey(text) {
  const normalized = text.replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}

// Suggested fix
function normalizeEchoTextKey(text) {
  const normalized = text.replace(/^\0+/, "").replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}

Additionally, the echo text TTL is 4 seconds (SENT_MESSAGE_TEXT_TTL_MS = 4e3). If the echo arrives after 4 seconds, it is not caught regardless of the text match. This may need to be tuned as well.

Fix Action

Workaround

Routing cron deliveries through imsg directly (bypassing the OpenClaw session layer) avoids the issue, but this is not a sustainable fix.

PR fix notes

PR #63581: imessage: strip NUL bytes from echo-cache text normalization

Description (problem / solution / changelog)

Summary

normalizeEchoTextKey() uses .trim() to normalize outbound messages before caching. JavaScript's .trim() does not strip NUL bytes, so when iMessage echoes back a sent message with a leading NUL prefix (as seen in chat.db), the key does not match the cached entry and the echo is forwarded as a new inbound message.

Fixed by stripping NUL bytes before trimming during text-key normalization. The implementation uses String.fromCharCode(0) based normalization so the cache key matches echoed messages without tripping the repo's no-control-regex lint rule.

Testing

  • Added two test cases covering single and multiple leading NUL bytes
  • pnpm test extensions/imessage/src/monitor/monitor-provider.echo-cache.test.ts -- 4 tests pass

Closes #63544


Made with Copilot | fully reviewed by human

Changed files

  • extensions/imessage/src/monitor/echo-cache.ts (modified, +6/-1)
  • extensions/imessage/src/monitor/monitor-provider.echo-cache.test.ts (modified, +13/-0)

Code Example

// Current (broken)
function normalizeEchoTextKey(text) {
  const normalized = text.replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}

// Suggested fix
function normalizeEchoTextKey(text) {
  const normalized = text.replace(/^\0+/, "").replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}
RAW_BUFFERClick to expand / collapse

Summary

Since upgrading to 4.2, outbound delivery messages sent via iMessage are echoing back as inbound messages, causing the main agent to reply with an acknowledgement (e.g., "收到。") after every cron-delivered notification.

Root Cause

normalizeEchoTextKey() in monitor-CkCMHJdv.js uses .trim() but does not strip NUL (\0) characters. When iMessage echoes an outbound message back into chat.db, the text is prefixed with one or more NUL bytes. This causes the echo cache lookup to fail because \0<original text> !== <original text>.

// Current (broken)
function normalizeEchoTextKey(text) {
  const normalized = text.replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}

// Suggested fix
function normalizeEchoTextKey(text) {
  const normalized = text.replace(/^\0+/, "").replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}

Additionally, the echo text TTL is 4 seconds (SENT_MESSAGE_TEXT_TTL_MS = 4e3). If the echo arrives after 4 seconds, it is not caught regardless of the text match. This may need to be tuned as well.

Reproduction

  1. Configure a cron task that sends a delivery notification to a contact via iMessage.
  2. After the delivery is sent, observe chat.db — the sent message re-appears as an inbound message with a \0 prefix on the text body.
  3. The main agent session receives the echoed message and responds.

Impact

Every iMessage-delivered cron notification (e.g., stock reports, reminders) generates a spurious agent reply to the recipient. Confirmed on macOS 15.7.4 / openclaw 2026.4.9.

Workaround

Routing cron deliveries through imsg directly (bypassing the OpenClaw session layer) avoids the issue, but this is not a sustainable fix.

extent analysis

TL;DR

Update the normalizeEchoTextKey() function to strip NUL characters and consider adjusting the SENT_MESSAGE_TEXT_TTL_MS value to catch delayed echoes.

Guidance

  • Modify the normalizeEchoTextKey() function as suggested in the issue to correctly handle NUL characters: text.replace(/^\0+/, "").replace(/\r\n?/g, "\n").trim().
  • Review and potentially adjust the SENT_MESSAGE_TEXT_TTL_MS value to ensure it can catch echoes that arrive after a short delay.
  • Test the updated function with the current SENT_MESSAGE_TEXT_TTL_MS value to see if it resolves the issue without needing to adjust the TTL.
  • Consider implementing a more robust solution that handles echoes in a way that doesn't rely solely on text matching and TTL.

Example

function normalizeEchoTextKey(text) {
  const normalized = text.replace(/^\0+/, "").replace(/\r\n?/g, "\n").trim();
  return normalized ? normalized : null;
}

Notes

The provided fix assumes that the issue is primarily caused by the NUL characters and the short TTL. However, the root cause might be more complex, and additional debugging might be necessary.

Recommendation

Apply the workaround by updating the normalizeEchoTextKey() function and adjusting the SENT_MESSAGE_TEXT_TTL_MS as needed, because upgrading to a fixed version is not mentioned as an option in the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING