fix: 重启/恢复会话后微信重复发送历史消息 - #5
Open
midmirror wants to merge 1 commit into
Open
Conversation
Two root causes caused WeChat users to receive previously-sent replies repeatedly after restarting the agent session: 1. getUpdates cursor was in-memory only. After a restart the client started polling with an empty cursor, so the WeChat iLink Bot server replayed all buffered history messages and the agent re-processed them (duplicate replies). Persist the cursor (cursor.json) and restore it on init. 2. The agent_end catch-up sent `allReplies.slice(sentCount)` where allReplies was extracted from the full event.messages. When a session is resumed (omp -c / continue), event.messages contains the entire conversation history, so every historical assistant reply was treated as "not yet sent" and re-sent to WeChat on every turn. Remove the catch-up replay: message_end already delivers each assistant message incrementally. Also drop the now-unused sendRepliesToWechat / extractAllAssistantReplies and their tests. Also persist seen message ids (seen-ids.json) as a safety net for cursor loss/expiry. Verified: tsc --noEmit clean, 42/42 tests pass.
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.
Closes #4
问题
微信桥接在 omp/pi 会话重启或恢复(
omp -c)后,向微信重复发送历史回复。两个独立根因:src/client.ts):重启后游标丢失,空游标轮询导致服务端重放全部历史消息,agent 重新处理并重发回复。src/index.ts):allReplies.slice(sentCount)在全量event.messages上切片。恢复会话后event.messages含整个会话历史,sentCount只计本次增量 → 每次对话都把全部历史回复补发到微信。修复
src/auth.ts/src/client.ts:游标持久化到cursor.json,初始化时恢复;已见消息 id 持久化到seen-ids.json(游标丢失/过期时的兜底去重);按messageId对入站消息去重。src/index.ts:移除 agent_end 补发。message_end已逐条增量发送,补发是冗余且危险的通道。sendRepliesToWechat/extractAllAssistantReplies及对应测试。验证
tsc --noEmit0 错误npm test42/42 通过