feat(slack): add reinstall flow for missing scopes#2857
Conversation
| const scopeInfo = getSlackMissingScopeErrorInfo(error); | ||
| if (!scopeInfo) return null; | ||
|
|
||
| const integration = await getInstallationByTeamId(teamId); |
There was a problem hiding this comment.
WARNING: Older Slack installations may never be marked for reinstall
getInstallationByTeamId only looks up platform_installation_id, but existing Slack rows can have that column unset and store the team ID only in platform_account_id (the uninstall path already has a fallback for these older rows). For those installations this new missing-scope path returns integrationId: null, so the reinstall banner/metadata and best-effort Slack notice never get set. Consider using the same fallback lookup here or updating getInstallationByTeamId to match both columns.
There was a problem hiding this comment.
SELECT COUNT(*) FROM platform_integrations
WHERE platform = 'slack'
AND platform_installation_id IS NULL
Results in 0, so I'm going to call bullshit here.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (4 files)
Fix these issues in Kilo Cloud Reviewed by gpt-5.5-20260423 · 1,078,125 tokens |
Move Slack missing_scope detection to a single try/catch in the webhook handler (wrapping both the direct handler call and waitUntil tasks), drop the AsyncLocalStorage webhook context, the per-event captureSlackBotError helper, and the in-thread reinstall notice.
| try { | ||
| await task; | ||
| } catch (error) { | ||
| await handleSlackWebhookError(error, slackTeamId); |
There was a problem hiding this comment.
WARNING: Missing-scope errors can be swallowed before this handler sees them
The new marker only runs when the webhook handler or a waitUntil task rejects. The Slack assistant/app-home callbacks catch Slack API errors locally and only call captureException, so missing_scope from setSuggestedPrompts/publishHomeView resolves successfully and never reaches this catch. That means the Sentry flow this PR targets can still fail without setting requires_reinstall. Consider rethrowing those Slack API errors after capture or marking the installation from those catches.
Summary
Fixes https://kilo-code.sentry.io/issues/7446778281/
missing_scopeerrors in integration metadata and preserves the selected Slack model after reinstall.team_idthrough async bot handlers so assistant/app-home scope failures can mark the correct installation and send a best-effort Slack notice.Verification
missing_scopeflow and confirmed the reinstall banner appears.requires_reinstallflow after preserving Slackteam_idfrom the webhook payload.Visual Changes
Reviewer Notes
metadata.requires_reinstallfrom a real Slack APImissing_scopeerror or by comparing stored integration scopes against the currently configuredSLACK_SCOPES.chat:writeis among the missing scopes.