fix(slack): truncate edit_message content to prevent msg_too_long

Slack's chat.update enforces the same ~40k character limit as
chat.postMessage, but edit_message sent the formatted text unchunked —
an oversized edit failed outright with msg_too_long and the message
was never updated. Unlike send() we cannot split an edit into multiple
messages, so truncate to MAX_MESSAGE_LENGTH via the shared chunker
(which preserves code-block boundaries) and keep the first chunk.

Reapplied from PR #33224 (targeted the pre-plugin gateway/platforms/slack.py
path) onto plugins/platforms/slack/adapter.py.
This commit is contained in:
CJ Wang / SoWork 2026-07-22 03:54:26 -07:00 committed by Teknium
parent a2d8b4b1f6
commit 72da4f8657

View file

@ -1701,6 +1701,12 @@ class SlackAdapter(BasePlatformAdapter):
return SendResult(success=False, error="Not connected")
try:
formatted = self.format_message(content)
# Slack's chat.update has the same ~40k char limit as postMessage.
# Unlike send() we can't split into multiple messages (we're
# editing an existing one), so truncate to fit — an oversized
# payload fails the whole edit with ``msg_too_long``.
chunks = self.truncate_message(formatted, self.MAX_MESSAGE_LENGTH)
formatted = chunks[0] if chunks else formatted
update_kwargs: Dict[str, Any] = {
"channel": chat_id,
"ts": message_id,