Skip to content

fix(slack-bot): prevent posting to main channel when thread message is deleted#1034

Merged
sriaradhyula merged 2 commits intomainfrom
fix/slack-bot-thread-ts-guard
Mar 24, 2026
Merged

fix(slack-bot): prevent posting to main channel when thread message is deleted#1034
sriaradhyula merged 2 commits intomainfrom
fix/slack-bot-thread-ts-guard

Conversation

@kevkantes
Copy link
Copy Markdown
Collaborator

Description

When a user posts a message and deletes it before the Slack bot processes the event, the bot would post its response to the main channel instead of a thread. This happened because Slack's chat_postMessage silently ignores an invalid thread_ts and falls back to posting in the channel.

This PR adds a multi-layer guard:

  1. Pre-processing check (verify_thread_exists in utils.py): Before processing any event, calls conversations_replies to confirm the parent message still exists. If deleted, the event is dropped. Applied to all 4 entry points: handle_mention, handle_qanda_message, handle_dm_message, and handle_ai_alert_processing.

  2. Mid-stream abort (thread_deleted flag in ai.py): If the message is deleted during A2A streaming (race condition), startStream fails with invalid_thread_ts. Instead of logging 30+ warnings and falling through to chat_postMessage, we set a thread_deleted flag, break out of the stream loop, and drop the response.

Additionally migrates the slack bot from requirements.txt + pip to pyproject.toml + uv, matching the rest of the project's dependency management:

  • New pyproject.toml with explicit PyPI index and unittest dependency group
  • Updated Dockerfile.slack-bot to use uv sync --locked
  • Added command override in docker-compose.dev.yaml to handle volume-mount dev mode
  • Removed requirements.txt

Type of Change

  • Bugfix
  • Refactor

Checklist

  • I have read the contributing guidelines
  • I have verified this change is not present in other open pull requests
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass (70/70)

…s deleted

Signed-off-by: Kevin Kantesaria <kkantesaria@splunk.com>
@github-actions
Copy link
Copy Markdown
Contributor

✅ No proprietary content detected. This PR is clear for review!

@github-actions
Copy link
Copy Markdown
Contributor

📊 Test Coverage Report

Main Tests Coverage

Metric Coverage Details
Lines 39.8% 7495/18845 lines
Branches 0.0% 0/0 branches

📁 Coverage Artifacts

  • Main tests: coverage-reports-main artifact
  • RAG tests: coverage-reports-rag artifact (not available)
  • Download artifacts to view detailed HTML coverage reports

…nts.txt

Signed-off-by: Kevin Kantesaria <kkantesaria@splunk.com>
@github-actions
Copy link
Copy Markdown
Contributor

✅ No proprietary content detected. This PR is clear for review!

@github-actions
Copy link
Copy Markdown
Contributor

📊 Test Coverage Report

Main Tests Coverage

Metric Coverage Details
Lines 39.8% 7495/18845 lines
Branches 0.0% 0/0 branches

📁 Coverage Artifacts

  • Main tests: coverage-reports-main artifact
  • RAG tests: coverage-reports-rag artifact (not available)
  • Download artifacts to view detailed HTML coverage reports

@sriaradhyula sriaradhyula merged commit 0da3bdf into main Mar 24, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants