Inline CSV uploads in code execution can reuse a stale file or corrupt raw bytes
Mantenedores costumam responder em até 3 dias
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 22.3k
- Forks
- 4.4k
- Merge médio
- 1d 2h
- PRs com merge (30d)
- 6
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de google/adk-python
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
google/adk-python#8360 ·
Mantenedores costumam responder em até 3 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
google/adk-python#8359 ·
Mantenedores costumam responder em até 3 dias
-
Can pin to litellm version be changed?Talvez já em andamento @llalitkumarrr assumiu há 10 dias. Abertamodels
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 65/100
google/adk-python#8129 · 2 comentários · 1 responsável ·
Mantenedores costumam responder em até 3 dias
-
OpenAPI tools ignore operation- and path-level server overridesTalvez já em andamento @sanketpatil06 assumiu há 14 dias. Abertatools
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
google/adk-python#8064 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 3 dias
-
Two docstrings in openapi_tool document parameters the signatures do not acceptTalvez já em andamento @surajksharma07 assumiu há 17 dias. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
google/adk-python#8024 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 3 dias
Todas as issues de google/adk-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
vllm-project/vllm#70030 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
TigreGotico/tugaphone#408 ·
Mantenedores costumam responder em até 1 dia
-
needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
gke-labs/kube-agents#7308 ·
Mantenedores costumam responder em até 1 dia
-
t: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 3 dias
-
chore
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
lugassawan/swe-workbench#841 ·