Skip to content

feat(slack): add reinstall flow for missing scopes#2857

Open
RSO wants to merge 5 commits intomainfrom
RSO/silver-card
Open

feat(slack): add reinstall flow for missing scopes#2857
RSO wants to merge 5 commits intomainfrom
RSO/silver-card

Conversation

@RSO
Copy link
Copy Markdown
Contributor

@RSO RSO commented Apr 28, 2026

Summary

Fixes https://kilo-code.sentry.io/issues/7446778281/

  • Add a Slack reinstall state that records missing_scope errors in integration metadata and preserves the selected Slack model after reinstall.
  • Surface a dedicated Slack reinstall page for user and organization integrations, plus warning CTAs on the existing Slack integration page.
  • Preserve Slack webhook team_id through async bot handlers so assistant/app-home scope failures can mark the correct installation and send a best-effort Slack notice.

Verification

  • Manually reproduced the Slack assistant missing_scope flow and confirmed the reinstall banner appears.
  • Manually confirmed the metadata-backed requires_reinstall flow after preserving Slack team_id from the webhook payload.
  • Manually checked the Slack reinstall pages for user and organization integration paths.

Visual Changes

CleanShot 2026-04-28 at 15 01 35@2x CleanShot 2026-04-28 at 14 51 03@2x

Reviewer Notes

  • The banner can be triggered either by stored metadata.requires_reinstall from a real Slack API missing_scope error or by comparing stored integration scopes against the currently configured SLACK_SCOPES.
  • Slack notification is best-effort and skipped when chat:write is among the missing scopes.

const scopeInfo = getSlackMissingScopeErrorInfo(error);
if (!scopeInfo) return null;

const integration = await getInstallationByTeamId(teamId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 28, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/integrations/slack-service.ts 190 Older Slack installations with only platform_account_id are not found by the reinstall marker path
apps/web/src/lib/bot/webhook-handler.ts 78 Central missing-scope handler does not see Slack API errors swallowed by bot event callbacks
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
None
Files Reviewed (4 files)
  • apps/web/src/lib/bot.ts - 0 issues
  • apps/web/src/lib/bot/webhook-context.ts - 0 issues
  • apps/web/src/lib/bot/webhook-handler.ts - 1 issue
  • apps/web/src/lib/integrations/slack-service.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by gpt-5.5-20260423 · 1,078,125 tokens

RSO added 3 commits April 28, 2026 15:20
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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant