Skip to content

feat(bot): replay GitHub mentions after account linking#3107

Draft
RSO wants to merge 1 commit intomainfrom
RSO/desert-krill
Draft

feat(bot): replay GitHub mentions after account linking#3107
RSO wants to merge 1 commit intomainfrom
RSO/desert-krill

Conversation

@RSO
Copy link
Copy Markdown
Contributor

@RSO RSO commented May 7, 2026

Summary

  • Threads the chat message context through the GitHub link flow so that after a new user links their account we immediately replay their original mention — matching the Slack UX instead of telling them to mention Kilo again.
  • Extracts the Slack-only context store (createLinkAccountToken) into shared storeLinkAccountContext / readLinkAccountContext helpers, and adds an optional contextKey to the GitHub link token and OAuth state so the key survives the OAuth round-trip.
  • Hoists reprocessLinkedMessage into lib/bot/run.ts and uses it from both the Slack /api/chat/link-account route and the GitHub OAuth callback.

Verification

  • Mention Kilo from an unlinked GitHub account → click the link → complete GitHub OAuth → Kilo posts a response to the original issue/PR comment without a second mention. The callback success page now reads "Kilo is already processing your message".
  • Repeat the OAuth callback (e.g. browser back + re-submit) → the context is consumed once, the second attempt does not re-trigger a bot run, and the success page falls back to "mention Kilo again".
  • Legacy pre-deploy link tokens (no contextKey) still link successfully; only the replay is skipped.

Visual Changes

N/A

Reviewer Notes

  • consumeLinkAccountContext is the single-use guard — we call readLinkAccountContext first so we can reconstruct the context, then consumeLinkAccountContext atomically to prevent duplicate replays from OAuth retries. The Slack route keeps its existing consume → after(reprocess) order.
  • createGitHubBotLinkState changed from positional callbackPath to an options bag so we can carry contextKey. Only one callsite, updated in /github/link/route.ts.
  • No new PII is persisted — the Redis context only contains already-serialized thread/message payloads that were already written by the Slack flow under the same LINK_ACCOUNT_CONTEXT_KEY_PREFIX.

Mirrors the Slack link-account UX: when an unlinked GitHub user mentions
the bot, the thread + message is stashed under a Redis contextKey that
rides through the link token and OAuth state, so the callback can
auto-replay the original comment instead of asking the user to mention
Kilo again.
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