Repository navigation
fix(adkrest): drop nil parts when serializing events and scanning the event graph - #2192
Conversation
… event graph Event.MarshalJSON wrapped every entry of Content.Parts in a ProxyPart and read part.FunctionCall without a nil check, and the event-graph helpers functionalCalls/functionalResponses guarded Content and Parts but not the elements. A nil part reaches storage directly - a create-session body with "parts":[null] is copied verbatim by ToSessionEvent - after which every endpoint that serializes the session (CreateSession, GetSession, ListSessions, Run, RunSSE) panics in MarshalJSON, and the web UI's event-graph endpoint panics in the scan. Skip nil entries in all three loops, keeping the slot in the marshaled parts so counts round-trip. Regression tests cover the marshal path and the event-graph handler; both panic before the fix.
|
Thanks for the PR, @PratikDhanave. One thing before review. Our contribution guide asks for an issue behind each change, and I could not find one linked here.
If this is a small doc or typo fix, ignore me. A maintainer can open the issue for you if you would rather. |
wolo-lab
left a comment
There was a problem hiding this comment.
Must change before merge: the two test gaps noted inline, in debug_test.go and event_test.go. Everything else below is non-blocking.
The fix does what the description says. Through adkrest.NewServer with the in-memory session service, a create-session body whose parts are [{"text":"hi"}, null, {"functionCall":{"name":"f"}}] drops the connection on both the POST and the follow-up GET on main. On this branch both return 200 with the null in place and "args":{} intact, and the same body without the null serializes identically on both. One correction to the description: list sessions does not panic on main, because it returns sessions without their events.
Two things for whoever merges, neither caused by this PR:
- The nil part is still stored as sent.
ToSessionEventcopiesContentunchanged (event.go L122). With the Vertex AI session service,createAiplatformpbContentreadspart.Thoughton every part (vertexai_client.go L727-L729) and panics on a nil one, so the same create-session body would still fail there during the append. I checked the function directly but did not run it against a Vertex AI backend. - #1769 changes the same four files and takes the other approach. It drops null parts at the REST boundary and compacts them in
MarshalJSON. The two PRs conflict, so it is worth settling which shape the REST output should have before either lands.
…past a nil
Review follow-up, settling the open shape question on purpose:
MarshalJSON now drops the nil slot instead of keeping it, so REST
clients - including the bundled web UI, which reads fields off every
part it renders - never receive a null part. The marshal test pins the
exact output: two parts, order preserved, no null element, args kept
as {}.
The event-graph test now discriminates: the agent carries a lookup
tool, and the dot output highlights that tool node only when
functionalCalls/functionalResponses actually find the call (or, in the
second case, the response) past the nil part. Neutering either scan
fails the test; before, only the status code was checked.
|
Both test gaps closed in eb5a1fd, and the open output-shape question settled on purpose — by dropping the null slot rather than keeping it:
Re: the Vertex AI session service still panicking on append ( |
…1720, #2106, #2090, #1870, #1988, #2052, #2107, #2199, #2191, #2192) (#2358) * fix(server/triggers): honor MaxConcurrentRuns in PubSubController (#1720) (cherry picked from commit 26495ae) * fix(adkrest): let AutoCreateSession reach /run and /run_sse (#2106) (cherry picked from commit f6da03a) * fix(adkrest): answer [] from /run when a run yields no events (#2090) (cherry picked from commit 0159a2e) * fix(adkrest): include timestamp in REST Event model (#1870) (cherry picked from commit 4db0bd9) * fix(adkrest): preserve debug span attribute types (#1988) (cherry picked from commit c377836) * fix(triggers): use timer-and-select for context-aware retry backoff (#2052) (cherry picked from commit 123fea9) * fix(adkrest): answer 500, not 404, when /run cannot read the session (#2107) (cherry picked from commit 8ce8f01) * fix(agentengine): preserve fractional seconds in event timestamp encoding (#2199) (cherry picked from commit c00807e) * fix(adkrest): treat MaxConcurrentRuns<=0 as unlimited in the Eventarc trigger (#2191) (cherry picked from commit 2278f8f) * fix(adkrest): drop nil parts when serializing events and scanning the event graph (#2192) (cherry picked from commit 3193128)
Problem
Two adkrest paths dereference entries of
Content.Partswithout a nil check:Event.MarshalJSON(server/adkrest/internal/models/event.go) wraps every part in aProxyPartand readspart.FunctionCall.functionalCalls/functionalResponses(server/adkrest/controllers/debug.go) guardContent == nilandParts == nilbut not the elements.A nil part reaches storage directly: a create-session body with
{"events":[{"content":{"parts":[null]}}]}is copied verbatim byToSessionEvent. After that, every endpoint that serializes the session —CreateSession's response,GetSession,Run,RunSSE— panics insideMarshalJSON(surfacing as a dropped connection/500), and the web UI'sGET .../events/{id}/graphpanics in the scan.The codebase defends against nil parts in ~10 other walks (
session/session.go,contents_processor,storage_session, the summarizer, and the recent #2189/#2190); these three loops were the stragglers.Change
Skip nil entries in all three loops.
MarshalJSONdrops the nil slot from the output (settled per review): REST clients — including the bundled web UI, which reads fields off every part it renders — never receive anullpart, and nothing was found relying on part counts round-tripping. Regression tests:TestMarshalEventDropsNilParts(models) — marshals an event with[text, nil, functionCall]parts and pins the exact output shape: exactly two parts in order, nonullelement,"args":{}intact.TestEventGraphHandlerToleratesNilParts(controllers) — drives the event-graph endpoint over events whose parts put a function call (and, in a second case, a function response with no calls) after a nil part, against an agent carrying the referencedlookuptool, and asserts the dot output highlights the tool node — which only happens when the scan finds the part past the nil. Neutering either scan fails the test (verified by mutation).Both panic before the fix.
Verification
go test ./server/adkrest/... -race -count=1— all packages pass.golangci-lint run ./server/adkrest/...— 0 issues.Same nil-
Partclass as #2189/#2190, different subsystem (REST serialization/debug).