Skip to content

Handle Slack msg_too_long by posting tail in thread#132

Merged
seratch merged 1 commit into
seratch:mainfrom
PeterDaveHello:fix/slack-long-replies-chunk-tail
Dec 29, 2025
Merged

Handle Slack msg_too_long by posting tail in thread#132
seratch merged 1 commit into
seratch:mainfrom
PeterDaveHello:fix/slack-long-replies-chunk-tail

Conversation

@PeterDaveHello
Copy link
Copy Markdown
Contributor

When chat.update hits msg_too_long, post only the remaining tail in the same thread to avoid truncation and repetition. Track last-sent prefixes and final-send claims to prevent duplicate replies, and cover long-reply paths with tests.

GitHub Copilot summary:

This pull request introduces robust handling for Slack message length limits and improves how replies are posted and updated in threads, especially for long AI-generated responses. The changes ensure that updates and final replies respect Slack's practical and hard limits, prevent duplicate message sends, and improve reliability for threaded conversations. Additionally, new tests verify correct thread root handling for replies.

Slack message length management and reliability:

  • Added logic to split long Slack messages into safe chunks using UTF-8 byte limits, both for interim updates and final replies, and introduced constants for Slack's practical message size limits (SLACK_INTERIM_MESSAGE_BYTE_LIMIT, SLACK_POST_MESSAGE_BYTE_LIMIT). (app/slack_constants.py [1] app/slack_ops.py [2]
  • Enhanced update_wip_message and related reply logic to handle msg_too_long errors: now posts only the unsent tail of long messages as new thread replies, avoiding duplication and flooding. (app/slack_ops.py app/slack_ops.pyR110-R345)
  • Added in-memory cache (_ReplyCache) to track last sent message chunks and prevent duplicate final sends in threads. (app/slack_ops.py app/slack_ops.pyR110-R345)

Thread handling improvements:

  • Ensured that replies in threads use the correct root thread timestamp (root_thread_ts) for both interim and final updates, across both app mentions and new messages. (app/bolt_listeners.py [1] [2]
  • Updated all relevant message posting and updating functions to accept and use root_thread_ts, propagating this value through the call chain. (app/openai_ops.py [1] [2]

Testing and validation:

  • Added tests to verify that threaded replies correctly use the thread root timestamp for posting and updating messages, preventing misplaced replies. (tests/bolt_listeners_test.py tests/bolt_listeners_test.pyR1-R111)

These changes collectively make Slack interactions with the bot more robust, especially for long AI-generated responses and threaded conversations.

When chat.update hits msg_too_long, post only the remaining tail in the
same thread to avoid truncation and repetition. Track last-sent prefixes
and final-send claims to prevent duplicate replies, and cover long-reply
paths with tests.
@seratch seratch merged commit 6736942 into seratch:main Dec 29, 2025
7 checks passed
@PeterDaveHello PeterDaveHello deleted the fix/slack-long-replies-chunk-tail branch December 29, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants