Skip to content

fix(zulip): 弃用,重新PR#477

Closed
wedone wants to merge 8 commits into
HKUDS:mainfrom
wedone:fix/zulip-attachment-upload-error
Closed

fix(zulip): 弃用,重新PR#477
wedone wants to merge 8 commits into
HKUDS:mainfrom
wedone:fix/zulip-attachment-upload-error

Conversation

@wedone
Copy link
Copy Markdown
Contributor

@wedone wedone commented May 12, 2026

Description

修复 Zulip 通道在处理附件上传和发送时存在的四个 BUG,涉及文件对象传递、路径解析、路由元数据补全和进度消息过滤。

BUG 1: 附件上传报错 'str' object has no attribute 'name'

  • 根因: _upload_and_send 将文件路径字符串直接传入 client.call_endpoint(files=...),但 Zulip Python 客户端期望文件对象列表(内部执行 f.name),导致 AttributeError
  • 修复: 使用 open(media_path, "rb") 打开文件后传入文件对象

BUG 2: 附件重发时 Zulip 上传路径被当作本地文件路径

  • 根因: LLM 回复时使用消息内容中的 Zulip 服务器路径(如 /user_uploads/...)作为 media 参数,而非本地已下载的文件路径,导致 open() 报错 No such file or directory
  • 修复: 新增 _resolve_media_path 方法,将 Zulip 上传路径解析为本地文件路径(优先查找已下载副本,否则重新下载)

BUG 3: 附件发送报错 Message must have recipients

  • 根因: MessageTool 创建的 OutboundMessage 只包含 {"message_id": ...},缺少 msg_type/stream/topic/recipient_user_id 等 Zulip 路由字段,导致 _build_send_request 生成空收件人列表。_recipient_map 在收到消息时已存储完整路由元数据,但从未被读取使用
  • 修复: 在 send() 中,当 metadata 缺少 msg_type 时,从 _recipient_map 查找对应 chat_id 的路由信息并合并

BUG 4: 附件发送时产生重复的 message("...") 格式文本

  • 根因: LLM 调用 message 工具时,agent loop 先发送 _tool_hint 进度消息(如 message("内容")),然后 MessageTool 才发送真正的消息。配置中 send_tool_hints 默认为 False,但 _outbound_router 未检查该标志
  • 修复: 在 send() 入口处过滤 _tool_hint 消息,直接返回不发送

Related Issues

  • Related to Zulip channel attachment handling

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: channels

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

所有修复仅涉及 deeptutor/tutorbot/channels/zulip.py 一个文件,改动最小化,不影响其他通道(Matrix、飞书等)的行为。

WeDone and others added 8 commits May 9, 2026 01:17
Zulip Python 客户端的 call_endpoint 方法期望 files 参数接收文件对象列表(有 .name 属性),但代码错误地传入了文件路径字符串列表,导致附件上传时触发 AttributeError。

修复方案:在调用 call_endpoint 前使用 open() 打开文件,传递文件对象给 Zulip 客户端,确保 with 语句在使用完毕后正确关闭文件。

Closes #附件上传失败问题
LLM 回复时可能使用消息内容中的 Zulip 上传路径(如 /user_uploads/...)
作为 media 参数,而非本地已下载的文件路径,导致 open() 报错 No such file or directory。

添加 _resolve_media_path 方法,在上传前将 Zulip 路径解析为本地文件:
- 本地路径直接存在则原样返回
- Zulip 上传路径(/user_uploads/...)或完整 URL 先查找已下载的本地副本
- 若本地不存在则从 Zulip 服务器重新下载
- 无法解析时记录错误并跳过
…cipients

MessageTool 创建的 OutboundMessage 只包含 message_id,缺少 msg_type/stream/topic/recipient_user_id 等 Zulip 路由字段,导致 _build_send_request 生成空收件人列表。

_recipient_map 在收到消息时已存储了完整的路由元数据,但从未被用于补全发送消息的元数据。

修复:在 send() 中,当 metadata 缺少 msg_type 时,从 _recipient_map 查找对应 chat_id 的路由信息并合并,确保发送消息时始终有正确的收件人。
LLM 调用 message 工具时,agent loop 会先发送一条 _tool_hint 进度消息,然后 MessageTool 才发送真正的消息。配置中 send_tool_hints 默认为 False,但 _outbound_router 未检查该标志,导致 Zulip 通道将工具提示当作普通消息发送,产生重复且格式错误的文本。修复:在 send() 入口处过滤 _tool_hint 消息,直接返回不发送。
@wedone
Copy link
Copy Markdown
Contributor Author

wedone commented May 12, 2026

关闭此 PR,将基于 upstream/dev 创建新的干净 PR,仅包含修复 commit

@wedone wedone closed this May 12, 2026
@wedone wedone deleted the fix/zulip-attachment-upload-error branch May 12, 2026 08:09
@wedone wedone changed the title fix(zulip): 修复 Zulip 通道附件上传与发送的四个 BUG fix(zulip): 弃用,重新PR May 12, 2026
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