
用 opencode-telegram-bot 把 opencode 接入 Telegram 是个很方便的方案(详见 上一篇:用 Telegram 远程操控本地 OpenCode:opencode-telegram-bot 实战指南,但最近踩了个坑——bot 突然完全无响应,进程明明在跑,消息就是没有回应。
Bot 无响应的表现有两种:
第二种情况容易误导人,以为是 opencode 进程本身出了问题,实际上根因是一样的。
一切看起来都正常:
ps aux | grep -E "opencode|telegram" | grep -v grep
输出显示三个进程都在运行,opencode serve 也在监听 127.0.0.1:4096。但 Telegram 里发消息,毫无反应。
lsof -i -P -n | grep opencode
opencode serve 正常监听,没问题。
lsof -i -P -n -p <telegram-bot-pid>
这一步发现了关键线索:bot 进程没有任何活跃的 TCP 连接。进程存在,但根本没有连上 Telegram API——也就是说,bot 虽然活着,但处于 " 失联 " 状态。
日志在 ~/Library/Logs/opencode-telegram-bot.log,翻出来一看,全是 429:
[ERROR] [Sessions] Failed to send loading message:
GrammyError: Call to 'sendMessage' failed! (429: Too Many Requests: retry after 26965)
26965 秒,约 7.5 小时。
前一天切换 session 时,bot 短时间内发送了大量消息,触发了 Telegram 的频率限制。被封禁后,bot 尝试重连都会失败,最终陷入静默状态。
事件时间线大概是这样:
时间 | 事件 |
|---|---|
16:18 | 切换 session,大量消息触发 429,retry after 26965 秒 |
16:23 | Compact 操作失败 |
23:39 | 仍被限流(retry after 455 秒),bot 崩溃 |
次日 07:41 | Bot 重启,但网络请求依然失败 |
08:24 | 排查时确认 bot 静默,无任何新日志 |
等限流期过了,重启 bot 就好:
# 干掉当前进程
kill <bot-pid> <npm-pid>
# 重新启动
npm exec @grinev/opencode-telegram-bot start
~/Library/Logs/opencode-telegram-bot.log