Skip to content

fix(oauth): evict every cached installation for a workspace on save - #2051

Merged
WilliamBergamin merged 2 commits into
mainfrom
fix/cacheable-store-stale-installation
Nov 17, 2026
Merged

WilliamBergamin merged 2 commits into
mainfrom
fix/cacheable-store-stale-installation

Conversation

@WilliamBergamin

Copy link
Copy Markdown
Contributor

Summary

This pull request makes CacheableInstallationStore.save() (and the async store) evict every cached installation for the saved workspace, so lookups stop serving an old bot token after a reinstall or token rotation.

  • save() only evicted the exact enterprise-team-user key. The default no-user find_installation() caches under enterprise-team-, so it kept returning the pre-rotation installation.
  • Every built-in store merges the latest bot token into per-user lookups, so other users' cached entries went stale too. The fix evicts the whole enterprise-team- prefix, the same loop delete_installation() already uses.
  • Not covered here: an org-wide Installation that carries a team_id. Its cache key doesn't match find_installation's is_enterprise_install normalization, and the bot-key eviction has the same gap.

Testing

The new tests (sync and async) fail on main and pass on this branch. Wrap a FileInstallationStore in the cache, warm the no-user and U111 lookups, then save a refreshed installation: both lookups return the refreshed bot token. After a U222 install, the U111 lookup returns U222's bot 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

CacheableInstallationStore.save() only evicted the exact enterprise-team-user
key, so the default no-user lookup (cached under enterprise-team-) kept
serving the old bot token after a reinstall or token rotation. Underlying
stores also merge the latest bot token into per-user lookups, so other users'
cached entries went stale too. Evict the whole workspace prefix, as
delete_installation() already does. Same fix in the async store.

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

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.60%. Comparing base (39775bb) to head (658fcfc).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2051      +/-   ##
==========================================
+ Coverage   84.52%   84.60%   +0.08%     
==========================================
  Files         118      118              
  Lines       14044    14046       +2     
==========================================
+ Hits        11871    11884      +13     
+ Misses       2173     2162      -11     

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

@WilliamBergamin WilliamBergamin self-assigned this Nov 17, 2026
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch oauth labels Nov 17, 2026
@WilliamBergamin WilliamBergamin added this to the 3.47.1 milestone Nov 17, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review November 17, 2026 18:25
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner November 17, 2026 18:25

@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! Clearing the whole workspace prefix means a reinstall no longer hands out the old bot token from the no-user lookup.

for key in list(self.cached_installations.keys()):
if key.startswith(key_prefix):
self.cached_installations.pop(key)
return await self.underlying.async_save(installation)

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.

suggestion (non-blocking): Not new in this PR, but a lookup that runs while this await is in flight can cache the old installation again with nothing left to clear it. Evicting after the save too would close that gap, happy for it to be a follow-up.

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.

Good point but lets make this a follow up 🙏

@WilliamBergamin
WilliamBergamin merged commit 1b59fea into main Nov 17, 2026
19 checks passed
@WilliamBergamin
WilliamBergamin deleted the fix/cacheable-store-stale-installation branch November 17, 2026 19:31
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.

2 participants