fix: use per-appId token cache for multi-account support#86
Open
tangyoha wants to merge 1 commit intosliverp:mainfrom
Open
fix: use per-appId token cache for multi-account support#86tangyoha wants to merge 1 commit intosliverp:mainfrom
tangyoha wants to merge 1 commit intosliverp:mainfrom
Conversation
The previous implementation used a single global cachedToken variable, causing multiple QQ Bot accounts to share the same access token. This led to authentication failures when Bot A tried to send messages using Bot B's token. Changes: - Replace global cachedToken with Map<string, TokenCache> keyed by appId - Replace global tokenFetchPromise with Map<string, Promise<string>> - Update getAccessToken() to cache tokens per appId - Update clearTokenCache() to support clearing specific appId or all - Update getTokenStatus() to accept appId parameter - Update background token refresh to use per-appId cache This ensures each bot account maintains its own token cache, fixing the 500 Internal Server Error (code 11255) that occurred when multiple accounts were configured. Fixes multi-account token authentication issue.
|
Can't wait to use this feature! |
|
太棒了。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When configuring multiple QQ Bot accounts in OpenClaw, the second bot fails to send messages with a
500 Internal Server Error(error code 11255).Root Cause
The
api.tsmodule uses a globalcachedTokenvariable that is shared across all bot accounts:This causes:
Evidence
From Gateway logs:
Bot 1 fails with:
{ "code": 11255, "message": "Internal Server Error" }Solution
Replace the global token cache with a per-appId Map:
Changes Made
Map<string, TokenCache>keyed byappIdMap<string, Promise<string>>to prevent concurrent token fetches per appIdappIdparameter to clear specific account or all accountsappIdparameter to check specific account statusTesting
Tested with 2 QQ Bot accounts:
Before fix:
After fix:
Gateway logs confirm separate tokens:
Impact
getTokenStatus()now requiresappIdparameterRelated Issues
This is a similar bug pattern found in other OpenClaw plugins:
Checklist
npm run build)