Skip to content

fix(adkrest): drop nil parts when serializing events and scanning the event graph - #2192

Merged
wolo-lab merged 3 commits into
google:mainfrom
PratikDhanave:fix/adkrest-nil-part
Nov 9, 2026
Merged

wolo-lab merged 3 commits into
google:mainfrom
PratikDhanave:fix/adkrest-nil-part

Conversation

@PratikDhanave

@PratikDhanave PratikDhanave commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Two adkrest paths dereference entries of Content.Parts without a nil check:

  • Event.MarshalJSON (server/adkrest/internal/models/event.go) wraps every part in a ProxyPart and reads part.FunctionCall.
  • The event-graph helpers functionalCalls / functionalResponses (server/adkrest/controllers/debug.go) guard Content == nil and Parts == nil but not the elements.

A nil part reaches storage directly: a create-session body with {"events":[{"content":{"parts":[null]}}]} is copied verbatim by ToSessionEvent. After that, every endpoint that serializes the session — CreateSession's response, GetSession, Run, RunSSE — panics inside MarshalJSON (surfacing as a dropped connection/500), and the web UI's GET .../events/{id}/graph panics 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. MarshalJSON drops 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 a null part, 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, no null element, "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 referenced lookup tool, 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-Part class as #2189/#2190, different subsystem (REST serialization/debug).

… 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.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

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 an issue already exists, add Closes: #<number> or Related: #<number> to the description.
  • If not, open one — the link prefills the bug template with your PR title — then reference it the same way.

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 wolo-lab 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.

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. ToSessionEvent copies Content unchanged (event.go L122). With the Vertex AI session service, createAiplatformpbContent reads part.Thought on 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.

Comment thread server/adkrest/internal/models/event.go Resolved
…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.
@PratikDhanave

Copy link
Copy Markdown
Contributor Author

Both test gaps closed in eb5a1fd, and the open output-shape question settled on purpose — by dropping the null slot rather than keeping it:

  • Shape decision: your web-UI point was the decider — rawMessageText's parts.filter(e => e.text) throws on a null element, and I couldn't find anything that relies on part counts round-tripping. So MarshalJSON now omits nil slots entirely; clients never see "parts":[..., null, ...]. This also converges with fix: drop null parts from REST requests and skip nil parts on read #1769's output shape, which should shrink that conflict to the boundary-vs-marshal question. The PR title/description updated to match.
  • event_test.go: now pins the exact output — marshaling [text, nil, functionCall] must produce exactly two parts in order, no null element, "args":{} intact. A MarshalJSON that kept the null (or dropped a real part) fails it.
  • debug_test.go: the graph test now discriminates. The agent carries a lookup tool, and the test asserts the dot output highlights (fills) that tool node — which only happens when the scan finds the call past the nil. A second case puts a FunctionResponse after the nil with no calls present, so the response branch at debug.go L175-180 is actually read. I verified both by mutation: neutering functionalCalls fails the suite now.

Re: the Vertex AI session service still panicking on append (createAiplatformpbContent) — agreed, pre-existing and worth its own issue; happy to file it.

@PratikDhanave PratikDhanave changed the title fix(adkrest): skip nil parts when serializing events and scanning the event graph Drop nil parts when serializing REST events; guard event-graph scans Nov 9, 2026
@wolo-lab wolo-lab changed the title Drop nil parts when serializing REST events; guard event-graph scans fix(adkrest): drop nil parts when serializing events and scanning the event graph Nov 9, 2026

@wolo-lab wolo-lab 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.

lgtm, ty!

@wolo-lab
wolo-lab merged commit 3193128 into google:main Nov 9, 2026
15 checks passed
wolo-lab added a commit that referenced this pull request Nov 16, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants