Skip to content

fix(oauth): evict cached installations for a workspace on save_bot - #2090

Merged
WilliamBergamin merged 2 commits into
mainfrom
fix/cacheable-store-save-bot-eviction
Nov 30, 2026
Merged

WilliamBergamin merged 2 commits into
mainfrom
fix/cacheable-store-save-bot-eviction

Conversation

@WilliamBergamin

@WilliamBergamin WilliamBergamin commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request makes save_bot() in the cacheable installation stores (sync and async) evict every cached installation for the workspace, so per-user lookups stop returning an old bot token after a bot-only token rotation. Fixes #2089, thanks @student-shivamm for the report and repro.

  • Cause: save_bot() only evicted the cached bot. The built-in stores merge the latest bot into per-user find_installation() results, so those cached entries kept the old token.
  • Fix: save() and save_bot() now share one _evict_team_cache() helper, which clears the team's cached bot and all of its cached installations (the same eviction save() got in fix(oauth): evict every cached installation for a workspace on save #2051).
  • Where it matters: Bolt calls save_bot(refreshed_bot) on bot-only token rotation (authorize.py / async_authorize.py).

Testing

The new sync and async tests fail on main and pass here. They also check that a neighboring team (T1111) stays cached, so eviction can't spill over to other workspaces.

To check by hand, run the snippet from #2089 on this branch: the backend and the cache now both print the new token.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

🤖 Generated with Claude Code

save_bot() and async_save_bot() evicted only the cached bot, so cached
per-user installations kept serving the old bot token after a bot-only
token rotation. Evict the workspace's installation prefix, the same way
save() does since #2051.

Fixes #2089

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.91%. Comparing base (4ae2f75) to head (03eff62).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2090      +/-   ##
==========================================
+ Coverage   84.85%   84.91%   +0.05%     
==========================================
  Files         118      118              
  Lines       14137    14133       -4     
==========================================
+ Hits        11996    12001       +5     
+ Misses       2141     2132       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@WilliamBergamin WilliamBergamin left a comment

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.

🧪 The new sync and async tests fail on main and pass here, and no signature, export, or default changes, so anyone using the cacheable stores keeps working without changes. Left two optional comments, nothing blocking 💯


store.save_bot(build_installation(user_id="U111", bot_token="xoxb-refreshed").to_bot())
i = store.find_installation(enterprise_id="E111", team_id="T111", user_id="U111")
self.assertEqual(i.bot_token, "xoxb-refreshed")

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.

🧪 suggestion (non-blocking): Could we also cache a second workspace (say T222) and assert it survives save_bot()? That pins the trailing - in the prefix, so over-eviction can't slip in.


await store.async_save_bot(build_installation(user_id="U111", bot_token="xoxb-refreshed").to_bot())
i = await store.async_find_installation(enterprise_id="E111", team_id="T111", user_id="U111")
self.assertEqual(i.bot_token, "xoxb-refreshed")

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.

🧪 suggestion (non-blocking): Same here, a second cached workspace that survives async_save_bot().

save() and save_bot() ran the same eviction block in both cacheable
stores. They now call one _evict_team_cache helper, so a future key fix
lands once.

The save_bot tests also cache a second team, T1111, and assert it
survives. T1111 is used over T222 because its key starts with
"E111-T111", so the assertion fails if the prefix loses its trailing "-".

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch oauth labels Nov 30, 2026
@WilliamBergamin WilliamBergamin added this to the 3.48.1 milestone Nov 30, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review November 30, 2026 16:33
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner November 30, 2026 16:33

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ Thanks @WilliamBergamin, sharing one helper between save() and save_bot() means token rotation and reinstalls now clear the cache the same way, and the T1111 check keeps neighbouring workspaces safe.

key = f"{bot.enterprise_id or ''}-{bot.team_id or ''}"
if key in self.cached_bots:
self.cached_bots.pop(key)
self._evict_team_cache(bot.enterprise_id, bot.team_id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

note: The evict-after-save follow-up from #2051 applies here too: a lookup that lands during this await can cache the old bot again. Fine to keep it for that follow-up and not hold this PR.

@WilliamBergamin
WilliamBergamin merged commit 01a4d2b into main Nov 30, 2026
19 checks passed
@WilliamBergamin
WilliamBergamin deleted the fix/cacheable-store-save-bot-eviction branch November 30, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented oauth semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

save_bot leaves cached user installations with stale bot tokens

2 participants