Skip to content

fix(extended_chat): keep real tool errors and recover chat lookup by id - #1134

Open
3316891527 wants to merge 2 commits into
AAswordman:devfrom
3316891527:fix/extended-chat-error-semantics
Open

3316891527 wants to merge 2 commits into
AAswordman:devfrom
3316891527:fix/extended-chat-error-semantics

Conversation

@3316891527

@3316891527 3316891527 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

变更说明 / Description

背景与动机 / Context and motivation

extended_chat 对宿主聊天 API 的错误处理和会话查找不够准确:超时可能被当成成功,失败文案被统一改写,按 id 查找时可能错过实际存在的会话。

改动范围 / Changes

  • chat_with_agent 不再用 Promise.race 把发送超时写成成功,只等待原生 timeout_ms。
  • 工具失败不再统一包成「读取对话消息失败」,保留原始错误文案。
  • 角色卡查找失败不再被空 catch 吞掉;按名称精确匹配,否则大小写不敏感匹配。
  • startService 失败会让 chat_with_agent 失败,不再忽略。
  • 传入已有 chat_id 时要求该会话已绑定角色,并按角色 id 或名称校验一角色一会话。
  • read_messages_range 的工具描述标明行号包含库内 summary 等隐藏行。
  • find_chat / 按标题解析会话 / chat_with_agent 校验已有会话时:先走宿主 findChat;query 为对话 id 仍找不到则用 list_chats 和 agent_status 再确认;支持 current 解析为当前会话。

不同步修改宿主 findChat、工作流或其它插件。

兼容性与风险 / Compatibility and risks

  • chat_with_agent 超时从成功变为失败。
  • 失败文案不再带统一前缀。
  • 未绑定角色的会话不能再用于 chat_with_agent。
  • startService 失败会阻断发信。

关联 Issue / Related issue

N/A。内置 extended_chat 插件修复。

验证方式 / Verification

检查或命令:
tsc 编译 examples/extended_chat.ts,同步 examples/extended_chat.js 与 app/src/main/assets/packages/extended_chat.js(去掉 "use strict")
android-build.yml / android-tests.yml on fix/extended-chat-error-semantics
环境与变体:
分支基于 upstream/dev
结果:
三文件已同步。Tests 若失败于 DeepseekProviderMediaRoleTest / XaiProviderReasoningTest,为上游存量编译错误,与本 diff 无关。

证据 / Evidence

2 commits, 3 files (examples/extended_chat.ts, examples/extended_chat.js, app/src/main/assets/packages/extended_chat.js).

Stop treating send timeouts as success, keep native error text, require one bound role per chat, and fail if chat service cannot start.
If find_chat only trusts the in-memory chat list, a valid UUID can still
fail with Chat not found. Fall back to DAO-backed existence checks and
accept current as the active window.
@CATMIAOZHI
CATMIAOZHI self-requested a review September 25, 2026 07:19

@CATMIAOZHI CATMIAOZHI left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审计结论:✅ 批准合并

改动(3 文件,+345/−216):修复 extended_chat 插件的错误语义与会话查找——超时不再伪装成功、保留原始工具错误、角色卡查找不再吞异常、startService 失败向上传播、传入已有 chat_id 时校验一角色一会话、find_chat 支持按 id / current 查找并带回退恢复。

通过的检查:

  • 目标分支为 dev ✓
  • Promise.race 超时写成功已移除,改为等待宿主原生 timeout_ms;语义变更(超时从成功变为失败)在 PR 描述中明确披露
  • 工具失败不再统一包成「读取对话消息失败」,原始错误文案保留,符合"keep real tool errors"
  • 角色卡查找移除空 catch,精确匹配→大小写不敏感匹配,listCharacterCards 异常向上传播
  • startService 失败不再忽略,会阻断发信(符合描述)
  • findChatRobust 回退链完整:宿主 findChat → listChats(200) → agentStatus 存在性确认;current 别名只递归一层,无无限递归;非"找不到"类错误直接 rethrow,不吞异常
  • 三文件(examples/extended_chat.ts、examples/extended_chat.js、app/src/main/assets/packages/extended_chat.js)内容同步,已核验
  • read_messages_range 描述修正(行号含库内 summary 等隐藏行),文档准确
  • PR 描述与 diff 一致

问题:

  1. [P2] recoveredByIdOnly 路径跳过了一角色一会话校验:chat_with_agent 传入已有 chat_id 时,若会话仅通过 agentStatus 恢复(synthetic chat,无绑定信息),if (!existing.recoveredByIdOnly) 直接跳过绑定角色校验。这与 PR 描述中"传入已有 chat_id 时要求该会话已绑定角色,并按角色 id 或名称校验一角色一会话"不一致;且 findListedChatById 的 listChats({ limit: 200 }) 是固定上限,会话超过 200 个的用户可能误入该路径。建议:文档注明该例外,或对该路径尝试分页获取绑定信息。
  2. [question] 宿主 sendMessage 的原生 timeout_ms 超时后是 reject 还是 resolve?若宿主超时后 resolve(而非 reject),超时仍会被当成成功返回,本 PR「超时不再当成功」的核心目标就没达成。请确认宿主行为。
  3. [P3] '.' 被收进 CURRENT_CHAT_ALIASES:标题恰为 . 的会话将永远查不到(被解析为当前会话)。
  4. [P3] cardResult.cards 对 null/undefined 无保护(cardResult?.cards ?? [] 更稳妥);旧代码同理,顺手可修。
  5. [P3] isMissingChatQueryError 依赖英文错误文案匹配;若宿主错误信息被本地化,回退逻辑不会触发。

由 水晴喵的muse 审计

Comment thread examples/extended_chat.ts
if (!existing?.id) {
throw new Error(`Chat not found: ${chatId}`);
}
if (!existing.recoveredByIdOnly) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] recoveredByIdOnly 的 synthetic chat 会跳过一角色一会话校验(无绑定信息可查),与 PR 描述声称的「传入已有 chat_id 时要求绑定角色」不一致;且 findListedChatById 的 limit: 200 可能让会话多的用户误入该路径。建议文档注明例外,或尝试分页获取绑定信息。

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.

2 participants