Skip to content

fix(bot): do not report a busy bot as a Telegram outage - #282

Draft
atn18 wants to merge 1 commit into
grinev:mainfrom
atn18:fix/stale-busy-notice
Draft

atn18 wants to merge 1 commit into
grinev:mainfrom
atn18:fix/stale-busy-notice

Conversation

@atn18

@atn18 atn18 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description of changes

  • A message sent while a long update handler was running waited in grammY's sequential update loop. When it was finally handled, the stale check (older than 60 seconds) dropped it and sent "Some messages were skipped while Telegram was unreachable" - although Telegram had delivered the message and the bot was simply busy.
  • After 5 seconds without chat output the bot now tells the chat it is busy, so the user does not resend into the silence. While the chat keeps receiving progress (for example a session-pick transcript, streaming drafts or edits) the notice waits, and it is re-checked once the chat goes silent.
  • Messages delayed by a long handler are executed after it within 15 seconds; older ones are dropped with a separate honest "the bot was busy" notice. Messages delayed without a busy window keep the existing outage behavior and text.
  • Busy windows are only recorded for handlers that actually ran: an update dropped by the stale check never starts a busy timer.

Closes issue (optional)

  • None

How it was tested

  • npm run lint, npm run build, npm run typecheck, npm test - all green (2825 passed, 7 skipped).
  • New tests: busy-window recording and boundaries (second rounding, TTL, windows kept until the TTL, 14-second recording threshold); the measuring middleware records long handlers, ignores short ones, records when the handler throws, sends the busy notice once after 5 silent seconds, waits while the chat shows progress and re-checks once it stops, and logs a failed notice send without failing the handler; a message delayed by a busy handler within 15 seconds runs, past 15 seconds is dropped with the busy notice, an old message covered by a busy window prefers the busy notice over the outage one, a transport delay without a window runs, and an outage keeps the outage notice; draft sends update the chat-activity timestamp; a mixed burst queues both notices one second apart.
  • PRODUCT.md updated with the two-stage behavior.

Checklist

  • PR title follows Conventional Commits: <type>(<scope>)?: <description>
  • This PR contains one logically complete change
  • Branch is rebased on the latest main
  • I ran npm run lint, npm run build, and npm test
  • If this PR is OS-sensitive, behavior/limitations for Linux/macOS/Windows are described

@atn18
atn18 marked this pull request as draft October 21, 2026 08:07
@atn18
atn18 force-pushed the fix/stale-busy-notice branch 3 times, most recently from d507ffa to c9f147f Compare October 21, 2026 10:51
A message sent while a long update handler was running waited in the
sequential update loop, and once it was finally handled the stale check
dropped it with "Telegram was unreachable" - although Telegram had
delivered it.

After five seconds without chat output the bot now tells the chat it is
busy, so the user does not resend into the silence. Messages delayed by a
busy handler are executed after it within fifteen seconds; older ones are
dropped with a separate "the bot was busy" notice, and messages delayed
without such a window keep the outage notice.
@atn18
atn18 force-pushed the fix/stale-busy-notice branch from c9f147f to 05a429b Compare October 21, 2026 11: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