Skip to content

fix(imessage): drop late self-chat copies of own sends - #31455

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/26059-imessage-late-echo
Nov 7, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/26059-imessage-late-echo

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: In an iMessage self-chat, the agent no longer answers late copies of its recent messages (the running gateway's last ECHO_WINDOW sends), however late the copies arrive.

In a self-chat on an Apple Account that is signed in on other devices, Messages writes about four extra is_from_me=0 copies of each message the agent sends, hours or days after the send. Each copy has a new guid and a new ROWID, and the same date as the sent row. The channel delivers every copy as a new user message, the agent answers it, and that answer gets copies too. In the report the agent answered its own replies, the /help text and a gateway notice over four days. The echo guard fired once, for a copy inside its 30 s window.

Why it matters

Messaging yourself is a setup the iMessage guide documents as supported, and a self-chat on an account that is also signed in on another device, as in the report, is hit. Each late copy is a real turn: model cost, and replies the user never asked for. Each answer then spawns more copies. The per-conversation turn ceiling does not stop it, because the copies trickle in over days.

Not a goal

  • Dropping a row because its date is much older than its arrival. The cursor's restart replay and messages that Messages delivers late are legitimately old.
  • Persisting the ledger or the new history across a restart, or bounding the history by age instead of by count.
  • Changing the 30 s exposure (ECHO_TTL_S) or the window size (ECHO_WINDOW).
  • Late copies of the user's own messages sent from another device. Not measured here; if they occur, that is a separate finding with its own test.
  • Group chats, and the other channels.

What changed (motivation → approach → change)

The guard matched a copy by when it arrived. A ledger record lives 30 s after its send resolves and is consumed by its first match, so a copy arriving hours later finds nothing. The guid dedupe, the cursor and is_from_me all see a genuinely new row, so nothing else stops it.

The client (src/kiro_crew/imessage/client.py) recognises a copy by when the agent sent it, since a late copy keeps the original send's date. Every send that may have gone out (success or an ambiguous failure, never a definitive rejection) is added to a bounded history of (body key, wall-clock send time). The history holds the last ECHO_WINDOW sends and is never consumed, because one send gets several copies. When no ledger record matches, an inbound row with that handle and body whose bridge created_at is within ECHO_TTL_S of the send is dropped as the echo. A user's own repeat of those words is dated when the user sends it, so it goes through unless it falls within 30 s of the agent's send.

The history is bounded by count, not by age. A channel with more than ECHO_WINDOW sends between a send and its late copy answers that copy once, and that answer's own copies are guarded only if they arrive within the next ECHO_WINDOW sends. The same holds for a copy of a send from before a restart, since the history lives in memory.

The body key that the ledger and the history retain is a SHA-256 digest of the normalized handle and body, so each entry has one size however long the message is; matching compares the same digest of the inbound row.

The ledger's consume-once matching, the gate order in transport.receive, the TTL and the window are unchanged. The ECHO_TTL_S comment names its second use, the date tolerance. The user guide's "Messaging yourself" section (src/kiro_crew/docs/imessage-integration.md) and the own-message section of docs/system-specs/modules/messaging.md describe the date-keyed match, the digest key, its count bound and its cost.

Backwards compatibility

Compatible: no setting, key or message shape changes; the client only gains a second way to recognise its own message.

One behaviour narrows, by design. The accepted false positive keeps its scope (an allow-listed message carrying the agent's exact text, dated within 30 s of that send), but it now holds for every such row, not only the first one. So in a self-chat, a user who sends back the agent's exact words dated within 30 s of the agent's send is now suppressed even after the echo has used up the ledger record; before, that repeat was delivered.

Removes nothing: no function, key, setting or stored state is removed or renamed, and nothing is dropped for its age.

Tests

  • test_a_late_copy_dated_at_the_send_is_still_an_echo in test/test_imessage_client.py: a send at a fixed wall time, then the clock moved three days on. Two copies with new guids, dated at the send in the bridge's format, are both echoes. A row with the same text dated an hour after the send is not, and neither is a row with other words dated at the send. The clock is a ManualClock installed on the client module, and the test reds if the body match, the date match or the wall clock is dropped, or if a match consumes its history entry.
  • test_a_retained_body_key_has_one_size_however_long_the_body: a 100,000-character send leaves one history entry whose key is the size of an empty body's key, shared with its ledger record, and the echo of that body still matches. It reds if the key keeps the body itself.
  • test_a_definitively_rejected_send_leaves_no_record_behind asserts that a definitively rejected send leaves the history empty. It reds if the rejection branch appends to the history.
  • The other ledger tests are unchanged and still pin the ledger's consume-once behaviour. Their rows carry the fixture's fixed 2026-08-21 date, far from the send, so the history never matches them; they do not cover a repeat dated within 30 s of the send, which the history now suppresses (see Backwards compatibility).

Proof: PROVEN test/test_imessage_client.py::TestOwnEchoLedger::test_a_late_copy_dated_at_the_send_is_still_an_echo (head 124af6c)

Determinism: the two new tests passed 20 of 20 runs at -n0, and 10 of 10 runs at -n 2 --dist loadgroup --max-worker-restart=2 beside test/test_imessage_transport.py and test/test_imessage_dispatch.py. All 77 tests of test/test_imessage_client.py passed in a shuffled order (seed 26059). The flake-pattern ratchet and the repository's semgrep rules on the diff are clean.

Manual verification

The live bridge probe could not run on the Mac used for this PR: the imsg bridge is not installed there, the probe would have needed new Messages permission grants, and no second Apple device was available. So the late copies did not reproduce here. The fix rests on the reporter's database evidence, and only the field shapes were confirmed, from the bridge's source rather than a live capture:

  • Q1 (late copies of an agent send): not measured on this Mac. The real-row evidence is the reporter's read-only chat.db query in iMessage self-chat: delayed "received" copies get past the echo guard, and the agent loops #26059: four is_from_me=0 copies of one sent row, each with its own guid and ROWID and a date equal to the sent row's, one of them arriving after rows dated a day later.
  • Q2 (late copies of a message the user sends from another device): not measured, so it is listed under Not a goal.
  • Q3 (created_at format): ISO 8601 with milliseconds and Z, for example 2026-08-21T05:12:44.123Z. The bridge formats it with ISO8601DateFormatter (.withInternetDateTime, .withFractionalSeconds) from the row's date column (OutputModels.swift, MessageStore+Messages.swift), so a copy that carries the sent row's date carries the same created_at. Python 3.12's datetime.fromisoformat parses it as is.
  • Q4 (sent row date minus the client's clock before the send): not measured on this Mac. The sent row is written by Messages on the same Mac while send awaits the bridge, which it does for at most 30 s (the call's timeout). In the report, the gateway logged its one in-window echo drop at 09:26:16 local time, the same second as the 16:26:16 UTC date of the /help sends, which is consistent with a small delta if that Mac was on UTC-7 (US Pacific daylight time on that date; the report does not state the zone).
  • Q5 (send result): ok, transport, guid, message_id, chat_guid and service, plus id on the AppleScript path or attempt_id on the bridge path.

Related tests run locally: the 32 test files that reference the iMessage package or the two edited docs, plus the security package line-budget test and the flake-pattern ratchet (2567 passed, 1 skipped).

Screenshots / video

N/A: no frontend change.

Related Issues

Closes #26059
Refs #5246

Sibling sweep

Swept: git grep -n ECHO_TTL_S -- src
Swept: git grep -nE "bot_user_id|from_me|is_own_echo" -- src/kiro_crew/whatsapp src/kiro_crew/discord
Sibling: src/kiro_crew/whatsapp/echo.py -- not affected -- it keys on the sent message id with a 20-minute arrival TTL, and WhatsApp redelivers with the same id within minutes, not as new ids days later
Sibling: src/kiro_crew/discord/client_gateway.py:405 -- not affected -- it drops its own messages by the bot user id the platform reports

Pattern harvest

Not generalizable: the defect is specific to a platform that re-delivers an account's own message as new rows with new ids but the original date; every other channel recognises its own messages by an identity or id the platform keeps.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 14:14
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 14:14
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 124af6c09a6440b46e133b3cd7732f915908191c touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 124af6c09a6440b46e133b3cd7732f915908191c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the match is keyed on the send date that a late copy keeps, it is bounded by count, and it only adds suppression, so reverting it is clean.

Notes

  • The fix depends on each late copy carrying the sent row's created_at. That comes from the reporter's chat.db rows, and no live capture confirms it. If Messages ever re-dates a copy, the guard misses it and nothing logs that, so the loop comes back unnoticed. A debug line when a history key matches but the date is outside the window would show this in the field.

[DESIGN-REVIEWED] 124af6c

Description read

[DESCRIPTION-READ] 2653705d641a3defaa7fb31824119d766dabc51fe2ea19d4a85886d25b20258e

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 124af6c09a6440b46e133b3cd7732f915908191c — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The date-keyed history fixes the reported loop (#26059) at the mechanism level. The SHA-256 key rides along with no reported harm behind it.

Notes

  • Item 3 — rides along, inherited: the ledger already held full bodies, capped at ECHO_WINDOW = 256 (client.py:81), and no issue reports that memory as a problem. The only support is "each entry has one size however long the message is". Subtraction: in _echo_key, drop hashlib.sha256(...) and keep the plain pair string, along with test_a_retained_body_key_has_one_size_however_long_the_body.

What this change ships

Inventory (5 items) — 4 justified

Intent: in an iMessage self-chat, stop the agent answering its own messages when Messages delivers copies of them days later. This is a FIX.

  1. Late copies dated within 30 s of one of the last 256 sends are now ignored, however late they arrive — justified
  2. A user who sends back the agent's exact words, dated within 30 s of its send, is now suppressed every time instead of once — justified
  3. The stored echo key is now a SHA-256 digest of handle and body — rides along
  4. Inbound messages now carry the bridge's created_at date (one consumer: is_own_echo) — justified
  5. The user guide and the messaging spec describe the date-keyed match — justified

[FIRST-PRINCIPLES-REVIEWED] 124af6c

Description read

[DESCRIPTION-READ] e272caa7e0f0915ab06d3441d6c8ab5e5968ee360978411d49900105e0fb7cf4

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 124af6c09a6440b46e133b3cd7732f915908191c — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 124af6c

Verdict parsed from the review's SHA-scoped output markers for commit 124af6c09a6440b46e133b3cd7732f915908191c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 124af6c09a6440b46e133b3cd7732f915908191c false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 124af6c09a6440b46e133b3cd7732f915908191c and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 124af6c

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 124af6c09a6440b46e133b3cd7732f915908191c false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 14:43
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Backend Tests (3.12, 2), Backend Tests (Windows) (2) and Coverage Gate on c91cd6f come from main, not from this diff:

This PR waits for #31469 to merge, then rebases onto it and re-runs CI. No rerun or override for this red before then.

@bolichen97
bolichen97 force-pushed the fix/26059-imessage-late-echo branch from c91cd6f to 0abefe6 Compare November 6, 2026 16:26
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] #31469 has merged, so this branch is now rebased onto main at 89a6107, which carries it. That is the fix for the main-side red (test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget) behind Backend Tests (3.12, 2), Backend Tests (Windows) (2) and Coverage Gate on c91cd6f.

  • The patch is unchanged: same patch-id as c91cd6f, same four files.
  • Locally on the new head 0abefe6: the iMessage, channel-boot and messaging contract tests plus that line-budget node id pass (539 passed), along with isort, flake8, mypy (linux platform), the flake-pattern ratchet and docs-lint. prove.py re-run: PROVEN.
  • The Proof: line in the body now names the new head. CI is re-running on 0abefe6.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/26059-imessage-late-echo branch from 0abefe6 to 545ede9 Compare November 6, 2026 17:23
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • Count-limited history retains unbounded message bodies span=c10c4efa5a6c

fixed in 545ede9: _echo_key returns the SHA-256 hex digest of the normalized handle and body, so every retained body key is 64 characters however long the message is.
That one chokepoint bounds both stores that keep the key: the _sent_history deque and the _own_sends ledger records, each capped at ECHO_WINDOW entries.
Matching keeps its meaning: the inbound row's key is the same digest, compared for equality. The encode uses surrogatepass, so a lone surrogate in a body cannot raise.
Pinned by test_a_retained_body_key_has_one_size_however_long_the_body: a 100,000-character send keeps a key the size of an empty body's, and its echo still matches. Reverting the digest turns it red.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/26059-imessage-late-echo branch from 545ede9 to fdd9743 Compare November 6, 2026 18:31
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased: main moved in docs/system-specs/modules/messaging.md (the Telegram private-topic target, #31123) and 23 same-directory spec files since this head went green (0846b6a -> c0e9c2e); CI re-running. The diff is unchanged (same patch id), the iMessage and doc-reading tests pass on the new base, and the Proof: line is re-recorded for the new head.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Backend Tests (3.12, 2) and Backend Tests (Windows) (2) on fdd9743 come from main, not from this diff:

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • macOS-only premise has no manual verification span=dc55a18ba8d1

Rebutted: Q1 rests on real rows, the reporter's read-only chat.db query in #26059: four is_from_me=0 copies of one sent row, each with a new guid and ROWID and a date equal to the sent row's. The bridge formats created_at from that date column, so every copy carries the sent row's created_at.
Q4 is bounded by the code: sent_at = time.time() is taken just before send, the sent row is written by Messages on the same Mac while the call awaits the bridge, and that call times out at 30 s (_call's default), within ECHO_TTL_S. The report's one in-window drop is logged at 09:26:16 local time, the same second as the 16:26:16 UTC date of the /help sends, consistent with one clock if that Mac was on UTC-7 (the report does not name the zone).
If either premise were wrong, the history never matches and the copy is answered, which is the behaviour before this PR; the accepted false positive keeps its 30 s scope, as Backwards compatibility states.
A live capture needs a second Apple device and new Messages permission grants, which the Mac used for this PR does not have; Manual verification records both points. A maintainer who wants a live capture before merge can ask for it here.

@bolichen97
bolichen97 force-pushed the fix/26059-imessage-late-echo branch from fdd9743 to 1b1395e Compare November 6, 2026 20:23
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] #31625 has merged, so this branch is now rebased onto main at 39717a0, which carries it. That is the fix for the main-side red (test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget) behind Backend Tests (3.12, 2), Backend Tests (Windows) (2) and Coverage Gate on fdd9743.

  • The patch is unchanged: same patch-id as fdd9743, same four files.
  • Locally on the new head 1b1395e: the 32 test files that reference the iMessage package or the two edited docs, that line-budget node id and the flake-pattern ratchet pass (2567 passed, 1 skipped), along with isort, flake8, mypy (linux platform), black, comment-history, brand-name, file line cap and docs-lint. prove.py re-run: PROVEN.
  • The Proof: line in the body names the new head, and Manual verification cites the reporter's real-row evidence for Q1 and Q4. CI is re-running on 1b1395e.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Backend Tests (3.12, 7) and Coverage Gate on 1b1395e do not come from this diff:

The five AI review lanes on this head stopped on GitHub's API rate limit before producing a verdict, so they have been rerun once.

@bolichen97
bolichen97 force-pushed the fix/26059-imessage-late-echo branch from 1b1395e to 136a3dd Compare November 7, 2026 00:56
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased onto current main (39717a0 -> f71f5dd) to pick up #31803, which fixes the main-side failure of test_pull_request_target_allowlist behind the red Backend Tests (3.12, 7) and Coverage Gate on the previous head. The patch is unchanged (same patch id); only the base and the head named on the Proof: line moved. CI re-running on 136a3dd.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 7, 2026
In a self-chat on an account with other devices, Messages can write
extra is_from_me=0 copies of a sent message hours or days later. Each
copy has a new guid and ROWID but the sent row's date. The echo ledger
matches for 30 s after the send resolves and is consumed on its first
match, so every late copy reached the agent as a new user message, and
the answer to it got late copies too.

Recognise a copy by when the agent sent it instead of when it arrives.
Each possibly delivered send also goes into a bounded, never-consumed
history of (body key, wall-clock send time). When no ledger record
matches, a row with that body whose bridge created_at is within
ECHO_TTL_S of the send is the echo. The ledger, the gate order in
transport.receive, the TTL and the window size are unchanged, so the
accepted false positive stays the exact text dated within 30 s of the
send. Nothing old is dropped by age, which keeps the cursor's restart
replay working.

The body key the ledger and the history retain is a SHA-256 digest of
the normalized handle and body, so each entry has one size however
long the message is.

The user guide and the messaging spec describe the date-keyed match.
@bolichen97
bolichen97 force-pushed the fix/26059-imessage-late-echo branch from 136a3dd to 124af6c Compare November 7, 2026 03:12
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased: main moved in docs/system-specs/modules/messaging.md and 18 sibling spec files since this head's CI ran (f71f5dd -> a5664dd); CI re-running on 124af6c. The patch is unchanged (range-diff identical), and the iMessage and doc-contract tests pass locally on the new base.

The red Opus 5.5, GPT 6.1, Design, First Principles and UX lanes, plus Dependency License Gate, Sensitive Change Review and Publish readiness signal on 136a3dd, came from the CI app hitting its API rate limit (API rate limit exceeded for installation). None of them posted a verdict, and the new head runs them all again.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for the on-call. Review lanes pass on 124af6c, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit e9e94fd into main Nov 7, 2026
97 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/26059-imessage-late-echo branch November 7, 2026 05:04
buluoray pushed a commit that referenced this pull request Nov 8, 2026
In a self-chat on an account with other devices, Messages can write
extra is_from_me=0 copies of a sent message hours or days later. Each
copy has a new guid and ROWID but the sent row's date. The echo ledger
matches for 30 s after the send resolves and is consumed on its first
match, so every late copy reached the agent as a new user message, and
the answer to it got late copies too.

Recognise a copy by when the agent sent it instead of when it arrives.
Each possibly delivered send also goes into a bounded, never-consumed
history of (body key, wall-clock send time). When no ledger record
matches, a row with that body whose bridge created_at is within
ECHO_TTL_S of the send is the echo. The ledger, the gate order in
transport.receive, the TTL and the window size are unchanged, so the
accepted false positive stays the exact text dated within 30 s of the
send. Nothing old is dropped by age, which keeps the cursor's restart
replay working.

The body key the ledger and the history retain is a SHA-256 digest of
the normalized handle and body, so each entry has one size however
long the message is.

The user guide and the messaging spec describe the date-keyed match.

(cherry picked from commit e9e94fd)
buluoray pushed a commit that referenced this pull request Nov 8, 2026
In a self-chat on an account with other devices, Messages can write
extra is_from_me=0 copies of a sent message hours or days later. Each
copy has a new guid and ROWID but the sent row's date. The echo ledger
matches for 30 s after the send resolves and is consumed on its first
match, so every late copy reached the agent as a new user message, and
the answer to it got late copies too.

Recognise a copy by when the agent sent it instead of when it arrives.
Each possibly delivered send also goes into a bounded, never-consumed
history of (body key, wall-clock send time). When no ledger record
matches, a row with that body whose bridge created_at is within
ECHO_TTL_S of the send is the echo. The ledger, the gate order in
transport.receive, the TTL and the window size are unchanged, so the
accepted false positive stays the exact text dated within 30 s of the
send. Nothing old is dropped by age, which keeps the cursor's restart
replay working.

The body key the ledger and the history retain is a SHA-256 digest of
the normalized handle and body, so each entry has one size however
long the message is.

The user guide and the messaging spec describe the date-keyed match.

(cherry picked from commit e9e94fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iMessage self-chat: delayed "received" copies get past the echo guard, and the agent loops

2 participants