Repository navigation
fix(oauth): evict every cached installation for a workspace on save - #2051
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files☔ View full report in Codecov by Harness. |
mwbrooks
left a comment
There was a problem hiding this comment.
✅ 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good point but lets make this a follow up 🙏
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 exactenterprise-team-userkey. The default no-userfind_installation()caches underenterprise-team-, so it kept returning the pre-rotation installation.enterprise-team-prefix, the same loopdelete_installation()already uses.Installationthat carries ateam_id. Its cache key doesn't matchfind_installation'sis_enterprise_installnormalization, and the bot-key eviction has the same gap.Testing
The new tests (sync and async) fail on
mainand pass on this branch. Wrap aFileInstallationStorein the cache, warm the no-user andU111lookups, then save a refreshed installation: both lookups return the refreshed bot token. After aU222install, theU111lookup returnsU222's bot token.Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code