Skip to content

fix: large Slack file attachments crash workflow_runs INSERT with JSONB overflow #435

@j-s

Description

@j-s

Summary

When a Slack thread contains a large file attachment (e.g., a video), the slack_thread_turn workflow fails with:

asyncpg.exceptions.ProgramLimitExceededError: string too long to represent as jsonb string
DETAIL: Due to an implementation restriction, jsonb strings cannot exceed 268435455 bytes.

Root Cause

services/slackbot/src/slack/normalize.tsfetchSlackFilePart() downloads and base64-encodes Slack files of any size into the message parts. These parts flow into the slack_thread_turn workflow's input_json JSONB column via POST /workflows/runs, which crashes on INSERT for files larger than ~190MB (256MB JSONB limit minus overhead).

The centralized AttachmentProcessor (#383) exists but is not wired into the workflow run creation path — it only processes attachments after the workflow run is already stored.

Impact

  • Bot silently fails to respond in any Slack thread with a large media attachment (video, large PDF, etc.)
  • The slack_thread_turn workflow returns 500, slackbot logs Centaur Slack handoff failed: 500
  • No error is surfaced to the user in Slack

Suggested Fix

Add a file size check in fetchSlackFilePart() before downloading. For files exceeding a threshold (e.g., 25MB), return a text-only part with file metadata instead of inlining the binary content:

if (knownSize !== undefined && knownSize > MAX_INLINE_FILE_BYTES) {
  return {
    type: 'text' as const,
    text: `[Attached file: ${fileName} (${mimeType}, ${sizeMB} MB) — too large to inline]`
  }
}

A more complete fix would route large files through the AttachmentProcessor / attachments table before creating the workflow run, so the agent can still access the file content on demand.

Reproduction

  1. Upload a large video (>25MB) to a Slack channel where the bot is active
  2. Mention the bot in the thread containing the video
  3. Observe 500 error in API logs for POST /workflows/runs

Environment

  • Chart version: 0.1.49
  • Commit: 89988b1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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