feat: detect silently-lapsed login state and alert the user - #46
Open
Firegoiste wants to merge 1 commit into
Open
feat: detect silently-lapsed login state and alert the user#46Firegoiste wants to merge 1 commit into
Firegoiste wants to merge 1 commit into
Conversation
The ilink bot login state can expire with no error code (typically overnight): the token still authenticates and getUpdates keeps returning HTTP 200, but the server stops delivering messages. The existing onSessionExpired only fires on ret:-14, so this silent lapse went unnoticed — the daemon kept polling forever while the user's messages silently went nowhere. A/B comparing a valid vs. an expired token showed the only reliable difference: healthy idle : msgs === [] AND get_updates_buf is a non-empty string expired : msgs is ABSENT AND get_updates_buf is empty/missing monitor.ts now counts consecutive expired-shaped responses and, after 3 in a row (so a one-off blip never trips it; a healthy response re-arms it), fires a new onSessionLikelyExpired callback. main.ts surfaces it via an out-of-band desktop notification (WeChat itself is the dead channel), telling the user to re-scan. Quiet-but-healthy nights never false-positive because a healthy idle poll always carries a fresh cursor.
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.
What
Detects a silently-lapsed login state and alerts the user out-of-band.
Why
The ilink bot login state can expire with no error code (typically overnight): the token still authenticates and
getUpdateskeeps returning HTTP 200, but the server stops delivering messages. The existingonSessionExpiredonly fires onret: -14, so this silent lapse goes completely unnoticed — the daemon polls forever with a frozen cursor while the user's messages silently go nowhere. From the user's side it looks like "I sent a message and nothing ever came back."How
A/B comparing a valid vs. an expired token against
getUpdates(no buf) revealed the only reliable difference in the expired state:msgsfieldget_updates_buf[](empty array)(
retisundefinedin both, so it can't distinguish them.)monitor.tsnow counts consecutive expired-shaped responses. After 3 in a row it fires a new optionalonSessionLikelyExpiredcallback. A single healthy response resets the counter and re-arms the alert, so:main.tssurfaces the alert via an out-of-band desktop notification (Windows toast / macOSosascript/ Linuxnotify-send) — since WeChat itself is the dead channel, an in-band message can't reach the user — telling them to re-scan (node dist/main.js setup→npm run daemon -- restart).Compatibility
Pure addition: the new callback is optional (
onSessionLikelyExpired?), so existing callers are unaffected.+38inmonitor.ts,+36inmain.ts, 0 deletions. Builds clean (npm run build).Testing
Simulated the detection against real response shapes — quiet nights and active chats stay silent; a sustained expired state alerts on the 3rd poll; 1–2 blips followed by recovery never alert. Behavior verified against the live API using both a valid and an actually-expired token.