fix(adk): preserve empty MCP arrays in task history - #2372
Conversation
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.
supreme-gg-gg
left a comment
There was a problem hiding this comment.
Is this a bug specific to v0.9.x? Otherwise, why is it not opened against main or v0.10.x, since 0.9.x will be legacy soon as we release 0.10.x
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.