Repository navigation
fix(slack): record an observe-channel message once, not per message/app_mention event - #26770
Conversation
59b0ca4 to
8001277
Compare
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: a separate [DESIGN-REVIEWED] 2a0712a Description read[DESCRIPTION-READ] dce3892cb5164e65134fe341839310a0a2cb2865a82cdb12ad4005ca056679c3 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix guards the only What this change shipsInventory (2 items) — 2 justifiedIntent: a Slack message in an observe channel is written to channel history once, not once per delivery. FIX.
[FIRST-PRINCIPLES-REVIEWED] 2a0712a Description read[DESCRIPTION-READ] 927027403647329d75596031a528b1d29d3100ed7b0aa985945c7e70203d2f11 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
A Slack @mention is delivered as both a `message` and an `app_mention` event sharing one msg_ts, and socket mode can redeliver an envelope. Observe mode records channel history above the msg_ts turn-dedup, so the same message was written to history twice (in memory and on disk) while the turn ran once. Guard the observe push with its own `observe:` seen key so each message is recorded once, without consuming the bare msg_ts token the paired app_mention turn needs. Closes kirodotdev#26769
f9cf77e to
2a0712a
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: dedups the observe-mode history push under its own key so one Slack mention is recorded once, with a test.
…pp_mention event (#26770) * fix(slack): dedup observe-channel history pushes by msg_ts A Slack @mention is delivered as both a `message` and an `app_mention` event sharing one msg_ts, and socket mode can redeliver an envelope. Observe mode records channel history above the msg_ts turn-dedup, so the same message was written to history twice (in memory and on disk) while the turn ran once. Guard the observe push with its own `observe:` seen key so each message is recorded once, without consuming the bare msg_ts token the paired app_mention turn needs. Closes #26769 * test(slack): sort the observe-dedup test imports --------- Co-authored-by: iamwhatever <12429733+iamwhatever@users.noreply.github.com> (cherry picked from commit 45955da)
Problem / Motivation
Goal: a Slack message in an
activation=observechannel is recorded in channel history exactly once.In
_route_message(src/kiro_crew/slack/events.py), the observe-mode history push runs at the top of the observe branch (near line 757), BEFORE themsg_tsdedup near line 804 (if seen.check_and_add(msg_ts): return). A Slack @mention is delivered as BOTH amessageevent (routed withis_mention=False) and anapp_mentionevent (is_mention=True) sharing onemsg_ts, and socket mode can redeliver an envelope. Each delivery reaches the observe push, so the one message is appended tochannel_historytwice — in memory and in the JSONL file — andcontext_forinjects the line twice. The turn itself still runs once, because only theapp_mentionevent passes the dedup and dispatches.Why it matters
The non-observe push (near line 887) sits below the dedup, and its comment says observe channels are "already pushed above ... to avoid duplicates" — single recording is the intent. The duplicate entries persist, reload from disk on restart, inflate the agent's context, and count against
observe_max_entries, so a busy observe channel loses real history faster than its cap implies.Why the existing dedup does not catch it
The token at line 804 is placed after the activation check on purpose, so a plain
messageevent does not mark the ts seen before itsapp_mentionarrives (its own comment, andSeenCache.check's docstring, say exactly this). Themessageevent (is_mention=False) returns at the thread-follow gate immediately after the push, before ever reaching line 804, so it never marks the baremsg_ts; theapp_mentionevent then finds an unmarked ts and pushes again. Marking the baremsg_tsat the push site would instead drop the pairedapp_mentionturn, so the turn-dedup token cannot be reused here.Not a goal
tsdelivery, so they are out of scope.What changed (motivation → approach → change)
Symptom: one observe-channel message is recorded twice. Root cause: the observe push runs above the turn-dedup, and the two deliveries of one message share no dedup before the push.
Change: in
src/kiro_crew/slack/events.py, guard the observe push with its own dedup key —seen.check_and_add(f"observe:{msg_ts}")— distinct from the bare-msg_tsturn token. The code already namespacesseenkeys (intercept:{msg_ts}), so this follows the existing convention. The first delivery records the message and marksobserve:<ts>; any later delivery of the same ts (the paired event, or a redelivered envelope) skips the push. Because the key is separate from the baremsg_ts, the turn-dedup at line 804 is untouched and the pairedapp_mentionturn still runs exactly once. The guard short-circuits aftershould_record_observe_history, so an unauthorized sender neither records nor marks a key.Backwards compatibility
Compatible. A single-delivery message (the common case) records exactly as before. Only a second delivery of the same
msg_tsis now skipped, which is the bug. No on-disk format or config changes.Tests
test/test_observe_mention_dedup.py:test_observe_mention_pair_recorded_once— amessage(is_mention False) +app_mention(is_mention True) pair with onetsyieldsentry_count == 1, andhandle_messageis called once (the turn is unchanged).test_observe_redelivered_message_recorded_once— a socket-mode redelivery of onemessageevent yieldsentry_count == 1.ChannelHistoryand reuse_make_orchfromtest/test_channel_activation.py. With the guard reverted both fail (entry_count == 2).test/test_channel_activation.py(17 tests) passes unchanged alongside the two new ones.Manual verification
On
origin/mainthe two tests reproduce the double-record (entry_count == 2); on this branch both record once. The change touches no frontend file.Related Issues
Closes #26769
Sibling sweep
Swept: every
channel_history.pushsite inevents.py(lines 757 and 887) and the dedup token at line 804.Sibling:
src/kiro_crew/slack/events.py:887-- not affected -- the non-observe history push already sits below themsg_tsdedup, so a redelivered or paired event returns before reaching it; only the observe branch pushes above the dedup.Related, not a duplicate: PR #6557 (open) bounds the observe history file on disk by entry count in
channel_history.py; it does not touch this event-layer double-record and shares no files with this change, which reduces what that on-disk bound has to hold.Pattern harvest
Rule candidate: review-prompt
Pattern: a record written above a dedup gate, where one logical event arrives as two deliveries that each reach the record before the gate — dedup the record under its own key rather than reusing the gate's token.
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license, as the Licensing section of CONTRIBUTING.md describes.