fix(channels/wechat-sidecar): recover context_token via librefang_user across sidecar restart#5448
Merged
Merged
Conversation
…r across sidecar restart The in-process `_user_context_tokens[user_id]` cache populated by inbound iLink callbacks vanishes on sidecar restart (any operator upgrade, debug pass, or supervisor respawn). Without the context_token, the bot's first reply after restart posts with an empty token — iLink may reject it or post out-of-thread. Fix: parse_wechat_msg also surfaces `context_token` via `ChannelUser.librefang_user`, which the bridge round-trips bytewise through serde (verified at crates/librefang-channels/src/sidecar.rs:766 inbound, :1204 outbound) so it survives serde + restart cleanly. The in-memory cache stays as the freshness signal (the latest token Lark/ iLink issued is more current than whichever inbound the daemon happens to round-trip back) and takes precedence in on_send. Tests: - New test_on_send_recovers_context_token_from_user_librefang_user_when_cache_cold simulates post-restart (cache empty, cmd.user.librefang_user carries the token) and asserts on_send recovers it. - New test_on_send_ignores_url_shaped_librefang_user pins the cross- channel pollution guard (librefang_user is shared across channels — dingtalk puts a sessionWebhook URL there, telegram puts @username). - cd sdk/python && pytest tests/test_wechat_adapter.py — 63 passed (was 61; +2 regression guards). Surfaces from the #5439-followup audit chain (dingtalk #5423 → qq #5431 → omnibus #5439 → THIS). Same library_user routing pattern, distinct symptom — restart-survivability rather than cap-gate stripping.
This was referenced May 21, 2026
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.
Summary
Runtime hotfix surfaced by the #5439 follow-up audit chain.
WeChat sidecar's in-process `_user_context_tokens[user_id]` cache vanishes on sidecar restart (any operator upgrade, debug pass, or supervisor respawn). Without the cached `context_token`, the bot's first reply after restart posts with an empty token — iLink may reject it or post out-of-thread.
Fix
Mirror the dingtalk #5423 / qq #5431 / omnibus #5439 pattern:
Tests
Cross-reference