Skip to content

fix(code_executors): send correct field names for sandbox input files#5958

Open
jordanchendev wants to merge 2 commits into
google:mainfrom
jordanchendev:fix/3690-sandbox-input-file-field-names
Open

fix(code_executors): send correct field names for sandbox input files#5958
jordanchendev wants to merge 2 commits into
google:mainfrom
jordanchendev:fix/3690-sandbox-input-file-field-names

Conversation

@jordanchendev
Copy link
Copy Markdown

Problem

AgentEngineSandboxCodeExecutor was building the input-file payload with
incorrect JSON field names:

Code sent API expects
contents content
mimeType mime_type

This caused all input files to be silently unreadable inside the sandbox,
producing errors such as:

pandas.errors.EmptyDataError: No columns to parse from file

Fixes #3690

Changes

  • src/google/adk/code_executors/agent_engine_sandbox_code_executor.py — rename the two dict keys in the input_data['files'] list comprehension.
  • tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py — add regression test test_execute_code_sends_correct_field_names_for_input_files that verifies the correct keys are sent to the API.

Testing plan

  • New regression test added that asserts content and mime_type are used (was failing before the fix, passes after).
  • All existing tests in the file still pass.

pytest output

uv run --extra test python -m pytest tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py -v
======================== 11 passed, 5 warnings in 2.04s ========================

pre-commit

pre-commit run --files src/google/adk/code_executors/agent_engine_sandbox_code_executor.py \
                       tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py
isort....................................................................Passed
pyink....................................................................Passed
addlicense...............................................................Passed

AgentEngineSandboxCodeExecutor was sending 'contents' and 'mimeType'
when the Agent Engine Sandbox API expects 'content' and 'mime_type'.
This caused input files to be silently unreadable inside the sandbox,
producing errors such as pandas.errors.EmptyDataError.

Fixes google#3690
@jordanchendev jordanchendev marked this pull request as ready for review June 3, 2026 15:51
@rohityan rohityan self-assigned this Jun 5, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

rohityan commented Jun 5, 2026

/adk-pr-analyze

@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Jun 5, 2026

I will read the instructions for the adk-pr-analyze skill to ensure I follow the required protocol when triaging/analyzing a pull request.I will run the Contributor License Agreement (CLA) verification script to ensure the contributor has signed the Google CLA before proceeding with the analysis.I will fetch the PR metadata for PR 5958 using the dedicated fetch_github_pr tool. This is a precise read-only tool designed specifically for retrieving pull request details from the Google ADK Python repository.I will inspect the PR triage/verification script to understand its validation criteria and how it performs CLA verification.I will run a direct gh pr view command to fetch the status check details for PR 5958. This will allow us to verify if the Google CLA has been signed successfully (the cla/google status check).I will fetch the complete line-by-line diff of the pull request to inspect the exact modifications proposed by the author.I will inspect the baseline source file src/google/adk/code_executors/agent_engine_sandbox_code_executor.py in our local workspace around the modifications to understand the implementation context.I will inspect the full structure of src/google/adk/code_executors/agent_engine_sandbox_code_executor.py to examine style alignment, annotations, typing, imports, and verify how it interacts with other files.I will fetch the details of the referenced Issue 3690 to verify the background context and find more details about the problem.I will inspect the remaining lines of src/google/adk/code_executors/agent_engine_sandbox_code_executor.py to see how stdout and stderr mapping (Bug 1 from the issue) is handled in the baseline.I will find the code_execution_utils.py file to understand the definition of the File class.I will view google/adk/code_executors/code_execution_utils.py to examine the attributes and types of File.I will load the first lines of the test file tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py in our workspace to inspect imports and formatting.I will create an artifact file containing our comprehensive ADK Pull Request Analysis so that it is persisted and beautifully documented in the artifacts directory.I have analyzed Pull Request PR #5958 using the read-only workflow. Below is the detailed Pull Request analysis report.

You can also view the persistent artifact report directly at pr_5958_analysis.md.


🔍 ADK Pull Request Analysis: PR #5958

Title: fix(code_executors): send correct field names for sandbox input files
Author: @jordanchendev
Status: open
Impact: 51 additions, 2 deletions across 2 changed files

Executive Summary

  1. Core Objective: Corrects structured field naming inside AgentEngineSandboxCodeExecutor when uploading code interpreter input files to Vertex AI's Agent Engine Sandboxes.
  2. Justification & Value: Justified Fix – Resolves a critical bug reported in Issue #3690 where input files provided to the code executor were processed as empty (0 bytes) due to camelCase/plural mismatches. This caused silent script execution failures.
  3. Alignment with Principles: Pass – Avoids any public API breaking changes, adheres to Pythonic typing/naming boundaries, and introduces robust unit testing using high-fidelity real ADK models instead of arbitrary mocking.
  4. Recommendation: Approve – Meritorious fix that cleanly repairs a major functionality gap.

Detailed Findings & Analysis

1. Objectives & Impact ("What does it do?")

  • Context & Background:
    Under Issue #3690, the AgentEngineSandboxCodeExecutor serialized input_files list items with the keys 'contents' and 'mimeType'. However, the Vertex AI Sandbox API endpoint expects 'content' (singular, base64 data) and 'mime_type' (snake_case). Because the backend silently ignored the unmatched fields, execution environments received zero-byte files, making code interpreter setups involving dataframes or local file ingestion unusable.
  • Implementation Mechanism:
    The change is localized inside the file agent_engine_sandbox_code_executor.py:
    input_data['files'] = [
        {
            'name': f.name,
            'content': f.content,
            'mime_type': f.mime_type,
        }
        for f in code_execution_input.input_files
    ]
  • Affected Surface:
    Fully internal modification; zero exposure to external API/CLI structures or public schemas.

2. Justification & Value ("Is it a valid and useful change?")

  • Workspace Verification:
    We examined agent_engine_sandbox_code_executor.py using our read-only views, confirming the buggy baseline serialization has been resolved. Additionally, verifying code_execution_utils.py shows the class properties of the File model (content, mime_type) map seamlessly to the new dictionary properties.
  • Value Assessment:
    This is a critical addition. Silent file truncation bugs are notoriously hard for developers to diagnose, typically leading to confusing failures like pandas.errors.EmptyDataError: No columns to parse from file which look like code execution design issues instead of SDK transport issues.
  • Alternative Approaches:
    The proposed fix is optimal because dictionary mapping happens at the serialization boundary immediately prior to invoking the API client. No structural refactoring is needed.
  • Scope & Depth:
    Systematic Fix (Root Cause addressed). Note that the original issue also mentioned standard output decoding mismatches (msg_out and msg_err), but verification on lines 205-207 of the baseline confirms that the console stdout/stderr mapping was already patched, leaving this contribution as the final piece to fully resolve Issue AgentEngineSandboxCodeExecutor uses wrong JSON field names for stdout/stderr #3690.

3. Principle & Style Alignment Checklist ("Does it follow rules?")

  • Public API & Visibility Boundaries:
    • Status: Pass
    • Analysis: No changing of public interfaces, method overrides, signature variations, or export tables (__all__).
  • Code Quality, Typing & Conventions:
    • Status: Pass
    • Analysis: Adheres strongly to formatting patterns and keeps the codebase compliant with ADK standards.
  • Robustness & Edge Cases:
    • Status: Pass
    • Analysis: Includes validation checking on the presence of code executor inputs before building dictionary payloads.
  • Test Integrity & Quality:
    • Status: Pass
    • Analysis: The author has added the unit test test_execute_code_sends_correct_field_names_for_input_files inside test_agent_engine_sandbox_code_executor.py, which constructs high-fidelity CodeExecutionInput and File models, patches the vertex client, exercises execution, and validates key mapping payloads securely.

Conclusion & Recommendation

The pull request is clean, correctly targeted, highly necessary, and fully compliant with ADK architectural guidelines. I recommend approving this PR directly.

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.

AgentEngineSandboxCodeExecutor uses wrong JSON field names for stdout/stderr

3 participants