Skip to content

fix: Feishu duplicate message processing#649

Open
dimeng07 wants to merge 2 commits into
op7418:mainfrom
dimeng07:fix/feishu-dedup
Open

fix: Feishu duplicate message processing#649
dimeng07 wants to merge 2 commits into
op7418:mainfrom
dimeng07:fix/feishu-dedup

Conversation

@dimeng07

@dimeng07 dimeng07 commented Jul 3, 2026

Copy link
Copy Markdown

问题

飞书桥接存在两个严重问题:

  1. 重复回复 — 用户在同一会话中收到多条相同回复
  2. 回复历史消息 — bot 在凌晨自动回复了用户很久以前发的消息

根因分析

问题 1:重复回复(3 个独立原因)

1a. Feishu 插件无消息去重

enqueueMessage() 直接入队无检查 messageId,Lark SDK 重连时重复推送事件。

1b. WSClient 未真正关闭

Gateway.stop() 只置空引用没有调用 SDK close(),旧连接继续存活导致 restart 时双 WSClient 同时运行。

1c. bridge-manager 并发竞态

start() 没有防止并发调用,Electron auto-start + UI 手动 Start 可能同时触发。

问题 2:回复历史消息

Lark SDK 在 WSClient 重连时会重放所有未确认的历史事件,Feishu adapter 没有过期消息过滤。

修复内容

  • FeishuChannelPlugin: 添加 seenMessageIds Set 去重
  • FeishuGateway.stop(): 调用 wsClient.close(force:true) 真正关闭
  • FeishuChannelPlugin.enqueueMessage(): 添加 5 分钟过期消息过滤
  • FeishuChannelPlugin.stop(): 不再清空去重集合
  • bridge-manager.start(): 添加 starting 标志位防止并发调用

全部 590 测试通过。

🤖 Generated with Claude Code

- Add seenMessageIds Set to FeishuChannelPlugin for message dedup
- FeishuGateway.stop() calls wsClient.close({ force: true }) to properly
  terminate WebSocket and prevent ghost connections after restart
- Do not clear dedup set on stop to prevent in-flight events from bypassing
@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the op7418's projects Team on Vercel.

A member of the Team first needs to authorize it.

The Lark SDK replays unprocessed historical events when the WSClient
reconnects or the bridge restarts. Without age filtering, the bot would
respond to messages from hours or days ago, appearing to reply to old
conversations at random times (e.g. 4:50 AM).

Add a 5-minute stale message filter in enqueueMessage(): messages with
create_time older than 5 minutes are dropped with a log message before
being enqueued or dedup-checked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant