fix(chat): deduplicate forward=true boundary messages to prevent infinite pagination loop#461
Open
weiconghe wants to merge 1 commit into
Open
Conversation
…nite pagination loop (DingTalk-Real-AI#430) When --forward=true is used with chat message list / list-direct, the upstream API returns messages where createTime >= T (inclusive boundary). Using the last message's createTime as the next page's --time returns identical messages, causing an infinite loop. Changes: - Add chat_hooks.go: wraps RunE to intercept JSON output when --forward=true, removes messages whose createTime matches the --time anchor, and emits a stderr warning recommending --forward=false - Add chat_hooks_test.go: 21 tests covering dedup logic, hook installation, error passthrough, and edge cases - Wire installChatHook in dynamic_commands.go alongside existing mail/todo hooks - Update chat.md docs (mono + multi) to recommend --forward=false for pagination and document the forward=true boundary limitation
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.
Issue for this PR
Closes #430
Type of change
What does this PR do?
问题描述
chat message list/list-direct使用--forward=true翻页时,上游 API 返回createTime >= T的消息(含边界)。当用户按文档推荐使用最后一条消息的createTime作为下一页的--time参数时,会得到完全相同的消息集合,导致无限循环。具体文件:
internal/compat/dynamic_commands.go— 动态命令生成器,生成chat message list等命令skills/mono/references/products/chat.md— 文档描述翻页方式复现步骤(v1.0.34 实测):
影响分析
--forward=true翻页的用户/AI 都会陷入无限循环chat message list的自动化流程修复方案
新增
chat_hooks.go:参照已有的mail_hooks.go/todo_hooks.go模式,新建installChatHook,在动态命令构建时安装--forward=true时,wrapRunE捕获 JSON 输出createTime与--time锚点相同的边界重复消息--forward=false更新文档:在
chat.md(mono + multi 两份)中:--forward=false(从新往老翻页)--forward=true的已知限制How did you verify your code works?
go test ./internal/compat/PASS)Screenshots / recordings
N/A
Checklist