Skip to content

Comments

fix(agent): 修复附件状态同步:上传文件后 Agent 调用 read_file 无法读取用户附件问题#519

Merged
xerrors merged 2 commits intoxerrors:mainfrom
1165506270:codex/fix-attachment-state-main
Feb 25, 2026
Merged

fix(agent): 修复附件状态同步:上传文件后 Agent 调用 read_file 无法读取用户附件问题#519
xerrors merged 2 commits intoxerrors:mainfrom
1165506270:codex/fix-attachment-state-main

Conversation

@1165506270
Copy link

变更描述

背景与问题

44e41bb 重构后,附件已转为基于 StateBackend 使用,但出现两个连续问题:

  1. 用户上传文件后,Agent 调用 read_file 无法读取到用户上传附件;
  2. 在会话已有 runtime files(Agent 运行中生成的文件)时,附件同步可能导致这些文件丢失或在状态工作台消失。

本 PR 目标(以第一提交为主)

第一提交核心修复:

  • 在“上传附件/删除附件”后,主动同步线程的 LangGraph state(attachments + files),确保附件立即进入可读文件系统视图,Agent 可直接通过 read_file 访问。

第二提交补充增强:

  • files 更新策略改为只处理 /attachments/ 命名空间,采用增量合并(并对已删除附件写 None 删除),避免覆盖非附件 runtime files。

具体改动

  • src/services/conversation_service.py

    • 新增附件到 state files 的构建逻辑;
    • 在上传/删除附件后调用 state 同步;
    • 同步时仅更新 /attachments/...,不再整包覆盖 files
  • test/test_conversation_service_attachment_state.py

    • 覆盖上传后 state 同步、缺失 agent 安全降级、附件命名空间增量更新等关键场景。

修复效果

  • 上传附件后,Agent 可通过 read_file /attachments/... 直接读取用户上传内容;
  • 不再影响或覆盖 Agent 运行期创建的非附件文件,状态工作台文件显示稳定。

变更类型

  • 新功能
  • Bug 修复
  • 文档更新
  • 其他

测试

  • 已在 Docker 环境测试
  • 相关功能正常工作

相关日志或者截图

说明

(可选)有什么需要特别说明的吗?


💡 提示: 提交前可以运行 make lintmake format 检查代码规范

@xerrors xerrors merged commit a39333b into xerrors:main Feb 25, 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.

2 participants