Skip to content

fix(telegram): stop /update from looping on every restart#37

Merged
yerzhansa merged 1 commit into
mainfrom
fix/update-notification-loop
Apr 16, 2026
Merged

fix(telegram): stop /update from looping on every restart#37
yerzhansa merged 1 commit into
mainfrom
fix/update-notification-loop

Conversation

@yerzhansa

Copy link
Copy Markdown
Owner

Summary

Two bugs caused "Update available" and "Checking for updates..." / "Updating..." to repeat on every bot startup:

  1. notifyUpdate had no dedup — re-sent the "Update available" message on every restart. Now records the notified version under `{dataDir}/last-notified-version` and skips if already notified for that version.
  2. /update handler exited before committing the Telegram offset — `selfUpdate()` called `process.exit(0)` before grammy could confirm the `/update` message via `getUpdates`, so Telegram re-delivered it on every restart, causing an infinite loop. Fix: call `bot.stop()` first (grammy's stop() commits the offset via `getUpdates({ offset, limit: 1 })`), then run `selfUpdate()`.

Test plan

  • `npm test` — 85/85 pass
  • `npm run check` — typecheck + lint clean
  • After merge + release: trigger /update in Telegram and confirm no message repetition on restart
  • Confirm `last-notified-version` file is created under `~/.cycling-coach/` after the first notification

Two root causes produced the repeated "Update available" / "Checking for
updates..." messages on each startup:

1. notifyUpdate re-sent the "Update available" message on every restart
   because there was no dedup. Now it records the latest notified version
   under {dataDir}/last-notified-version and skips if we've already
   notified about that version.

2. selfUpdate called process.exit(0) before grammy's long-polling loop
   could confirm the /update message by advancing the Telegram offset. On
   restart, Telegram re-delivered /update, triggering an infinite loop.
   Now the handler calls bot.stop() first — grammy's stop() commits the
   offset via getUpdates({ offset, limit: 1 }) — and only then runs
   selfUpdate.
@yerzhansa yerzhansa force-pushed the fix/update-notification-loop branch from 05bdd75 to f17314c Compare April 16, 2026 18:14
@yerzhansa yerzhansa merged commit 19737ff into main Apr 16, 2026
1 check passed
@yerzhansa yerzhansa deleted the fix/update-notification-loop branch April 16, 2026 18:15
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