Skip to content

fix(code-executors): render an empty text part when a code execution result has no output - #903

Merged
AmaadMartin merged 2 commits into
google:mainfrom
AmaadMartin:fix/code-execution-result-missing-output-guard
Sep 16, 2026
Merged

AmaadMartin merged 2 commits into
google:mainfrom
AmaadMartin:fix/code-execution-result-missing-output-guard

Conversation

@adk-foundry-bot

@adk-foundry-bot adk-foundry-bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

This pull request will be merged automatically

Scheduled merge: 2026-09-16 21:27 UTC (about 24h from opening).

It was selected by [ADK Foundry] because the merge critic approved
the change, it is small, it touches no sensitive path, and CI is
green. No human has reviewed it.

To stop it: close this pull request, add the status/on-hold
label, or leave a review comment. Any of the three cancels the
merge; pushing a commit restarts the clock. Nothing is merged while
a question is open.

Approving does not stop it. An approval, or a comment that says
only lgtm, lets the merge run on schedule. Add any other text and
the merge stops.

Staged from fork PR #922.

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):

No existing issue.

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

Problem:

convertCodeExecutionParts concatenates codeExecutionResult.output into the
tool_output delimiters without a guard. output is optional in
@google/genai, so an absent output becomes the literal string undefined. The
model then reads ```tool_output\nundefined\n``` as a real tool result. A part
with no output reaches the converter from an A2A data part, from a replayed
session event, or from user-built Content.

Solution:

The converter now writes an empty text part, with no delimiters, when the output
is absent. This matches adk-python, which guards the same branch with
if output is not None. I compare with == null because a deserialized peer
part can carry an explicit null at runtime. An output of '' keeps its
delimiters, because adk-python guards on is not None and not on truthiness.

Testing Plan

Unit Tests:

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

Three new cases in core/test/code_executors/code_execution_utils_test.ts: an
absent output, an explicit null output, and an empty-string output that keeps
its delimiters. No existing test changed.

npx vitest run --project unit:core core/test/code_executors/code_execution_utils_test.ts   # 36 passed

The tests can fail. With the guard reverted, the first two cases report
'```tool_output\nundefined\n```' and '```tool_output\nnull\n```'
instead of ''. With the guard written as a truthiness check, the empty-string
case loses its delimiters.

Manual End-to-End (E2E) Tests:

No end-to-end test. The converter is a pure synchronous transform with no I/O
and no model call, so the three unit tests observe the whole change.

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

buildCodeExecutionResultPart is untouched. This converter guard is still
needed after that helper is fixed, because the converter also consumes parts
that ADK did not build.

adk-foundry-bot added 2 commits September 15, 2026 14:08
…tput

convertCodeExecutionParts concatenated codeExecutionResult.output into the
tool_output delimiters without a guard. output is optional, so an absent one
became the literal string "undefined" in the prompt the model reads next.

adk-python guards the same branch with `is not None` and writes an empty text
part with no delimiters, so this port matches it. `== null` covers the explicit
JSON null an A2A peer or a persisted event can carry, which `=== undefined`
would miss. An empty-string output still keeps its delimiters.
Replace the JSON.parse that laundered a null past output?: string with a
visible `as unknown as Part` cast, so the escape is greppable and nothing is
re-parsed at runtime.

Drop the two `.not.toContain(...)` assertions. Each followed a `toBe('')` on
the same value, and the empty string contains no substring, so neither could
ever fail.

Type the parts array instead of the whole content. The `!` on every
`content.parts![0]` goes away, and the tests still typecheck.
@AmaadMartin AmaadMartin added the automerge: scheduled Foundry will merge this automatically; close it to stop that label Sep 15, 2026
@AmaadMartin

Copy link
Copy Markdown
Collaborator

Merging in about 6h unless someone objects. Close this PR, add status/on-hold, or comment to stop it. Approving, or commenting only lgtm, lets it merge. No human has reviewed this change.

@AmaadMartin

Copy link
Copy Markdown
Collaborator

Merging in about 1h unless someone objects. Close this PR, add status/on-hold, or comment to stop it. Approving, or commenting only lgtm, lets it merge. No human has reviewed this change.

@adk-foundry-approver adk-foundry-approver left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved automatically by ADK Foundry. No human has read this change.

This approval attests only that the change passed the gates below, all
enforced in code:

  • the merge critic read the diff and approved it (93.9% precision measured
    against 107 upstream pull requests with known maintainer outcomes)
  • ? changed lines across ? file(s), inside the 200/5 ceiling
  • no auth, credential, security, release or dependency-manifest path touched
  • required checks green, re-verified immediately before this approval
  • opened 25h ago and visible as automerge: scheduled throughout,
    with no objection from anyone

To stop this merging, close the pull request or add status/on-hold. To stop
the mechanism entirely, revoke this account's access; delivery continues and
nothing merges.

@AmaadMartin
AmaadMartin merged commit 032e171 into google:main Sep 16, 2026
15 checks passed
@AmaadMartin AmaadMartin added automerge: merged Merged automatically by Foundry after its 24h review window expired with no objection and removed automerge: scheduled Foundry will merge this automatically; close it to stop that labels Sep 16, 2026
@kalenkevich kalenkevich mentioned this pull request Sep 16, 2026
prasanna8585 pushed a commit to prasanna8585/adk-js that referenced this pull request Nov 10, 2026
…result has no output (google#903)

* Fix: render an empty text part when a code execution result has no output

convertCodeExecutionParts concatenated codeExecutionResult.output into the
tool_output delimiters without a guard. output is optional, so an absent one
became the literal string "undefined" in the prompt the model reads next.

adk-python guards the same branch with `is not None` and writes an empty text
part with no delimiters, so this port matches it. `== null` covers the explicit
JSON null an A2A peer or a persisted event can carry, which `=== undefined`
would miss. An empty-string output still keeps its delimiters.

* Test: address the complexity review on the converter tests

Replace the JSON.parse that laundered a null past output?: string with a
visible `as unknown as Part` cast, so the escape is greppable and nothing is
re-parsed at runtime.

Drop the two `.not.toContain(...)` assertions. Each followed a `toBe('')` on
the same value, and the empty string contains no substring, so neither could
ever fail.

Type the parts array instead of the whole content. The `!` on every
`content.parts![0]` goes away, and the tests still typecheck.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge: merged Merged automatically by Foundry after its 24h review window expired with no objection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants