Inline CSV uploads in code execution can reuse a stale file or corrupt raw bytes
维护者通常 3 天内回复
评估
这个 Issue 还没有评估数据。
描述
Environment
ADK main (2.14.1), macOS, Python 3.11.17. Offline reproductions; no model, credentials, Docker, or network services needed. Regression introduction is unknown.
Symptoms and impact
With optimize_data_file=True, inline CSV attachments are extracted into executor input files. Two defects in the same extraction path can cause analysis of incorrect data:
- With
include_contents="none", uploadb"value\n10\n", finish the turn, then uploadb"value\n99\n"at the same part position. Both requests derivedata_1_1.csv. The second request reuses the first cached file and skips preprocessing because that name is already processed. - Upload the valid one-cell CSV
b"1234". The encoding helper mistakes these raw bytes for encoded content. The executor decodes them intob"\xd7m\xf8"instead of the original CSV.
Expected versus actual
| Input | Expected | Actual on upstream/main |
|---|---|---|
Raw inline CSV b"1234" |
Executor receives b"1234" |
Executor receives b"\xd7m\xf8" |
| Second current-turn CSV with value 99 | Placeholder resolves to value 99; eligible for preprocessing | Placeholder resolves to cached value 10; preprocessing skipped |
| Identical upload repeated at the same position | Reuse its cached file without duplicates | Reuses the filename regardless of content |
Offline reproduction
Run the following script using Python 3.11 with dependencies installed and PYTHONPATH=<checkout>/src. It prints both symptoms before asserting the expected behavior. It fails on upstream/main and passes with the local fix.
"""Offline regression check: no model, credentials, or executor service."""
from google.genai import types
from google.adk.code_executors.code_executor_context import CodeExecutorContext
from google.adk.events.event import Event
from google.adk.flows.llm_flows.context._contents import _get_current_turn_contents
from google.adk.flows.llm_flows.extensions._code_execution import (
_extract_and_replace_inline_files, get_content_as_bytes,
)
from google.adk.models.llm_request import LlmRequest
def upload(context, history, data):
history.append(Event(author='user', content=types.Content(role='user', parts=[
types.Part.from_bytes(data=data, mime_type='text/csv')
])))
request = LlmRequest(contents=_get_current_turn_contents(None, history, 'agent'))
files = _extract_and_replace_inline_files(context, request)
placeholder = request.contents[0].parts[0].text
current = next(f for f in files if f'`{f.name}`' in placeholder)
history.append(Event(author='agent', content=types.Content(role='model', parts=[
types.Part(text='Done')
])))
return files, current
_, raw = upload(CodeExecutorContext({}), [], b'1234')
raw_bytes = get_content_as_bytes(raw.content)
context, history = CodeExecutorContext({}), []
_, first = upload(context, history, b'value\n10\n')
context.add_processed_file_names([first.name])
second_files, second = upload(context, history, b'value\n99\n')
repeated_files, repeated = upload(context, history, b'value\n99\n')
second_bytes = get_content_as_bytes(second.content)
new_files = [f for f in second_files if f.name not in context.get_processed_file_names()]
print('Raw upload decoded for executor:', repr(raw_bytes))
print('Second turn decoded for executor:', repr(second_bytes))
print('Cached files:', len(second_files), 'New files to preprocess:', len(new_files))
print('Identical re-upload adds files:', len(repeated_files) - len(second_files))
assert raw_bytes == b'1234'
assert second_bytes == b'value\n99\n'
assert len(second_files) == 2 and new_files == [second]
assert repeated_files == second_files and repeated == second
assert get_content_as_bytes(second_files[0].content) == b'value\n10\n'
The original independent reproductions are also recorded locally at out/reports/correctness-review-2/repro_csv_base64.py and out/reports/correctness-review-2/repro_csv_cache_collision.py. Those original scripts assert the buggy behavior and therefore intentionally fail once fixed.
Cause and proposed fix
_extract_and_replace_inline_files derives filenames from request-local indices but caches files across turns. Its filename-only check ignores newly uploaded bytes. Separately, get_encoded_file_content guesses whether bytes are encoded even though inline_data.data is known to be raw.
Encode raw inline bytes directly. Compare encoded content and MIME before reusing a positional filename; on collision, append a stable digest of MIME and content. Preserve earlier cached files and placeholders, and reuse the digest filename on identical re-upload. Leave the general encoding helper's existing behavior intact for compatibility.
Duplicate re-check
No matching issues or PRs updated since 2026-11-17 were returned by read-only searches for code execution CSV, inline_data csv, data file cache, get_encoded_file_content, base64 csv, and optimize_data_file. The earlier review separately distinguished historical PR #4024 (persisting replacements in history) from these new-upload collisions.
- 主要语言
- Python
- 星标
- 22.3k
- 派生
- 4.4k
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/adk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
google/adk-python#8360 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
google/adk-python#8359 ·
维护者通常 3 天内回复
-
Can pin to litellm version be changed?可能已有人在做 @llalitkumarrr 于 10 天前认领。 未关闭models
难度 1/5 1 小时以内 新手友好度 65/100
google/adk-python#8129 · 2 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
OpenAPI tools ignore operation- and path-level server overrides可能已有人在做 @sanketpatil06 于 14 天前认领。 未关闭tools
难度 2/5 1-3 小时 新手友好度 75/100
google/adk-python#8064 · 4 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
Two docstrings in openapi_tool document parameters the signatures do not accept可能已有人在做 @surajksharma07 于 17 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
google/adk-python#8024 · 1 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
查看 google/adk-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
vllm-project/vllm#70030 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
TigreGotico/tugaphone#408 ·
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 74/100
gke-labs/kube-agents#7308 ·
维护者通常 1 天内回复
-
t: bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
chore
难度 1/5 1-3 小时 新手友好度 88/100
lugassawan/swe-workbench#841 ·