Skip to content

fix(gateway): harden Telegram polling conflict handling#1339

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-048e6599
Mar 14, 2026
Merged

fix(gateway): harden Telegram polling conflict handling#1339
teknium1 merged 1 commit into
mainfrom
hermes/hermes-048e6599

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

  • detect Telegram long-polling conflicts explicitly and stop polling cleanly instead of retrying forever
  • add a machine-local token-scoped gateway lock so different HERMES_HOME profiles on the same host cannot poll the same Telegram bot token at once
  • persist gateway runtime health/fatal adapter state in gateway_state.json
  • surface recent fatal gateway health in hermes gateway status
  • shut down cleanly on non-retryable startup conflicts so services do not thrash on restart loops

Why

A user-provided log archive showed the gateway spending hours in repeated telegram.error.Conflict: terminated by other getUpdates request failures. The current behavior keeps retrying and spamming logs, which looks like a random gateway stop to non-technical users.

This PR makes the conflict explicit, prevents same-host duplicate pollers when possible, and gives the CLI a persistent explanation of what happened.

Test plan

  • python -m pytest tests/gateway/test_status.py tests/gateway/test_telegram_conflict.py tests/gateway/test_runner_fatal_adapter.py tests/hermes_cli/test_gateway_runtime_health.py -n0 -q
  • python -m pytest tests/gateway/ tests/hermes_cli/test_gateway_runtime_health.py -n0 -q
  • python -m pytest tests/ -n0 -q

- detect Telegram getUpdates conflicts and stop polling cleanly instead of retry-spamming forever
- add a machine-local token-scoped lock so different HERMES_HOME profiles on the same host can't poll the same bot token at once
- persist gateway runtime health/fatal adapter state and surface it in ● hermes-gateway.service - Hermes Agent Gateway - Messaging Platform Integration
     Loaded: loaded (/home/teknium/.config/systemd/user/hermes-gateway.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-03-14 09:25:35 PDT; 2h 45min ago
 Invocation: 8879379b25994201b98381f4bd80c2af
   Main PID: 1147926 (python)
      Tasks: 16 (limit: 76757)
     Memory: 151.4M (peak: 168.1M)
        CPU: 47.883s
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/hermes-gateway.service
             ├─1147926 /home/teknium/.hermes/hermes-agent/venv/bin/python -m hermes_cli.main gateway run --replace
             └─1147966 node /home/teknium/.hermes/hermes-agent/scripts/whatsapp-bridge/bridge.js --port 3000 --session /home/teknium/.hermes/whatsapp/session --mode self-chat

Mar 14 09:27:03 teknium-dev python[1147926]: 🔄 Retrying API call (2/3)...
Mar 14 09:27:04 teknium-dev python[1147926]: [409B blob data]
Mar 14 09:27:04 teknium-dev python[1147926]:    Content: ''
Mar 14 09:27:04 teknium-dev python[1147926]: ❌ Max retries (3) for empty content exceeded.
Mar 14 09:27:07 teknium-dev python[1147926]: [1K blob data]
Mar 14 09:27:07 teknium-dev python[1147926]:    Content: ''
Mar 14 09:27:07 teknium-dev python[1147926]: 🔄 Retrying API call (1/3)...
Mar 14 09:27:12 teknium-dev python[1147926]: [1.7K blob data]
Mar 14 09:27:12 teknium-dev python[1147926]:    Content: ''
Mar 14 09:27:12 teknium-dev python[1147926]: 🔄 Retrying API call (2/3)...
⚠ Installed gateway service definition is outdated
  Run: hermes gateway restart  # auto-refreshes the unit

✓ Gateway service is running
✓ Systemd linger is enabled (service survives logout)
- cleanly exit non-retryable startup conflicts without triggering service restart loops

Tests:
- gateway status runtime-state helpers
- Telegram token-lock and polling-conflict behavior
- GatewayRunner clean exit on non-retryable startup conflict
- CLI runtime health summary
@teknium1 teknium1 merged commit a748257 into main Mar 14, 2026
1 check passed
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…048e6599

Merging Telegram gateway conflict hardening: same-host token lock, clean shutdown on getUpdates conflict, persisted runtime health, and clearer gateway status diagnostics.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…048e6599

Merging Telegram gateway conflict hardening: same-host token lock, clean shutdown on getUpdates conflict, persisted runtime health, and clearer gateway status diagnostics.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…048e6599

Merging Telegram gateway conflict hardening: same-host token lock, clean shutdown on getUpdates conflict, persisted runtime health, and clearer gateway status diagnostics.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…048e6599

Merging Telegram gateway conflict hardening: same-host token lock, clean shutdown on getUpdates conflict, persisted runtime health, and clearer gateway status diagnostics.
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