Repository navigation
fix(lark): 飞书事件先回执再后台处理,并去重防重复触发 - #111
Merged
Merged
Conversation
在 PR #111 基础上修正几处秒回去重的边角: - 卡片动作改用持久 claim(按 event_id):关掉原本 in-flight-only 在处理完成后 被同一交互重投/重复触发导致 restart/close 二次执行的窗口;无 event_id 的回退 仍只用 in-flight 并发保护,不误伤合法重复点击(如 toggle 流式开/关) - 去重 TTL 60min→2h,覆盖 Feishu 15s/5min/1h 重推梯度;新增按时间间隔的剪枝, 让繁忙 bot 的 claim map 不随调用频率无界增长 - 超时分支不再静默吞掉「仅 toast」的慢结果(无法在 ACK 后补 toast,改为告警日志) - 消息无 id 兜底键由「内容前 200 字符」改为单调唯一键,杜绝前缀碰撞误丢真实消息 - Symbol.for→模块级 Symbol 哨兵;补「claim+setImmediate 必须同步」的顺序不变量注释 - 注释订正:SDK 是 await handler 后才发唯一 ACK 帧;卡片回调同步无补推,超时仅影响 UX - 测试:补「同 event_id 完成后重投去重」「无 event_id 合法重复放行」「无 id 消息双发不丢」三例
baicaicc
added a commit
to baicaicc/botmux
that referenced
this pull request
Oct 26, 2026
) Restored from integrations/botmux/native-sessions.patch at baicaicc/allInOne@225bd34 (patch version 18/28). Part of baicaicc/allInOne#144 Co-Authored-By: Claude Opus 5.5 <[email protected]>
jiyuuDev
added a commit
to zsnjuts/botmux
that referenced
this pull request
Nov 1, 2026
双副本下,孤儿扫描只跳过本副本有本地 owner 的会话,另一个副本每个扫描周期都会给同一 会话追加一条 terminalize_orphan;由 owner 所在副本认领时一律 Deferred,等一个可能永远 不会退场的 owner,后面的扫描行越堆越多。本地 owner 存活就说明不是孤儿,按终态 ignored 收尾;owner 退场后由下一轮扫描重新证明。认领了已失败恢复轮次的残留 owner 仍先放弃投影。 Co-Authored-By: Claude <[email protected]>
jiyuuDev
added a commit
to zsnjuts/botmux
that referenced
this pull request
Nov 1, 2026
双副本下,孤儿扫描只跳过本副本有本地 owner 的会话,另一个副本每个扫描周期都会给同一 会话追加一条 terminalize_orphan;由 owner 所在副本认领时一律 Deferred,等一个可能永远 不会退场的 owner,后面的扫描行越堆越多。本地 owner 存活就说明不是孤儿,按终态 ignored 收尾;owner 退场后由下一轮扫描重新证明。认领了已失败恢复轮次的残留 owner 仍先放弃投影。 Co-Authored-By: Claude <[email protected]>
jiyuuDev
added a commit
to zsnjuts/botmux
that referenced
this pull request
Nov 1, 2026
…y#109 / deepcoldy#111) (#65) * fix(primary): canonical Session 一直不存在的会话控制按终态忽略,不再无限重投(Mew deepcoldy#109) 控制可能先于 canonical 落库到达(流式卡片先发、admission 还在提交),所以 canonical 缺失时先照旧重试;控制写入超过 5 分钟仍不存在,说明会话从未落库或 已被删除,按 ignored 收尾(已有控制操作一并结算),不再每 6 秒重投一次。 Co-Authored-By: Claude <[email protected]> * fix(primary): 本副本仍在服务会话时孤儿控制直接收尾,不再无限延后(Mew deepcoldy#111) 双副本下,孤儿扫描只跳过本副本有本地 owner 的会话,另一个副本每个扫描周期都会给同一 会话追加一条 terminalize_orphan;由 owner 所在副本认领时一律 Deferred,等一个可能永远 不会退场的 owner,后面的扫描行越堆越多。本地 owner 存活就说明不是孤儿,按终态 ignored 收尾;owner 退场后由下一轮扫描重新证明。认领了已失败恢复轮次的残留 owner 仍先放弃投影。 Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这个 PR 解决什么问题
飞书要求事件回调要「秒回」(快速 ACK)。但 botmux 收到消息后,会先做一串网络查询(查群信息、群模式、群成员、判断发消息的是不是真人……),再决定怎么开会话——这些加起来可能要好几秒。回调被这些慢活拖住,飞书以为我们没收到,就把同一条事件重发一遍,结果同一句话被处理两次、同一个会话被开两次。
卡片按钮也有同样的毛病:点一下「重启」这类按钮会去拉起 CLI 进程,处理慢了,飞书那边的卡片回调也会超时(client error 200341)。
改了什么
消息事件、被拉群事件:先回执,再后台干活
收到事件后立刻返回(让飞书第一时间拿到 ACK),真正耗时的处理丢到后台
setImmediate异步跑。加一道去重闸
用事件自带的 id(
event_id/uuid,没有就退用message_id)记一笔,短时间内同一个事件再来就直接丢掉,挡住「飞书超时重投 → 同一句话干两遍」。卡片按钮:处理慢了也先回个话
2.5 秒内处理完就正常返回、卡片照常更新;超时就先回一个 toast「操作已收到,后台处理中」让飞书别再等,等真正处理完再后台把卡片补刷成最终样子。
评审后补强(在上面基础上)
restart/close二次执行;无 event_id 的回退仍只做并发保护,不误伤合法重复点击(如 toggle 流式开/关)。Symbol.for→模块级 Symbol 哨兵;补「claim+setImmediate 必须同步」的顺序不变量注释。测试
pnpm vitest run test/event-dispatcher.test.ts→ 84/84pnpm tsc --noEmit干净