Skip to content

bug(slack): streaming not disabled in multi-bot threads — wrong cache key in handle_message #556

@antigenius0910

Description

@antigenius0910

Description

src/slack.rs:1120other_bot_present is always false because the multibot_threads cache is queried with the wrong key.

The cache is written in note_other_bot_in_thread (line 91) keyed by thread_ts:

cache.entry(thread_ts.to_string()).or_insert_with(tokio::time::Instant::now);

It is correctly read in bot_participated_in_thread (line 228) using thread_ts:

cache.get(thread_ts).is_some_and(|ts| ts.elapsed() < self.session_ttl)

But handle_message at line 1120 diverges and uses channel_id — a key that never exists in the cache:

// Bug: always false — channel_id is never a key in multibot_threads
cache.contains_key(&thread_channel.channel_id)

Since use_streaming() (line 419) returns !other_bot_present, streaming is permanently ON for all threads regardless of whether another bot is present. Regresses PR #535.

Suggested fix:

let other_bot_present = {
    let cache = adapter.multibot_threads.lock().await;
    thread_channel.thread_id.as_deref()
        .is_some_and(|ts| cache.get(ts).is_some_and(|inst| inst.elapsed() < adapter.session_ttl))
};

Uses .get(ts).is_some_and(|inst| inst.elapsed() < session_ttl) to match the TTL-aware pattern at line 228, rather than bare contains_key.

Steps to Reproduce

Precondition: Two bots (openab-bot-1, openab-bot-2) running in the same workspace, both members of the test channel.

  1. @mention openab-bot-1 in a channel — confirm it replies (edited: true in conversations.replies is expected at this point; only bot-1 is in the thread).
  2. In the same thread, @mention openab-bot-2 — get a reply. This calls note_other_bot_in_thread and populates the cache with the thread_ts.
  3. In that same thread, @mention openab-bot-1 again.
  4. Inspect openab-bot-1's reply via conversations.replies.

Expected Behavior

openab-bot-1's reply in step 4 should have no edited field — streaming must be disabled once another bot has posted in the thread.

Environment

  • Version: openab-0.8.1-beta.3
  • Platform: Slack
  • Confirmed reproduction: thread 1777050262.713699 in #all-chuangwangfubot-1 reply after bot-2 posted still returned edited: true
  • Tested with: two live bot instances against Slack API

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions