Skip to content

fix(adk): preserve empty MCP arrays in task history - #2372

Open
erauner12 wants to merge 1 commit into
kagent-dev:release/v0.9.xfrom
erauner12:fix/v0.9-preserve-mcp-empty-arrays
Open

fix(adk): preserve empty MCP arrays in task history#2372
erauner12 wants to merge 1 commit into
kagent-dev:release/v0.9.xfrom
erauner12:fix/v0.9-preserve-mcp-empty-arrays

Conversation

@erauner12

Copy link
Copy Markdown
Contributor

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 [] to null.

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

  • Focused ADK A2A, MCP, task-store, and compatibility packages pass.
  • Regression tests cover nested empty arrays, non-empty arrays, repeated gob copies, and JSON round trips.
  • An isolated Kind/Garden run confirmed raw MCP [] values remain arrays in untouched A2A tasks/get history.

This targets the release/v0.9.x line and adds no dependency or schema change.

@github-actions github-actions Bot added the bug Something isn't working label Jul 31, 2026
@erauner12
erauner12 marked this pull request as ready for review August 2, 2026 06:11
Copilot AI review requested due to automatic review settings August 2, 2026 06:11

Copilot AI 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.

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 emptyJSONArray sentinel 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.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants