Repository navigation
Conversation
The Lark SDK's default token cache is process-global, so a long-lived feishuConn kept reusing an expired tenant access token after 99991663. A retry marked Retryable therefore kept failing with the same stale token and the bot never recovered (Tencent#1485). Give each feishuConn client its own token cache and rebuild client+cache when a reply is rejected with an invalid/missing access-token code (99991661/63/ 64/68), so the next retry fetches a fresh token. Rate-limit (99991400) and server/transport failures leave the client unchanged. Part of Tencent#1485; does not close the issue.
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.
fix(bot): refresh Feishu tenant token after invalid-token reply
This is the #1485 slice: recover the Feishu bot after its tenant access token expires.
Problem
The Feishu long-connection channel keeps a
feishuConnalive with one Lark client. The SDK's default token cache is process-global, so an expired tenant token stayed cached. Reply attempts rejected with 99991663 were marked Retryable, but the retry reused the same client and stale token — the bot never recovered until restart.(The Push path creates a fresh client per call and was unaffected.)
Change
internal/botinteraction/channel_feishu.goclient()accepts optional extra Lark options (existing callers unchanged).feishuTokenCache— a client-scopedlarkcore.Cachewith mutex + TTL.feishuConnstores its credential and guardsapiwith a mutex;freshAPI()builds a client with an empty token cache;resetAPI()swaps it in.Replyresets the client only on invalid/missing access-token codes (99991661/63/64/68). Rate-limit (99991400) and 5xx/transport failures leave the client untouched.No credential-model change; no front-end change.
Verification (Linux/amd64, Docker
python:3.12-slim)internal/botinteractionfull package: PASS.go vet(including copylocks),git diff --check, secret scan: clean. Windows cannot compile (Linux-specific syscalls); Go tests were cross-compiled and run in the container.Scope / notes
WithTokenCachereplaces a package-level token manager; keys include appID+secret, so bots do not share tokens. The only side effect is that a later default client may reuse the most recent conn's cache (one extra token fetch at most); documented in the handoff report.