Repository navigation
fix(oauth): evict cached installations for a workspace on save_bot - #2090
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. |
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧪 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") |
There was a problem hiding this comment.
🧪 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") |
There was a problem hiding this comment.
🧪 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>
mwbrooks
left a comment
There was a problem hiding this comment.
✅ 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) |
There was a problem hiding this comment.
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.
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.save_bot()only evicted the cached bot. The built-in stores merge the latest bot into per-userfind_installation()results, so those cached entries kept the old token.save()andsave_bot()now share one_evict_team_cache()helper, which clears the team's cached bot and all of its cached installations (the same evictionsave()got in fix(oauth): evict every cached installation for a workspace on save #2051).save_bot(refreshed_bot)on bot-only token rotation (authorize.py/async_authorize.py).Testing
The new sync and async tests fail on
mainand 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
/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