fix: 限制联网搜索重试并恢复 Chat 复制 - #164
Merged
Merged
Conversation
- make Tavily date filters mutually exclusive, expose structured retryability, and retry transient failures once - add a per-run web-search call budget, duplicate-failure detection, and consecutive-failure circuit breaker - project search failures into model-visible guidance so the agent stops repeating invalid calls - route message and Markdown code copying through the trusted native preload clipboard bridge - add regression coverage for search guarding, main-chat wiring, and clipboard behavior
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 主要聚焦两条主线:一是让 Tavily webSearch 的失败/重试行为更可控(结构化失败结果、仅一次短重试、单次运行级熔断与工具移除);二是恢复 Chat 与代码块复制能力(通过受信任的 preload 桥接到 Electron 原生剪贴板,而不是依赖可能被 guest 权限策略拦截的 Web Clipboard API)。
Changes:
webSearch:避免相对时间参数与绝对日期参数同时下发;将网络/HTTP/缺少凭据等失败转换为结构化输出,并仅对可重试场景执行一次内部短重试。- 主 Chat 路径:接入单次运行级
WebSearchRunGuard熔断(预算上限、重复失败调用拦截、连续失败熔断),并将“工具可用性/提示”投影到 step policy。 - Chat/Markdown 复制:统一改为
window.filework.clipboard.writeTextpreload 桥接,并补充对应回归测试。
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/renderer/components/chat/ChatPanel.tsx | Chat 消息复制改为走 preload 剪贴板桥接,并在失败时记录 warn。 |
| src/renderer/components/chat/tests/ChatPanel.rendering.test.tsx | 覆盖“消息复制走 preload 而非 navigator.clipboard”的回归测试。 |
| src/renderer/components/ai-elements/markdown-code-block.tsx | 代码块复制改为走 preload 剪贴板桥接。 |
| src/renderer/components/ai-elements/tests/markdown-code-block.test.tsx | 新增代码块复制走 preload 的测试。 |
| src/preload/index.ts | 在 window.filework 暴露 clipboard.writeText,桥接到 Electron clipboard。 |
| src/main/ipc/ai-handlers.ts | 主 chat 执行链路接入 WebSearchRunGuard:beforeAnyToolCall 门控 + onToolResult 观测 + step policy。 |
| src/main/ipc/tests/ai-handlers-media-runtime.test.ts | 新增测试验证 run guard 在主 chat 的接线与熔断后的 activeTools 调整。 |
| src/main/core/agent/tools/web-search.ts | Tavily 请求参数互斥处理、结构化错误输出、一次内部短重试与可重试性标注。 |
| src/main/core/agent/tools/model-output.ts | 将 webSearch 的结构化失败信息(error/status/retryable/hint)投影进模型上下文。 |
| src/main/core/agent/research-loop-guard.ts | 新增 WebSearchRunGuard:单次运行 webSearch 预算/失败熔断/工具移除策略。 |
| src/main/core/agent/tests/web-search.test.ts | 覆盖结构化失败投影、绝对日期优先、400 非重试、503 内部一次重试等行为。 |
| src/main/core/agent/tests/research-loop-guard.test.ts | 覆盖 WebSearchRunGuard:重复失败调用拦截、连续失败熔断、预算上限等行为。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+111
to
+126
| const waitForRetry = (signal: AbortSignal): Promise<void> => | ||
| new Promise((resolve, reject) => { | ||
| if (signal.aborted) { | ||
| reject(signal.reason); | ||
| return; | ||
| } | ||
| const timer = setTimeout(resolve, TRANSIENT_RETRY_DELAY_MS); | ||
| signal.addEventListener( | ||
| "abort", | ||
| () => { | ||
| clearTimeout(timer); | ||
| reject(signal.reason); | ||
| }, | ||
| { once: true }, | ||
| ); | ||
| }); |
Owner
Author
There was a problem hiding this comment.
Fixed in 93b79aa. waitForRetry now keeps a stable onAbort reference and removes it before resolving a completed retry delay. Added a regression test that verifies the exact registered callback is removed. Verified with lint, typecheck, build, and the full test suite (3547 tests).
- remove the task abort listener when a retry delay completes normally - verify cleanup uses the same callback reference registered for the delay
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.
改动概览
联网搜索 P0
time_range与start_date/end_date导致 400。success、retryable、status、hint结果。联网搜索 P1
webSearch,引导模型基于已有证据继续或说明限制。Chat 复制
验证
pnpm lint:通过pnpm typecheck:通过pnpm test:382 个测试文件、3546 项测试通过pnpm build:通过