Skip to content

fix(slack): record an observe-channel message once, not per message/app_mention event - #26770

Merged
KiroCrewCaptain merged 2 commits into
kirodotdev:mainfrom
rohnkum:fix/slack-observe-mention-dedup
Nov 6, 2026
Merged

KiroCrewCaptain merged 2 commits into
kirodotdev:mainfrom
rohnkum:fix/slack-observe-mention-dedup

Conversation

@rohnkum

@rohnkum rohnkum commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a Slack message in an activation=observe channel 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 the msg_ts dedup near line 804 (if seen.check_and_add(msg_ts): return). A Slack @mention is delivered as BOTH a message event (routed with is_mention=False) and an app_mention event (is_mention=True) sharing one msg_ts, and socket mode can redeliver an envelope. Each delivery reaches the observe push, so the one message is appended to channel_history twice — in memory and in the JSONL file — and context_for injects the line twice. The turn itself still runs once, because only the app_mention event 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 message event does not mark the ts seen before its app_mention arrives (its own comment, and SeenCache.check's docstring, say exactly this). The message event (is_mention=False) returns at the thread-follow gate immediately after the push, before ever reaching line 804, so it never marks the bare msg_ts; the app_mention event then finds an unmarked ts and pushes again. Marking the bare msg_ts at the push site would instead drop the paired app_mention turn, so the turn-dedup token cannot be reused here.

Not a goal

  • Other messaging transports (Discord, Telegram, WhatsApp, ...): a mention there does not produce a second same-ts delivery, so they are out of scope.
  • The on-disk observe file bound (PR fix(channels): bound the observe history file by observe_max_entries #6557): not changed here.
  • The turn-dedup at line 804 and the non-observe push at line 887: left unchanged — the turn still runs once and non-observe recording already sits below the dedup.

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_ts turn token. The code already namespaces seen keys (intercept:{msg_ts}), so this follows the existing convention. The first delivery records the message and marks observe:<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 bare msg_ts, the turn-dedup at line 804 is untouched and the paired app_mention turn still runs exactly once. The guard short-circuits after should_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_ts is 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 — a message (is_mention False) + app_mention (is_mention True) pair with one ts yields entry_count == 1, and handle_message is called once (the turn is unchanged).
    • test_observe_redelivered_message_recorded_once — a socket-mode redelivery of one message event yields entry_count == 1.
  • Both use the real ChannelHistory and reuse _make_orch from test/test_channel_activation.py. With the guard reverted both fail (entry_count == 2).
  • Proof: PROVEN test/test_observe_mention_dedup.py::test_observe_mention_pair_recorded_once, test/test_observe_mention_dedup.py::test_observe_redelivered_message_recorded_once (head 59b0ca4)
  • Regression: test/test_channel_activation.py (17 tests) passes unchanged alongside the two new ones.

Manual verification

On origin/main the 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.push site in events.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 the msg_ts dedup, 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

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

Contributed under the project's Apache-2.0 license, as the Licensing section of CONTRIBUTING.md describes.

@rohnkum
rohnkum requested review from a team and KiroCrewCaptain as code owners October 31, 2026 16:06
@rohnkum
rohnkum requested a review from iamwhatever October 31, 2026 16:06
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 31, 2026
@iamwhatever
iamwhatever force-pushed the fix/slack-observe-mention-dedup branch from 59b0ca4 to 8001277 Compare November 6, 2026 08:14
@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
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 2a0712a8afc0f3e0b50a22f3f628fe8b5ddcec74 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, fork) — ✅ PASS

Design-level review of 2a0712a8afc0f3e0b50a22f3f628fe8b5ddcec74 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: a separate observe: key dedups the history write without touching the turn-dedup, and it follows the existing intercept: namespacing.

[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 .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, fork) — ✅ PASS

Premise-level review of 2a0712a8afc0f3e0b50a22f3f628fe8b5ddcec74 via the fork AI-review pipeline — 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

The fix guards the only channel_history.push site above the turn-dedup, so it reaches the cause. It has a linked issue and a test that fails on base, and adds nothing beyond the fix.

What this change ships

Inventory (2 items) — 2 justified

Intent: a Slack message in an observe channel is written to channel history once, not once per delivery. FIX.

  1. When an observe-channel message arrives twice under the same ts (the message/app_mention pair, or a socket-mode redelivery), it is recorded once instead of twice — justified
  2. A regression test that pins one history entry for the pair and for a redelivery, with the turn still dispatched once — justified

[FIRST-PRINCIPLES-REVIEWED] 2a0712a

Description read

[DESCRIPTION-READ] 927027403647329d75596031a528b1d29d3100ed7b0aa985945c7e70203d2f11

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 (fork) — ✅ no blocking findings

Reviewed 2a0712a8afc0f3e0b50a22f3f628fe8b5ddcec74 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2a0712a

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 2a0712a8afc0f3e0b50a22f3f628fe8b5ddcec74 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2a0712a

@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
rohnkum and others added 2 commits November 6, 2026 11:01
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
@iamwhatever
iamwhatever force-pushed the fix/slack-observe-mention-dedup branch from f9cf77e to 2a0712a Compare November 6, 2026 11:01
@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 6, 2026
@iamwhatever iamwhatever self-assigned this Nov 6, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 6, 2026 15:08

@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.

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.

@KiroCrewCaptain
KiroCrewCaptain merged commit 45955da into kirodotdev:main Nov 6, 2026
95 of 99 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 6, 2026
buluoray pushed a commit that referenced this pull request Nov 9, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slack: an @mention in an observe channel is recorded twice in channel history

3 participants