fix(imessage): normalize leading echoed text corruption

Fixes #59973
This commit is contained in:
openclaw-clownfish[bot]
2026-04-28 21:04:20 -07:00
committed by GitHub
parent 34ef403cb2
commit be445dd1c1
3 changed files with 37 additions and 1 deletions

View File

@@ -22,12 +22,17 @@ export type SentMessageCache = {
// duplicate delivery (noisy but not lossy) — never message loss.
const SENT_MESSAGE_TEXT_TTL_MS = 4_000;
const SENT_MESSAGE_ID_TTL_MS = 60_000;
const LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS = /^[\uFEFF\uFFFD\uFFFE\uFFFF]+/u;
function normalizeEchoTextKey(text: string | undefined): string | null {
if (!text) {
return null;
}
const normalized = text.replace(/\r\n?/g, "\n").trim();
const normalized = text
.replace(/\r\n?/g, "\n")
.trim()
.replace(LEADING_ATTRIBUTED_BODY_CORRUPTION_MARKERS, "")
.trim();
return normalized ? normalized : null;
}

View File

@@ -17,6 +17,36 @@ describe("iMessage sent-message echo cache", () => {
expect(cache.has("acct:imessage:+1666", { text: "Reasoning:\n_step_" })).toBe(false);
});
it("matches delayed reflected echoes with leading attributedBody corruption markers", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
const cache = createSentMessageCache();
cache.remember("acct:imessage:+1555", { text: "Delayed echo reply" });
expect(
cache.has("acct:imessage:+1555", {
text: "\uFFFD\uFFFE\uFFFF\uFEFFDelayed echo reply",
}),
).toBe(true);
});
it("keeps attributedBody corruption cleanup leading-only", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));
const cache = createSentMessageCache();
cache.remember("acct:imessage:+1555", { text: "Delayed echo reply" });
expect(
cache.has("acct:imessage:+1555", {
text: "Delayed \uFFFD echo reply",
}),
).toBe(false);
expect(cache.has("acct:imessage:+1555", { text: "Delayed\techo reply" })).toBe(false);
expect(cache.has("acct:imessage:+1555", { text: "Delayed\necho reply" })).toBe(false);
});
it("matches by outbound message id and ignores placeholder ids", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-25T00:00:00Z"));