Repository navigation
fix(a2a): round-trip null data and nil raw parts through JSON - #513
Conversation
Part.MarshalJSON wrote {"data":null} for a data part holding nil and
{"raw":null} for a raw part holding nil bytes, and Part.UnmarshalJSON
rejected both as having no content.
Track whether the data key is present, so a JSON null decodes to
Data{Value: nil} as protojson and the v1 gRPC conversion already do.
Write nil raw bytes as "", which is how protojson writes empty bytes.
Fixes a2aproject#512
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| {name: "nil raw", part: NewRawPart(nil), json: `{"raw":""}`, want: NewRawPart([]byte{})}, | ||
| {name: "empty raw", part: NewRawPart([]byte{}), json: `{"raw":""}`, want: NewRawPart([]byte{})}, | ||
| {name: "empty text", part: NewTextPart(""), json: `{"text":""}`, want: NewTextPart("")}, | ||
| } |
There was a problem hiding this comment.
Could we also add cases for the other Data zero/empty JSON values to make sure none of them get dropped by omitemty— e.g. NewDataPart(false), NewDataPart(float64(0)), NewDataPart(""), NewDataPart([]any{}), and NewDataPart(map[string]any{})?
There was a problem hiding this comment.
Added in 4482b74: false, 0, "", [] and {} data cases in TestPartJSONCodecEmptyContent, each checking the exact JSON and the round-trip back to the same Part.
| Text *Text `json:"text,omitempty"` | ||
| Raw *Raw `json:"raw,omitempty"` | ||
| Data *any `json:"data,omitempty"` | ||
| Data partData `json:"data,omitzero"` |
There was a problem hiding this comment.
To avoid the extra partData wrapper type, could we use json.RawMessage with omitemty here, which can then be unmarshaled into any inside Part.UnmarshalJSON (and marshaled via json.Marshal(v.Value) in Part.MarshalJSON)?
There was a problem hiding this comment.
Done in 4482b74. partData is gone; data is now json.RawMessage with omitempty. omitempty only drops a zero-length RawMessage, so json.Marshal(nil) gives null (4 bytes) and {"data":null} is still written and decoded as Data{Value: nil}. The null, metadata and zero-value cases cover this.
Drop the partData wrapper. The data field is now a json.RawMessage with
omitempty: MarshalJSON stores json.Marshal(v.Value), so a nil value is
written as `null` (4 bytes) and is not omitted, and UnmarshalJSON
decodes the raw bytes into any when the key was present.
Add round-trip cases for false, 0, "", [] and {} data values.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes found while reviewing the v2.7.0..main diff before the 2.8.0 release (#500). * `a2asrv.NewTenantRESTHandler` matches a tenant sent as a single escaped path segment (`/locations%2Fx%2Fprojects%2Fy/...`) against multi-segment templates like `/{locations/*/projects/*}`. Since #488 the a2aclient (and JS clients) escape the tenant this way, while #514 split the path on `/` before decoding, so client and server on main returned 404. Unescaped tenants (Python clients) and escaped path remainders from #514 still work. * A part with `"data":null` next to `text`, `raw` or `url` decodes as that content again, as in v2.7.0. A part with only `"data":null` still round-trips as null data (#513). * `a2aacp.Executor` ends a task canceled while queued behind another turn in its context, or while its agent starts, with a canceled event. Before, `Execute` returned without a terminal event, which in cluster mode left the execution (its goroutine, concurrency slot and work item) running forever, since the cancel runs as a separate execution there. * The ACP connection skips and logs agent stdout lines which are not JSON-RPC messages, and a malformed member fails only its own request. Before, one such line (e.g. from a wrapper script) stopped the reader and failed every turn of the agent. * Processes left in the agent's process group after it exits are killed if they ignore SIGTERM, so that MCP servers don't outlive the agent.
🤖 I have created a release *beep* *boop* --- ## [2.8.0](v2.7.0...v2.8.0) (2026-11-06) ### Features * **a2aacp:** add an A2A agent executor for Agent Client Protocol (ACP) agents ([#491](#491), [#492](#492), [#493](#493), [#494](#494), [#530](#530), [#545](#545), [#548](#548), [#552](#552), [#562](#562)) * **a2agrpc:** add GRPCConnectionPool for gRPC client connection reuse (fixes [#109](#109)) ([#382](#382)) ([a2411f7](a2411f7)) * **a2asrv:** add NewErrorSanitizer, an opt-in interceptor which logs request errors in full and sends clients only A2A errors ([#552](#552)) ([ece71bc](ece71bc)) * **a2asrv:** agent card HTTP caching (ETag/304, opt-in Cache-Control) ([#496](#496)) ([313efd9](313efd9)) * implement structured input extension ([#490](#490)) ([367f987](367f987)) ### Bug Fixes * **a2aclient:** honor API key security scheme Location ([#497](#497)) ([c59beb5](c59beb5)) * **a2aclient:** honor configured HTTP authentication schemes ([#502](#502)) ([413de0c](413de0c)) * **a2aclient:** normalize service param keys set by the client and AuthInterceptor ([#479](#479)) ([96f4df0](96f4df0)) * **a2aclient:** return JSON-RPC errors from non-200 responses ([#559](#559)) ([97f1fac](97f1fac)) * **a2acrypto:** reject malformed Unicode before signing ([#450](#450)) ([ec6cb14](ec6cb14)) * **a2aevent:** preserve input-required history order ([#501](#501)) ([72f94a3](72f94a3)) * **a2aevent:** recover the whole artifact when it changes in place ([#485](#485)) ([4d61739](4d61739)) * **a2a:** round-trip null data and nil raw parts through JSON ([#513](#513)) ([186decc](186decc)) * **a2asrv:** make ServiceParams.With nil-safe ([#544](#544)) ([c6042b8](c6042b8)) * **a2asrv:** preserve escaped tenant REST paths ([#514](#514), [#562](#562)) ([f86cf6c](f86cf6c)) * **a2asrv:** preserve numeric precision in raw card ETags ([#546](#546)) ([18c2e72](18c2e72)) * **a2asrv:** reject HEAD before creating task subscriptions ([#481](#481)) ([e641e3c](e641e3c)) * **a2asrv:** split comma-separated A2A-Extensions values ([#519](#519)) ([db83820](db83820)), closes [#516](#516) * **a2av0:** keep security schemes and v0.3 interface in extended agent cards ([#558](#558)) ([196d4bb](196d4bb)), closes [#556](#556) * **client:** accept cached status and artifact stream events ([#508](#508)) ([ea78132](ea78132)) * **client:** honor streaming interceptor error recovery ([#507](#507)) ([737b626](737b626)) * **client:** keep propagated tenants local to each call ([#495](#495)) ([0eaf017](0eaf017)) * **client:** preserve escaped REST path segments ([#488](#488)) ([8880d8f](8880d8f)) * compare and send A2A-Version as Major.Minor ([#555](#555)) ([b5ea753](b5ea753)) * don't fail CancelTask when the canceled execution ends first ([#521](#521)) ([1613ae6](1613ae6)), closes [#518](#518) * don't move a task to FAILED when cancelation retries run out ([#522](#522)) ([247933b](247933b)) * **jsonrpc:** return empty result for successful push config deletion ([#525](#525)) ([42d0738](42d0738)) * pass CancelTask metadata over REST ([#520](#520)) ([a104b2e](a104b2e)), closes [#517](#517) * **pbconv:** preserve JSON data part values ([#503](#503)) ([7c040e0](7c040e0)) * **pbconv:** send pkceRequired for authorization code flows ([#542](#542)) ([cb2c30b](cb2c30b)) * **push:** cap push notification configs per task ([#405](#405)) ([6bb5a68](6bb5a68)) * report executions or cancelations in progress, and messages to terminal tasks in cluster mode, as UnsupportedOperation ([#552](#552)) ([ece71bc](ece71bc)) * **sse:** ignore a leading UTF-8 byte order mark ([#511](#511)) ([248f628](248f628)) * **taskexec:** keep the error when broadcasting an event fails ([#536](#536)) ([636fa9f](636fa9f)) * **taskexec:** report canceler panics during concurrent cancelation ([#535](#535)) ([7ffc680](7ffc680)) * **taskexec:** skip heartbeats for non-positive intervals ([#543](#543)) ([c4158ae](c4158ae)) * **taskexec:** wait for the cancelation result of input-required tasks ([#560](#560)) ([3194abe](3194abe)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: Yaroslav Shevchuk <[email protected]>
Fixes #512
a2a.Partwrote two JSON shapes that its ownUnmarshalJSONthen rejected withunknown part content type:NewDataPart(nil)was written as{"data":null}. Because the wrapper field was a*any,encoding/jsondecoded the null to a nil pointer and the part looked empty.{"data":null}is how ProtoJSON writes adataholdingNULL_VALUE, and since fix(pbconv): preserve JSON data part values #503 the v1 gRPC conversion keeps null data parts. Over JSON-RPC and REST, though, a Go server rejected them.NewRawPart(nil)was written as{"raw":null}. ProtoJSON writes empty bytes as"raw":""and reads"raw":nullas unset.The fix changes only
a2a/core.goand leaves the public API alone:partDatawrapper (omitzeroplusIsZero/MarshalJSON/UnmarshalJSON) records whether thedatakey was present, so a null value decodes toData{Value: nil}. As a result,{"text":"x","data":null}now counts as two contents and is rejected, which matches protojson ("oneof ... is already set").Rawis written as"".Tests:
TestPartJSONCodecEmptyContentcovers null data with and without metadata, nil and empty raw, and empty text.TestPartJSONUnmarshalNullDataWithOtherContentcovers the two-contents case. I wrote the tests first and confirmed they failed onmainfor null data, null data with metadata, nil raw, and text plus null data.Validation (Go 1.26.10, Windows):
go vet ./a2a/...,go build ./...andgolangci-lint run ./a2a/...(v2.15.0) pass on the changed files. The only lint reports are CRLFgoimportsfindings in files I didn't touch, which come from the Windows checkout.go test -count=1 -shuffle=on ./...passes, except for two failures unrelated to this change.TestResolver_FileURLina2aclient/agentcardfails on Windows because of how it builds file paths.TestSSE_PanicAfterClientDisconnectDoesNotLeak/restfailed once with a goroutine-leak timing flake and passed 5/5 on rerun.🤖 Generated with Claude Code