Repository navigation
Description
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).
chat.postEphemeralrejects:input must match regex pattern: ^[UW][A-Z0-9]{2,}$— Slack doesn't acceptB-prefixed IDs for ephemeral messages.- Fallback
conversations.open({ users: "B08GNFYU49J" })also rejects — you can't open a DM with a bot ID. deliverPrivateMessagereturnsfalse.onAuthorizationRequiredthrows a plainError: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—shouldIgnoreMessagepackages/junior/src/chat/services/mcp-auth-orchestration.ts—onAuthorizationRequiredpackages/junior/src/chat/task-execution/vercel-callback.ts—handleConversationQueueRetry
Reproduction
- Junior interacts in a thread (subscribes to it).
- A Slack integration (e.g. Linear, GitHub, Jira) syncs an external comment back to that thread via its bot.
- 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.
Activity
fix(auth): Hard-fail bot authorization requests
fix(auth): Hard-fail bot authorization requests (getsentry#700)