zai-org / zai-org/feedback

[Bug] 飞书 Bot:应用连续运行约 2 小时后停止回复(tenant_access_token 过期不刷新,HTTP 400 code=99991663)

Open
#586 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

问题类别 · Category

Bug — ZCode Desktop 内置 Bot Channel(飞书 / Lark)

涉及的 Agent 框架 · Agent framework

不涉及外部框架,ZCode Desktop 自带飞书 Bot(websocket 长连接接收,replyMode=streaming_card)

严重程度 · Severity

高:bot 功能完全不可用,且进程内无任何自愈路径,只能重启应用

复现频率 · Reproducibility

稳定复现:应用连续运行超过约 2 小时(token TTL)后,第一条飞书消息起全部失败

问题描述 · Description

ZCode Desktop 的飞书 Bot 收发链路分离:走 websocket 长连接(连接期鉴权,一直正常),走 REST API + tenant_access_token。tenant_access_token 有效期 2 小时,当前实现在过期后不主动刷新,收到 99991663 后也不重新获取 token,失效 token 缓存在 REST 客户端内,websocket 自动重连也救不回来。用户侧表现为"飞书发消息 bot 完全没反应"。

本地日志可确认的版本足迹显示这是 3.10.2 引入的回归(3.9.2 / 3.10.1 正常,见下)。

复现步骤 · Steps to reproduce
  1. 配置飞书 Bot(长连接模式),确认收发正常
  2. 保持 ZCode Desktop 连续运行约 2 小时(期间可以正常使用)
  3. 从飞书发任意消息
  4. bot 收到消息(日志有 provider callback)但零回复
期望表现 · Expected behavior
  • token 到期前主动刷新(TTL 7200s,提前数分钟刷新即可)
  • 或收到 99991663 时强制丢弃缓存 token、重新获取并重试一次
  • 启动时 token 获取失败(如机器刚开机 DNS 未就绪)应有重试
实际表现 · Actual behavior

所有出站调用失败并熔断,直到重启应用:

[2026-09-09 15:50:16] [bots] Feishu streaming card sync failed ... failures=1 retryDelayMs=1000: Feishu send interactive message failed: HTTP 400, code=99991663, msg=Invalid access token for authorization. Please make a request with token attached.
[2026-09-09 15:50:17] ... failures=2 ...
[2026-09-09 15:50:19] [bots] Feishu streaming card circuit opened ... failures=3: ... 99991663 ...

日志位置:~/.zcode/v2/logs/<date>.log(grep 99991663 / provider callback)。

版本相关性(疑似 3.10.2 回归)

每小时 update 检查日志行会打印运行版本,据此还原:

日期 运行版本 飞书 bot 使用情况 99991663 次数
08-27 / 08-28 3.9.2 单日 10:06→17:07 连续使用 0
08-29 ~ 08-31 3.10.1 单日最长 09:15→20:25(11h)跨天使用 0
09-01 起 3.10.2 09-02 11:19 首次出现该错误 09-02/04/05/09 共 4 天出现

3.9.2 / 3.10.1 期间 bot 每天跨 7~11 小时使用零故障,说明旧版 token 刷新正常;3.10.2(09-01 前后安装)起每次故障都符合"距 token 获取约 2 小时"模式,3.11.2 仍存在。

另一触发形态佐证 token 生命周期管理问题:机器重启后应用自启时 DNS 未就绪(getaddrinfo ENOTFOUND open.feishu.cn),启动时取 token 失败,之后一直使用无效 token,同样只能重启恢复。

关键时间线(2026-09-09):

  • 13:25:46 重启应用 → 13:26~15:24 飞书收发全部正常
  • 15:50:16(距启动 2h25m)起所有发送 99991663,15:52 / 15:58 消息全部无法回复
  • 15:51 飞书 websocket 自动重连(runtime 锁重建成功),发送仍失败 → 失效 token 不在 websocket 层,在 REST 客户端缓存里
临时规避 · Workaround

重启 ZCode Desktop(恢复约 2 小时后复发)。

环境
  • ZCode Desktop 3.11.2(此前在 3.10.2 上同样复现)
  • macOS 25.6.0 arm64(Apple Silicon)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the ZCode Desktop Feishu Bot REST client and its tenant_access_token cache; the issue does not name source files or tests. Reproduce with the logs in ~/.zcode/v2/logs/.log, then verify that expiry or HTTP 400 code=99991663 triggers token recovery and that outbound replies resume without restarting the app.

Written by the indexing model from the issue text.

Assessment

Domain
api, authentication, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.