fix(adk): preserve empty MCP arrays in task history - #2372
Open
erauner12 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a subtle JSON fidelity issue in the Go ADK ↔ A2A execution path where structured MCP tool outputs containing non-nil empty arrays ([]) could be transformed into null after A2A task-history persistence (due to gob-based deep copies). It introduces a small protective conversion at the A2A executor boundary and adds regression tests to ensure nested empty arrays remain arrays end-to-end.
Changes:
- Add a gob-stable
emptyJSONArraysentinel plus recursive rewriting logic to preserve zero-length JSON arrays during A2A task-history gob copies. - Apply the preservation step in the A2A executor right after GenAI→A2A part conversion and before task-history persistence.
- Add focused regression tests covering nested empty arrays, repeated gob copies, and JSON/compatibility round trips.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| go/adk/pkg/mcp/structured_content_test.go | Adds an integration-style test asserting nested empty arrays remain non-nil empty arrays in MCP function response events. |
| go/adk/pkg/a2a/executor.go | Applies preserveEmptyJSONArrays to A2A DataParts before they’re queued/persisted. |
| go/adk/pkg/a2a/converter.go | Introduces emptyJSONArray (gob-registered) and recursive preservation helpers to keep [] from turning into null. |
| go/adk/pkg/a2a/converter_test.go | Adds regression coverage for gob deep-copy behavior, JSON round trips, and compatibility conversions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Preserve nested non-nil empty JSON arrays in MCP structured results as
[]when they pass through A2A task-history storage.Root cause
The task status update path deep-copies stored history with gob. Interface-held zero-length JSON arrays become typed nil slices during that copy, so A2A JSON changes
[]tonull.Fix
Protect empty JSON arrays at the shared A2A executor seam after MCP conversion and before task-history persistence. Explicit nulls and non-empty arrays remain unchanged.
Validation
[]values remain arrays in untouched A2Atasks/gethistory.This targets the
release/v0.9.xline and adds no dependency or schema change.