Skip to content

fix: cool down transient Telegram typing failures#46355

Merged
teknium1 merged 3 commits into
mainfrom
openclaw-port/telegram-typing-cooldown
Jul 7, 2026
Merged

fix: cool down transient Telegram typing failures#46355
teknium1 merged 3 commits into
mainfrom
openclaw-port/telegram-typing-cooldown

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Telegram typing indicators now back off per chat after transient sendChatAction failures instead of retrying every keep-typing tick.

Port from openclaw/openclaw#93020. OpenClaw added cooldown handling for transient Telegram typing-action failures; Hermes adapts that at the gateway adapter boundary with Python Telegram Bot semantics.

Changes

  • gateway/platforms/telegram.py: records per-chat cooldowns for network errors, 429/retry-after, and 5xx-ish failures; clears cooldowns on successful typing sends.
  • Keeps DM-topic fallback behavior intact, and only cools down on transient failures rather than bad thread/user errors.
  • tests/gateway/test_telegram_typing_backoff.py: covers cooldown entry, cooldown expiry/success clearing, DM-topic fallback, and non-transient thread failures.

Validation

Check Result
Targeted pytest 28 passed
Project wrapper scripts/run_tests.sh tests/gateway/test_telegram_typing_backoff.py tests/gateway/test_keep_typing_timeout.py tests/gateway/test_telegram_approval_buttons.py28 tests passed
E2E Temp HERMES_HOME, real TelegramAdapter, mocked Bot API: transient failure suppressed second send; success after expiry cleared cooldown

Source

Infographic

Telegram typing cooldown

@teknium1
teknium1 marked this pull request as ready for review June 15, 2026 00:08
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: openclaw-port/telegram-typing-cooldown vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10903 on HEAD, 10904 on base (✅ -1)

🆕 New issues (2):

Rule Count
unresolved-import 1
invalid-assignment 1
First entries
tests/gateway/test_telegram_typing_backoff.py:7: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`

✅ Fixed issues (2):

Rule Count
unresolved-attribute 2
First entries
run_agent.py:2920: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`

Unchanged: 5733 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@liuhao1024

Copy link
Copy Markdown
Contributor

Verified ✅ — well-structured typing backoff with correct per-chat scoping.

Reviewed the full diff (2 files + 1 test file, ~340 lines).

What I checked:

  • Cooldown is per-chat (Dict[str, float]) — transient failures on one chat don't suppress typing on others.
  • _is_transient_typing_error() correctly targets 429, 5xx, retry_after, TimeoutError, ConnectionError, and asyncio.TimeoutError. Non-transient errors (400, 403) are correctly excluded.
  • Cooldown clears on success (pop in send_typing success path and both fallback paths).
  • DM topic fallback path correctly checks _is_transient_typing_error(fallback_exc) — a bad thread ID (non-transient) doesn't trigger cooldown.
  • _coerce_float_extra has proper min_value/max_value clamping (1.0–300.0).
  • Three test cases cover: transient failure → cooldown → expiry, DM fallback success → no cooldown, non-transient failure → no cooldown.
  • Config key typing_cooldown_seconds is properly exposed via PlatformConfig.extra.
  • No asyncio.get_running_loop() called outside async context.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists labels Jun 15, 2026
@teknium1
teknium1 force-pushed the openclaw-port/telegram-typing-cooldown branch from 47010a7 to a4fb69e Compare July 6, 2026 09:24
teknium1 added 3 commits July 7, 2026 02:07
Port from openclaw/openclaw#93020: add per-chat cooldown for transient sendChatAction failures so keep-typing refreshes do not hammer Telegram during network blips or rate limits.
The Telegram adapter moved from gateway/platforms/telegram.py to
plugins/platforms/telegram/adapter.py since this branch was created;
point the test imports and monkeypatch targets at the new module.
@teknium1
teknium1 force-pushed the openclaw-port/telegram-typing-cooldown branch from a4fb69e to 57a6a5d Compare July 7, 2026 09:09
@teknium1
teknium1 merged commit a796e0b into main Jul 7, 2026
31 checks passed
@teknium1
teknium1 deleted the openclaw-port/telegram-typing-cooldown branch July 7, 2026 09:39
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
* fix: cool down transient Telegram typing failures

Port from openclaw/openclaw#93020: add per-chat cooldown for transient sendChatAction failures so keep-typing refreshes do not hammer Telegram during network blips or rate limits.

* fix: support bare Telegram adapters in typing cooldown

* test: update typing backoff imports for relocated Telegram adapter

The Telegram adapter moved from gateway/platforms/telegram.py to
plugins/platforms/telegram/adapter.py since this branch was created;
point the test imports and monkeypatch targets at the new module.
justemu pushed a commit to justemu/hermes-agent that referenced this pull request Jul 18, 2026
* fix: cool down transient Telegram typing failures

Port from openclaw/openclaw#93020: add per-chat cooldown for transient sendChatAction failures so keep-typing refreshes do not hammer Telegram during network blips or rate limits.

* fix: support bare Telegram adapters in typing cooldown

* test: update typing backoff imports for relocated Telegram adapter

The Telegram adapter moved from gateway/platforms/telegram.py to
plugins/platforms/telegram/adapter.py since this branch was created;
point the test imports and monkeypatch targets at the new module.
tangdaibin pushed a commit to tangdaibin/hermes-agent that referenced this pull request Jul 20, 2026
* fix: cool down transient Telegram typing failures

Port from openclaw/openclaw#93020: add per-chat cooldown for transient sendChatAction failures so keep-typing refreshes do not hammer Telegram during network blips or rate limits.

* fix: support bare Telegram adapters in typing cooldown

* test: update typing backoff imports for relocated Telegram adapter

The Telegram adapter moved from gateway/platforms/telegram.py to
plugins/platforms/telegram/adapter.py since this branch was created;
point the test imports and monkeypatch targets at the new module.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
* fix: cool down transient Telegram typing failures

Port from openclaw/openclaw#93020: add per-chat cooldown for transient sendChatAction failures so keep-typing refreshes do not hammer Telegram during network blips or rate limits.

* fix: support bare Telegram adapters in typing cooldown

* test: update typing backoff imports for relocated Telegram adapter

The Telegram adapter moved from gateway/platforms/telegram.py to
plugins/platforms/telegram/adapter.py since this branch was created;
point the test imports and monkeypatch targets at the new module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants