Skip to content

fix(bot): silence "Aborted delay" polling log on Ctrl+C shutdown#464

Merged
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-460-f46b254644bf
Apr 29, 2026
Merged

fix(bot): silence "Aborted delay" polling log on Ctrl+C shutdown#464
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-460-f46b254644bf

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Apr 29, 2026

Summary

When the agent is stopped (Ctrl+C), Grammy's bot.stop() aborts the polling loop's pending long-poll delay through an AbortController. The resulting rejection surfaces in DealBot.start()'s .catch(...) handler and was being logged as:

[Bot] Polling error
  err: { type: "Error", message: "Aborted delay", stack: ... at Bot.stop (...grammy/out/bot.js:341) }

This is misleading — it looks like a real failure but is just Grammy's normal shutdown signal. The annoyance was especially visible on the MTProxy path, where the shutdown sequence is slower.

This PR adds a stopping flag to DealBot that is set inside stop(). The .catch handler in start() now suppresses the log when the rejection arrives during shutdown. Real polling failures during normal operation continue to be logged.

Changes

  • src/bot/index.ts: track stopping and skip the [Bot] Polling error log when the rejection arrives during a shutdown.
  • src/bot/__tests__/deal-bot-shutdown.test.ts (new): regression tests covering both the suppressed-during-shutdown case and the still-logged-during-runtime case.
  • CHANGELOG.md: note under [Unreleased] / Fixed.
  • package.json: bump to 0.8.17.

How to reproduce (before this PR)

  1. Configure mtproto.enabled: true with at least one proxy.
  2. npm start, wait for [Bot] @… polling started.
  3. Press Ctrl+C.
  4. Observe ERROR: [Bot] Polling error … Aborted delay followed (after SHUTDOWN_TIMEOUT_MS) by Shutdown timed out, forcing exit.

After this PR, the Polling error line is gone — stopping is silent on the polling channel.

Test plan

  • npm run lint — no errors
  • npm run typecheck — no errors
  • npm test — 3498/3498 passing, including the two new shutdown tests in src/bot/__tests__/deal-bot-shutdown.test.ts
  • npm run format:check — clean
  • Manual: run agent with MTProxy, Ctrl+C, confirm no [Bot] Polling error … Aborted delay line appears

Fixes #460

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#460
Grammy's bot.stop() aborts the polling loop's pending delay via
AbortController. The error surfaces as a rejected bot.start() promise
and was logged as "[Bot] Polling error", confusing users who simply
stopped the agent — especially noticeable with MTProxy enabled where
the shutdown path is slower.

DealBot now tracks a `stopping` flag set by stop() and skips the
error log when the rejection arrives during shutdown. Real polling
failures during normal operation continue to be logged.

Closes xlabtg#460
@konard konard changed the title [WIP] ERROR: [Bot] Polling error fix(bot): silence "Aborted delay" polling log on Ctrl+C shutdown Apr 29, 2026
@konard konard marked this pull request as ready for review April 29, 2026 09:20
@konard
Copy link
Copy Markdown
Author

konard commented Apr 29, 2026

Solution summary

Both CI runs passed. Summary:

Root cause: Grammy's Bot.stop() aborts the polling loop's pending long-poll delay via an AbortController. The rejection (Aborted delay) propagates through the bot.start() Promise into DealBot.start()'s .catch(...) handler at src/bot/index.ts:541, where it was logged as [Bot] Polling error — making a normal Ctrl+C look like a crash, particularly with MTProxy enabled.

Fix (commit 024d1a1):

  • src/bot/index.ts: added a stopping flag set inside stop(); the .catch in start() skips the error log when it fires during shutdown.
  • src/bot/__tests__/deal-bot-shutdown.test.ts: two regression tests — silent during shutdown, still logged during runtime.
  • CHANGELOG.md entry under [Unreleased] / Fixed.
  • package.json bumped to 0.8.17.

Verification: lint clean, typecheck clean, format clean, full suite 3498/3498 passing, both upstream CI runs green.

PR: #464 (now ready for review).


This summary was automatically extracted from the AI working session output.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 29, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $3.207598

📊 Context and tokens usage:

  • 93.5K / 1M (9%) input tokens, 19.3K / 128K (15%) output tokens

Total: (90.3K + 4.3M cached) input tokens, 19.3K output tokens, $3.207599 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Model: Claude Opus 4.7 (claude-opus-4-7)

📎 Log file uploaded as Gist (1701KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 29, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@xlabtg xlabtg merged commit 62ffa30 into xlabtg:main Apr 29, 2026
18 checks passed
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.

ERROR: [Bot] Polling error

2 participants