From fa7b0b0a67886f6d50e55d06370434e4f84ebb00 Mon Sep 17 00:00:00 2001 From: sprmn24 Date: Mon, 27 Apr 2026 22:37:15 +0300 Subject: [PATCH] fix(discord_tool): key capability cache by token instead of single global _capability_cache was a single module-level dict shared across all tokens. If the bot token rotates or multiple tokens are used in one process, capabilities detected for token A would be returned for token B, causing wrong schema gating and incorrect runtime behavior. Replace the single Optional cache with a Dict keyed by token so each token gets its own isolated capability entry. --- tools/discord_tool.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/discord_tool.py b/tools/discord_tool.py index 88e8c9fb2..589b70222 100644 --- a/tools/discord_tool.py +++ b/tools/discord_tool.py @@ -132,7 +132,7 @@ def _channel_type_name(type_id: int) -> str: # --------------------------------------------------------------------------- # Module-level cache so the app/me endpoint is hit at most once per process. -_capability_cache: Optional[Dict[str, Any]] = None +_capability_cache: Dict[str, Dict[str, Any]] = {} def _detect_capabilities(token: str, *, force: bool = False) -> Dict[str, Any]: @@ -148,8 +148,8 @@ def _detect_capabilities(token: str, *, force: bool = False) -> Dict[str, Any]: Cached in a module-global. Pass ``force=True`` to re-fetch. """ global _capability_cache - if _capability_cache is not None and not force: - return _capability_cache + if token in _capability_cache and not force: + return _capability_cache[token] caps: Dict[str, Any] = { "has_members_intent": True, @@ -172,14 +172,14 @@ def _detect_capabilities(token: str, *, force: bool = False) -> Dict[str, Any]: "Discord capability detection failed (%s); exposing all actions.", exc, ) - _capability_cache = caps + _capability_cache[token] = caps return caps def _reset_capability_cache() -> None: """Test hook: clear the detection cache.""" global _capability_cache - _capability_cache = None + _capability_cache = {} # ---------------------------------------------------------------------------