Skip to content

feat: detect silently-lapsed login state and alert the user - #46

Open
Firegoiste wants to merge 1 commit into
Wechat-ggGitHub:mainfrom
Firegoiste:feat/detect-silent-session-expiry
Open

feat: detect silently-lapsed login state and alert the user#46
Firegoiste wants to merge 1 commit into
Wechat-ggGitHub:mainfrom
Firegoiste:feat/detect-silent-session-expiry

Conversation

@Firegoiste

Copy link
Copy Markdown

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 getUpdates keeps returning HTTP 200, but the server stops delivering messages. The existing onSessionExpired only fires on ret: -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:

msgs field get_updates_buf
healthy idle [] (empty array) non-empty (fresh cursor)
expired absent empty / missing

(ret is undefined in both, so it can't distinguish them.)

monitor.ts now counts consecutive expired-shaped responses. After 3 in a row it fires a new optional onSessionLikelyExpired callback. A single healthy response resets the counter and re-arms the alert, so:

  • a one-off network blip never trips it, and
  • a genuinely quiet-but-healthy night never false-positives (a healthy idle poll always carries a fresh cursor).

main.ts surfaces the alert via an out-of-band desktop notification (Windows toast / macOS osascript / Linux notify-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 setupnpm run daemon -- restart).

Compatibility

Pure addition: the new callback is optional (onSessionLikelyExpired?), so existing callers are unaffected. +38 in monitor.ts, +36 in main.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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant