FileArtifactService changes CRLF and CR line endings in text artifacts
維護者通常 4 天內回覆
評估
研究方向
從 google/adk/artifacts/file_artifact_service.py 開始,追蹤文字的儲存與載入方式;issue 的重現指令碼展示了需要檢查的換行情況。執行該指令碼,接著確認以檔案為基礎的 artifact 傳回的已儲存文字保持不變,包括 CRLF 和單獨的 CR 行結尾。
由索引模型根據 Issue 內容生成。
描述
🔴 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:
pip install google-adk(reproduced onmainat 8cd3b12c8)- 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
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
google/adk-python 的其他 Issue
-
[LiteLLM] role='tool_responses' for Gemma 4 breaks tool calling on Vertex AI Model Garden MaaS (400 INVALID_ARGUMENT)可能已有人在做 @surajksharma07 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
google/adk-python#7977 · 1 則留言 · 已指派 1 人 ·
維護者通常 4 天內回覆
-
ContainerCodeExecutor drops output files that are hard links可能已有人在做 @llalitkumarrr 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
google/adk-python#7906 · 2 則留言 · 已指派 1 人 ·
維護者通常 4 天內回覆
-
GCS skill loaders ignore a skill.md manifest that the local and zip loaders accept可能已有人在做 @surajksharma07 於 6 天前認領。 未關閉tools
難度 2/5 1-3 小時 新手友好度 84/100
google/adk-python#7842 · 2 則留言 · 已指派 1 人 ·
維護者通常 4 天內回覆
-
RestApiTool crashes on a request body media type that has no schema可能已有人在做 @llalitkumarrr 於 6 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
google/adk-python#7838 · 1 則留言 · 已指派 1 人 ·
維護者通常 4 天內回覆
-
LiteLlm with SSE streaming records the answer twice in gen_ai.output.messages可能已有人在做 @surajksharma07 於 14 天前認領。 未關閉models
難度 2/5 1-3 小時 新手友好度 78/100
google/adk-python#7630 · 11 則留言 · 已指派 1 人 ·
維護者通常 4 天內回覆
查看 google/adk-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 64/100
its-me-prash/vwgroup-connect-ha#2019 ·
維護者通常 1 天內回覆
-
bug good first issue
難度 2/5 1-3 小時 新手友好度 86/100
KonstantinStarovoytov/kitden#21 ·
維護者通常 1 天內回覆
-
Refactor未關閉
難度 2/5 1-3 小時 新手友好度 62/100
ehmatthes/gh-profiler#166 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
smart-on-fhir/smart-fetch#73 ·
-
good first issue help wanted
難度 1/5 1-3 小時 新手友好度 85/100
RizgarOzan/playcal#13 ·