Skip to content

Conversation

@Sudhendra
Copy link

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

N/A - Issue #3690 exists.

Problem:
AgentEngineSandboxCodeExecutor has two JSON field mismatches that cause silent failures:

  1. Response parsing: The Vertex AI Agent Engine sandbox API returns msg_out/msg_err, but the code reads stdout/stderr, resulting in empty output.
  2. Input file payload: The API expects content/mime_type, but the code sends contents/mimeType, causing input files to be unreadable in the sandbox.

Solution:

  1. Updated response parsing to read msg_out/msg_err as primary fields, with fallback to stdout/stderr for backward compatibility.
  2. Fixed input file payload to use correct keys: content and mime_type.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added 10 new test cases covering:

  • test_execute_code_with_msg_out_msg_err - Primary API response fields
  • test_execute_code_fallback_to_stdout_stderr - Backward compatibility
  • test_execute_code_msg_out_takes_precedence_over_stdout - Precedence logic
  • test_execute_code_partial_response_only_msg_out - Partial response (stdout only)
  • test_execute_code_partial_response_only_msg_err - Partial response (stderr only)
  • test_execute_code_empty_response - Empty response handling
  • test_execute_code_with_input_files_uses_correct_payload_keys - Request payload validation
  • test_execute_code_without_input_files_no_files_key - No files in payload
  • test_execute_code_output_files_metadata_preserved - Output file metadata
pytest tests/unittests/code_executors/test_agent_engine_sandbox_code_executor.py -v

13 passed in 6.21s

Full code_executors test suite:

pytest tests/unittests/code_executors/ -v

60 passed in 6.96s

Manual End-to-End (E2E) Tests:

Tested against a real Vertex AI Agent Engine sandbox:

Before fix:

stdout: ''
stderr: ''
output_files: []

After fix:

stdout: 'hello from stdout\nfile contents: col1,col2\\n1,2\\n\n'
stderr: 'hello from stderr\n'
output_files: []

Both issues are resolved:

  • stdout/stderr now populated correctly
  • Input file contents readable in sandbox (evidenced by file contents: col1,col2... in output)

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

The fix maintains backward compatibility by using a fallback pattern:

stdout = json_output_data.get("msg_out", json_output_data.get("stdout", ""))
stderr = json_output_data.get("msg_err", json_output_data.get("stderr", ""))

This ensures existing integrations that may return stdout/stderr continue to work while supporting the actual API response format (msg_out/msg_err).

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Sudhendra, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical communication issues within the AgentEngineSandboxCodeExecutor by rectifying JSON field mismatches. The changes ensure that the executor correctly interprets API responses and formats input file payloads, thereby enabling reliable code execution and data handling within the Vertex AI Agent Engine sandbox environment. This significantly improves the robustness and functionality of the code executor.

Highlights

  • API Response Parsing Fix: The code now correctly parses msg_out and msg_err fields from the Vertex AI Agent Engine sandbox API response, with a fallback mechanism to stdout and stderr for backward compatibility. This resolves issues where output was previously empty.
  • Input File Payload Key Correction: The input file payload keys have been updated from contents to content and mimeType to mime_type to match the Vertex AI Agent Engine sandbox API's expectations, ensuring input files are now correctly processed.
  • Comprehensive Unit Testing: Ten new unit tests have been added to cover various scenarios, including primary API response fields, backward compatibility, precedence logic, partial and empty responses, and correct input file payload key usage, significantly improving test coverage and reliability.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Sudhendra Sudhendra changed the title fix(code_executors): Fix JSON field mismatches in AgentEngineSandboxCodeExecutor - Fix input file payload keys: contents -> content, mimeType -> mime_type - Fix response parsing: read msg_out/msg_err with fallback to stdout/stderr Fixes #3690 fix(code_executors): Fix JSON field mismatches in AgentEngineSandboxCodeExecutor Jan 25, 2026
@adk-bot adk-bot added tools [Component] This issue is related to tools core [Component] This issue is related to the core interface and implementation labels Jan 25, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses two JSON field mismatches in AgentEngineSandboxCodeExecutor. The changes to handle msg_out/msg_err with a fallback to stdout/stderr for response parsing, and to fix the input file payload keys to content and mime_type, are well-implemented. The addition of a comprehensive suite of unit tests is excellent and ensures these fixes are robust and protected against future regressions. I have one suggestion to further improve the robustness of the JSON response parsing.

…odeExecutor

- Fix input file payload keys: contents -> content, mimeType -> mime_type
- Fix response parsing: read msg_out/msg_err with fallback to stdout/stderr
- Add defensive type check for JSON response to prevent AttributeError

Fixes google#3690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AgentEngineSandboxCodeExecutor uses wrong JSON field names for stdout/stderr

2 participants