Repository navigation
fix(imessage): drop late self-chat copies of own sends - #31455
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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
[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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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
What this change shipsInventory (5 items) — 4 justifiedIntent: in an iMessage self-chat, stop the agent answering its own messages when Messages delivers copies of them days later. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 124af6c Description read[DESCRIPTION-READ] e272caa7e0f0915ab06d3441d6c8ab5e5968ee360978411d49900105e0fb7cf4 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
[operator: bolichen97] The red
This PR waits for #31469 to merge, then rebases onto it and re-runs CI. No rerun or override for this red before then. |
c91cd6f to
0abefe6
Compare
|
[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 (
|
0abefe6 to
545ede9
Compare
|
[operator: bolichen97]
|
545ede9 to
fdd9743
Compare
|
[operator: bolichen97] Rebased: main moved in |
|
[operator: bolichen97] The red
|
|
[operator: bolichen97]
|
fdd9743 to
1b1395e
Compare
|
[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 (
|
|
[operator: bolichen97] The red
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. |
1b1395e to
136a3dd
Compare
|
[operator: bolichen97] Rebased onto current main (39717a0 -> f71f5dd) to pick up #31803, which fixes the main-side failure of |
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.
136a3dd to
124af6c
Compare
|
[operator: bolichen97] Rebased: main moved in 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 ( |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on 124af6c, no conflict, no open change request.
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)
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)
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_WINDOWsends), 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=0copies 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/helptext 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
ECHO_TTL_S) or the window size (ECHO_WINDOW).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_meall 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 lastECHO_WINDOWsends and is never consumed, because one send gets several copies. When no ledger record matches, an inbound row with that handle and body whose bridgecreated_atis withinECHO_TTL_Sof 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_WINDOWsends 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 nextECHO_WINDOWsends. 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. TheECHO_TTL_Scomment 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 ofdocs/system-specs/modules/messaging.mddescribe 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_echointest/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 aManualClockinstalled 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_behindasserts that a definitively rejected send leaves the history empty. It reds if the rejection branch appends to the history.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=2besidetest/test_imessage_transport.pyandtest/test_imessage_dispatch.py. All 77 tests oftest/test_imessage_client.pypassed 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
imsgbridge 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:chat.dbquery in iMessage self-chat: delayed "received" copies get past the echo guard, and the agent loops #26059: fouris_from_me=0copies of one sent row, each with its own guid and ROWID and adateequal to the sent row's, one of them arriving after rows dated a day later.created_atformat): ISO 8601 with milliseconds andZ, for example2026-08-21T05:12:44.123Z. The bridge formats it withISO8601DateFormatter(.withInternetDateTime,.withFractionalSeconds) from the row'sdatecolumn (OutputModels.swift,MessageStore+Messages.swift), so a copy that carries the sent row's date carries the samecreated_at. Python 3.12'sdatetime.fromisoformatparses it as is.sendawaits 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/helpsends, 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).ok,transport,guid,message_id,chat_guidandservice, plusidon the AppleScript path orattempt_idon 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement