opencode-telegram-bot icon indicating copy to clipboard operation
opencode-telegram-bot copied to clipboard

[Bug]: Chat shows "typing" forever with no output after Telegram flood control breaks the tool-call stream

Open tmz81 opened this issue 1 month ago • 1 comments

What is broken?

During a long, tool-heavy agent run driven from Telegram, the bot stopped delivering any output while the chat kept showing the "typing" indicator for over an hour. The run only ended when the agent itself executed opencode service restart, which the bot reported as a lost run.

From the logs, the trigger is Telegram flood control: after several 429 Too Many Requests, a non-429 network failure on sendMessage marks the tool-call stream as broken, and the bot then silently drops all further streamed output for that session. The session stays busy, so the typing indicator (sendChatAction every 4s) keeps running — the chat looks hung.

Steps to reproduce

  1. Run the bot (v0.26.4, OPENCODE_SERVER_VERSION=v2) attached to a session.
  2. Send a prompt that produces a long, tool-heavy run with many streamed updates (dozens of sendMessage / editMessageText within a few minutes) so the chat exceeds Telegram's flood control.
  3. Observe 429 Too Many Requests: retry after 125/70/38 warnings, then a [ToolCallStreamer] Stream marked as broken ... reason=tool_file_boundary.
  4. From that point no further tool or assistant output reaches the chat, but the chat keeps showing "typing" until the session goes idle.

Reproducibility: seen once in a ~1h run (intermittent, load-dependent).

OS

Linux

Additional context (optional)

Bot version 0.26.4, Node v26.12.0, opencode v2.0.32 (latest).

Timeline (UTC) from ~/.config/opencode-telegram-bot/logs/bot-2026-10-17.log:

[20:01:10] session.promptAsync accepted; session marked busy
[20:04:10] [WARN] [Bot API] Retryable Telegram error on sendMessage, retrying in 125000ms (attempt=1) Error: Too Many Requests: retry after 125
[20:05:04] [WARN] [Bot API] Retryable Telegram error on sendMessage, retrying in 70000ms (attempt=1) Error: Too Many Requests: retry after 70
[20:05:37] [WARN] [Bot API] Retryable Telegram error on sendMessage, retrying in 38000ms (attempt=1) Error: Too Many Requests: retry after 38
[20:21:50] [ERROR] [ToolCallStreamer] Stream marked as broken: session=ses_..., reason=tool_file_boundary, error=Network request for 'sendMessage' failed!
[20:21:50 .. 21:05:19] no bot log output at all while the agent kept running tool calls
[21:05:19] Event stream error ... ClientError: Transport: terminated
[21:05:25] [Bot] Ending the run lost with the OpenCode server: session=ses_..., runningTools=1, reason=opencode_restarted
[21:44:25] next prompt accepted; [21:45:10] [BusyReconciliation] Clearing stale foreground busy state: ... status=not-found

Observations / suspected causes:

  • The typing indicator is summary-aggregation-manager.js#startTypingIndicator — a 4s setInterval(sendChatAction "typing") gated only by the session being busy. It remains active while the send path is dead, so the chat looks like it is still working.
  • In tool-call-streamer.js#syncState, a failure with no retry_after goes straight to markStreamBroken; afterwards hasUnsentMessages / syncState skip that state, so output is dropped with no chat-visible error.
  • response-streamer.js#flushState falls back to plain text before breaking, but tool-call-streamer.js breaks immediately — which is what happened here.
  • Affected session=ses_eb48e4d8fffe4UYhwEE52RtMjp, runningTools=1, reason=opencode_restarted.
  • Separately, the agent ran opencode service restart inside the run (to reload an MCP env var), killing the server mid-run. That is likely user/agent error, but it is also what finally cleared the stuck state.
  • Default settings amplify Telegram traffic (compactOutputMode=false, pinnedDashboardEnabled=true, showThinkingContent=true, responseStreamingMode=edit).
  • Environment diagnostics: opencode v2.0.32 (channel latest); Node v26.12.0; Linux 7.0.0-38-generic x86_64 (Ubuntu); shell/terminal /usr/bin/zsh, xterm-256color; active plugins: none found.

Not a duplicate of #144 (429 during pinned-message creation) or #233 ("Dropped the assistant response").

tmz81 avatar Oct 17 '26 23:10 tmz81

Fixed in https://github.com/grinev/opencode-telegram-bot/releases/tag/v0.28.0

grinev avatar Nov 15 '26 12:11 grinev