FileArtifactService changes CRLF and CR line endings in text artifacts

未关闭 适合新手
#7,914 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 4 天内回复

@sanketpatil06 已经在做这个了。

开始于 2026年11月2日。

  • #7915 来自 @emme1t —— 未关闭
  • #7917 来自 @TINGyu123644 —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
85/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 google/adk/artifacts/file_artifact_service.py 开始,追踪文本的保存和加载方式;issue 的复现脚本展示了需要检查的换行符情况。运行该脚本,然后验证基于文件的 artifact 返回的已保存文本保持不变,包括 CRLF 和单独的 CR 行结束符。

由索引模型根据 Issue 内容生成。

描述

request clarification services

🔴 Required Information

Describe the Bug:

FileArtifactService changes the line endings of text artifacts. A text artifact containing \r\n or a lone \r loads back with \n in their place. The payload is read with Path.read_text, whose universal newline mode rewrites both. It is written with Path.write_text, which translates \n to os.linesep, so on Windows every \n is stored as \r\n.

InMemoryArtifactService and GcsArtifactService return the saved text unchanged, so the same artifact differs only on the file backend. That backend is what adk web and adk run use by default (use_local_storage=True, via create_local_artifact_service). CSV files (RFC 4180 uses CRLF), patches, and Windows-authored text a tool saves therefore load back different from what was saved.

Steps to Reproduce:

  1. pip install google-adk (reproduced on main at 8cd3b12c8)
  2. Run:
import asyncio, tempfile
from google.genai import types
from google.adk.artifacts.file_artifact_service import FileArtifactService
from google.adk.artifacts.in_memory_artifact_service import InMemoryArtifactService

async def main():
  text = "id,name\r\n1,a\r\n2,b\rc\n"
  for svc in (FileArtifactService(root_dir=tempfile.mkdtemp()), InMemoryArtifactService()):
    await svc.save_artifact(app_name="a", user_id="u", session_id="s",
                            filename="t.csv", artifact=types.Part(text=text))
    got = await svc.load_artifact(app_name="a", user_id="u", session_id="s",
                                  filename="t.csv")
    print(type(svc).__name__, repr(got.text), got.text == text)

asyncio.run(main())

Expected Behavior:

Both services return the saved text unchanged.

Observed Behavior:

FileArtifactService 'id,name\n1,a\n2,b\nc\n' False
InMemoryArtifactService 'id,name\r\n1,a\r\n2,b\rc\n' True

Environment Details:

  • ADK Library Version (pip show google-adk): 2.13.0 (main at 8cd3b12c8)
  • Desktop OS: macOS (the read-side rewrite is platform independent; the write-side translation affects Windows)
  • Python Version (python -V): 3.11

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A (artifact service only)

🟡 Optional Information

Regression:

Not that I know of. The file backend has read and written text payloads with read_text / write_text.

Additional Context:

I would like to contribute a focused fix for this. Would writing artifact.text.encode("utf-8") with write_bytes and decoding read_bytes() on load be an acceptable approach? This keeps the stored payload exactly equal to the saved text. The error handling stays the same (OSError / UnicodeDecodeError are still caught and logged). Metadata JSON reads and writes are unaffected, since JSON escapes CR/LF inside strings.

How often has this issue occurred?:

  • Always (100%)
主要语言
Python
星标
22.1k
派生
4.3k
平均合并
1 天 10 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/adk-python 的其他 Issue

查看 google/adk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。