Skip to content

fix(ingress): bot-posted subscribed messages trigger agent turns + error spam loop #698

Closed

Description

@dcramer

Summary

When a Slack integration bot posts to a subscribed thread, Junior starts a full agent turn, fails during MCP auth delivery, and error-spams the thread (5 errors in ~27 seconds). This was observed in production today: a user posted a comment via the Linear integration; the Linear bot (B08GNFYU49J) synced it to Slack, and Junior crashed repeatedly in that thread.

Sentry issue: JUNIOR-44 — Error: Unable to deliver MCP authorization link for plugin "linear" — 5 events, 2026-06-30T19:07:09–19:07:36 UTC


Root cause

Three bugs compound to produce the error spam.

Bug 1 (primary): shouldIgnoreMessage does not filter bot-posted messages

File: packages/junior/src/chat/ingress/slack-webhook.ts

function shouldIgnoreMessage(message: Message): boolean {
  return (
    message.author.isMe === true ||
    !parseActorUserId(message.author.userId) ||
    isExternalSlackUser(message.raw as Record<string, unknown> | undefined)
  );
}

The SlackMessageEvent type includes bot_id?: string, but shouldIgnoreMessage never checks it. A message from the Linear Slack app carries bot_id (and a B-prefixed user field), but neither is checked, so the event proceeds through routeParsedMessage → subscribed route → full handleSubscribedMessage agent turn.

The preflight classifier in getSubscribedReplyPreflightDecision only short-circuits on text content (e.g. "directed at another bot by name"), not on author type, so the LLM classifier runs and may decide to reply, triggering a complete agent turn.

Bug 2 (compound): MCP auth delivery crashes with a plain Error when requesterId is a bot ID

File: packages/junior/src/chat/services/mcp-auth-orchestration.ts

During the agent turn, the Linear MCP provider requires auth. onAuthorizationRequired calls deliverPrivateMessage with userId: "B08GNFYU49J" (the bot's Slack ID).

  1. chat.postEphemeral rejects: input must match regex pattern: ^[UW][A-Z0-9]{2,}$ — Slack doesn't accept B-prefixed IDs for ephemeral messages.
  2. Fallback conversations.open({ users: "B08GNFYU49J" }) also rejects — you can't open a DM with a bot ID.
  3. deliverPrivateMessage returns false.
  4. onAuthorizationRequired throws a plain Error: Unable to deliver MCP authorization link for plugin "linear".

This error is not a ConversationQueueMessageRejectedError and not a ProviderRetryError, so the Vercel Queue treats it as a transient failure and retries.

Bug 3 (consequence): No queue-level circuit-break for auth delivery failures

File: packages/junior/src/chat/task-execution/vercel-callback.ts

handleConversationQueueRetry only suppresses ConversationQueueMessageRejectedError. The plain Error from Bug 2 passes through unhandled, causing the queue to retry up to its max retry count — producing the observed error spam (5 identical events in 27 seconds).


Full call stack (from Sentry event 400d9572ef114c7480c5985eadedd539)

Object.handleSubscribedMessage          (triggered by Linear bot message)
  → Object.replyToThread
    → Object.generateAssistantReply
      → generateAssistantReplyInPrivacyContext
        → McpToolManager.activateProvider
          → McpToolManager.handleAuthorizationRequired
            → Object.onAuthorizationRequired   ← throws here

Recommended fixes

Primary (Bug 1): In shouldIgnoreMessage, also return true when the raw event carries bot_id (set on all Slack bot/app posts):

function shouldIgnoreMessage(message: Message): boolean {
  const raw = message.raw as Record<string, unknown> | undefined;
  return (
    message.author.isMe === true ||
    !parseActorUserId(message.author.userId) ||
    isExternalSlackUser(raw) ||
    Boolean(raw?.bot_id)          // ← new: skip bot-posted messages
  );
}

This is the cleanest fix and prevents the downstream failures entirely. Bot messages should not trigger subscribed turns.

Defense-in-depth (Bug 2): In onAuthorizationRequired, before attempting deliverPrivateMessage, validate that requesterId matches the ^[UW] Slack user pattern. If not, throw AuthorizationFlowDisabledError (or ConversationQueueMessageRejectedError) instead of a plain Error. This makes the failure non-retryable.

Defense-in-depth (Bug 3): handleConversationQueueRetry should also suppress auth delivery failures as non-retryable ({ acknowledge: true }), similar to how ConversationQueueMessageRejectedError is handled.


Affected area

  • packages/junior/src/chat/ingress/slack-webhook.ts — shouldIgnoreMessage
  • packages/junior/src/chat/services/mcp-auth-orchestration.ts — onAuthorizationRequired
  • packages/junior/src/chat/task-execution/vercel-callback.ts — handleConversationQueueRetry

Reproduction

  1. Junior interacts in a thread (subscribes to it).
  2. A Slack integration (e.g. Linear, GitHub, Jira) syncs an external comment back to that thread via its bot.
  3. Junior picks up the bot message as a subscribed event, starts an agent turn, tries to use an MCP plugin that needs auth, and crashes + retries.

View Session in Sentry

Activity

  1. added
    bug
    on Jun 30, 2026
  2. added a commit that references this issue on Jun 30, 2026
    e03a8ea
  3. added a commit that references this issue on Jul 17, 2026
    0023630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions