Skip to content

bug: Telegram bot token β€” operator approval prompt repeats on every message and multiplies, no agent reply (staging regression)Β #4381

Description

@Al629176

Summary

On the staging build, the "Use your own Bot Token" Telegram path is broken end-to-end. Every message triggers repeated "πŸ”’ This bot requires operator approval" prompts, no agent reply is ever delivered, and the duplicate count grows with each message. The "Login with OpenHuman" path works correctly and is unaffected.

Problem

This is a regression of #1948 (closed as fixed in v0.53.x). The new behaviour is worse:

This pattern β€” increasing duplicate count across messages β€” points to a listener or subscription being registered on each inbound message without being deregistered, so each new message is handled by an increasing number of handler instances.

UI shows Connected throughout when the bot token path is active, confirming the session is established but the approval-state resolution is broken.

Scope

Path Status Working?
Login with OpenHuman Connected βœ… Works correctly
Use your own Bot Token Disconnected β†’ Connected ❌ Broken β€” approval loop, no agent reply

The bug is isolated to the bot token path. The shared Telegram path (Login with OpenHuman) is unaffected, which narrows the root cause to the bot-token-specific connection, polling, and approval-gate code paths.

Steps to reproduce

  1. Settings β†’ Connections β†’ Telegram
  2. Ignore "Login with OpenHuman" (working) β€” scroll to "Use your own Bot Token"
  3. Paste a bot token from @Botfather; optionally fill Chat ID and Allowed Users
  4. Click Connect β€” status becomes Connected
  5. In Telegram, send `/start` β†’ receive approval prompt
  6. Send any further message (e.g. `wassup`, `hi`)
  7. Observe: approval prompt fires again per message; no agent reply; duplicate count grows

Expected behaviour

  • After connecting with a bot token, messages from users in Allowed Users (or the first sender after `/start`) route to the OpenHuman agent and receive a reply.
  • The approval prompt fires at most once for a new/unapproved sender β€” never on repeat for the same session.
  • No duplicate messages.

Actual behaviour (staging)

  • Every message triggers `πŸ”’ This bot requires operator approval` + `ℹ️ If operator provides a one-time pairing code, run /bind `
  • No agent reply is delivered at any point
  • Duplicate count grows per message (`hi` β†’ 2Γ— each vs `wassup` β†’ 1Γ—)

Hypothesis

Two compounding issues, both specific to the bot token path:

  1. Approval state not persisting / stale read β€” The approval gate re-evaluates on every message and never resolves to "approved", even when UI shows Connected. The Allowed Users list or pairing state is either not written on connect or read from a stale scope in the bot-token handler (the Login with OpenHuman path resolves this correctly, so the shared approval logic is likely fine β€” the bug is in how the bot-token path writes/reads session state).

  2. Listener leak (growing duplicate count) β€” The bot-token update poller registers a new handler per inbound message without deregistering the old one (structurally similar to #1948 and #1648). Each message is processed by N+1 handlers, producing N+1 approval responses.

Environment

  • Build: staging
  • Channel: Telegram β†’ Use your own Bot Token
  • "Login with OpenHuman" path: working correctly (unaffected)
  • Platform: macOS (confirmed from screenshot)

Acceptance criteria

  • No spurious approval prompts β€” A message from an approved sender does not trigger the approval prompt on subsequent messages.
  • Agent reply delivered β€” Messages via bot token path route to the OpenHuman agent and return a reply, matching the behaviour of the Login with OpenHuman path.
  • No duplicate messages β€” Each inbound Telegram update produces exactly one approval check and, if approved, one agent response.
  • Listener lifecycle correct β€” Bot-token update handlers register once per connection and deregister on disconnect; handler count does not grow per message.
  • Pairing state persists β€” Approval/pairing state survives for the duration of the connection without reverting on each message.
  • Login with OpenHuman unaffected β€” No regression on the working path.
  • Diff coverage β‰₯ 80% β€” Fix PR meets the changed-lines coverage gate.

Related

  • Original duplicate-approval bug (closed, now regressed): #1948
  • Reply duplication fix referenced in #1948: #1648
  • Telegram + Discord channels broken (closed): #3712

Metadata

Metadata

Labels

bugpriority: highBreaks a specific featurestagingReproduces on staging build

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions