Skip to content

fix(openaimodel): send executable code parts as text - #1956

Merged
wolo-lab merged 14 commits into
google:mainfrom
mangeshraut712:cursor/openai-code-execution-text-674f
Nov 6, 2026
Merged

wolo-lab merged 14 commits into
google:mainfrom
mangeshraut712:cursor/openai-code-execution-text-674f

Conversation

@mangeshraut712

@mangeshraut712 mangeshraut712 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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

Linked issue

Problem:
A Gemini turn that stores ExecutableCode or CodeExecutionResult makes the next OpenAI request fail before it is sent. Both Chat Completions and Responses reject the part with openai: unsupported content part: ExecutableCode (or CodeExecutionResult).

Solution:
Send those parts as text, using the same fences as adk-python's Responses converter: a python block for the code and a code_output block for the result. Both APIs do this. adk-python's Chat Completions converter drops these parts; Go deliberately preserves them there so a cross-model session does not hide the code or its output from the model.

Behavior change

A request that used to fail on these parts now includes them as text. Other unsupported parts are still rejected.

Testing Plan

Unit Tests:

  • All unit tests pass locally.
  • Both endpoints assert the exact request payload for code-only and code-plus-image histories, including the media-message path.

go test -count=1 -race -timeout 180s ./model/openaimodel/...

ok  google.golang.org/adk/v2/model/openaimodel
ok  google.golang.org/adk/v2/model/openaimodel/internal/completions
ok  google.golang.org/adk/v2/model/openaimodel/internal/responses
ok  google.golang.org/adk/v2/model/openaimodel/internal/shared

golangci-lint run (v2.3.1) on those three internal packages reported 0 issues.

With your source change reverted and your tests kept, which test fails?

Leaving the new tests in place and not passing PartFieldCodeExecution from the converters:

  • TestBuildParams_CodeExecutionAsText (responses and completions)
  • TestBuildParams_DropsReplayedThoughts/thought_text_riding_on_code_drops_only_the_text

They fail with openai: unsupported content part: ExecutableCode.

Removing the media-path insertion instead makes these focused cases fail by omitting the fenced code before the image:

  • TestBuildParams_MediaOnTheWire/executable_code_before_an_inline_image_keeps_its_order (Chat Completions)
  • TestBuildParams_CodeExecutionAsText/code_keeps_its_place_on_a_media_message (Responses)

Manual End-to-End (E2E) Tests:

No live model call. The failure is in request construction, and the tests above check the payload that would be sent.

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.

Gemini code-execution turns stored in a session failed the next OpenAI
request. Render ExecutableCode and CodeExecutionResult as the fenced
text adk-python already sends, on both Chat Completions and Responses.

Fixes google#1924
@mangeshraut712
mangeshraut712 force-pushed the cursor/openai-code-execution-text-674f branch from aa452e2 to a40a51e Compare October 25, 2026 18:12
@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Rebased onto main and mergeable — ready when you are.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

CI is green on this tip (a bit behind main; happy to rebase if needed). It sends executable code parts as text in the OpenAI model path so they are not dropped. If it looks good, could you please review and merge when you get a chance? Thanks.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

CI is green. Sends executable code parts as text in the OpenAI model path. Please review and merge when you can.

@ktsoator ktsoator left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m not a maintainer, but this looks good to me overall, with one small suggestion on the comment wording.

@wolo-lab
wolo-lab force-pushed the cursor/openai-code-execution-text-674f branch from 666e47b to 8577599 Compare November 6, 2026 09:25

@wolo-lab wolo-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks

@wolo-lab
wolo-lab merged commit ded357e into google:main Nov 6, 2026
15 checks passed
mangeshraut712 added a commit to mangeshraut712/mangeshraut712 that referenced this pull request Nov 6, 2026
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.

model/openaimodel: send executable code and code execution results as text

3 participants