Skip to content

fix(runner): drop nil parts from live requests - #1795

Merged
wojtas000 merged 4 commits into
google:mainfrom
Trainingcqy:fix/runner-live-nil-parts
Oct 13, 2026
Merged

wojtas000 merged 4 commits into
google:mainfrom
Trainingcqy:fix/runner-live-nil-parts

Conversation

@Trainingcqy

@Trainingcqy Trainingcqy commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

1. Link the issue this change is for.

2. Describe the change:

Problem:

/run_live decodes a null part in a text frame as a nil element and passes the decoded content to runnerLiveSession.Send as is. Send forwards the request to the agent's live session and then iterates over the parts looking for function responses. Forwarding hands the request to the base_flow sender goroutine without reading the parts. Two goroutines read the parts, and neither checks for nil: the goroutine that reads client frames and calls Send panics at runner/runner.go:838 unless a function response comes before the nil part; the base_flow sender goroutine panics at internal/llminternal/googlellm/live_connection.go:102 when the first part is nil, and at :105 when the first part is a function response and a later part is nil; when the first part is neither nil nor a function response, the sender passes the content to genai at :131 and panics inside genai on a failed type assertion. Neither goroutine recovers, so the whole process exits. The process exits the same way when an SDK caller passes a request with a nil part to Send on the session returned by Runner.RunLive.

Solution:

runnerLiveSession.Send drops nil parts before forwarding, and both the request forwarded to the agent and the event written to the session use a copy of the Content with the nil parts removed. Only a request that contains a nil part is copied, and the caller's Content is left unchanged. Both /run_live and SDK callers go through runnerLiveSession.Send. At internal/llminternal/base_flow.go:394-396, the live flow returns an error unless the context carries runconfig.RunConfig.Live. runconfig is an internal package, and outside tests Live is set only in Runner.RunLive, at runner/runner.go:910. A caller outside a live run therefore cannot start the live flow except through the runner.

adk-python validates each frame as a LiveRequest. When a frame with a null part fails validation, adk-python logs an error and stops reading client frames; the connection stays open and the process keeps running. See src/google/adk/cli/api_server.py:2423-2439. This PR takes a different approach: it drops the nil part instead of rejecting the frame. A nil part carries no content, so dropping it loses no data. #1552 noted that nil parts can come from content an SDK user builds by hand or a client decodes from the network; it asked that the Parts accessors in internal/utils skip nil parts instead of dereferencing them, and #1556 made them do so. Other places in the repo do the same: internal/llminternal/contents_processor.go:247-250 drops nil parts when building the model request, and internal/llminternal/googlellm/live_connection.go:66-68 skips them when the live connection sends history. #1769 also drops null parts from /run and /run_sse requests.

Behavior change

What behaves differently for someone already on the current release?

When a /run_live text frame contains a null part, or a request that an SDK caller passes to Send contains a nil part, the process no longer exits. The nil part is dropped before the request is forwarded or written to the session, and the remaining parts are handled as before: if any of them is a function response, the request is not written to the session; otherwise it is written as one user event. When every part is nil, what remains is an empty Content, the same as sending "parts":[] today: nothing is written to the session, the live session ends with empty content, a /run_live client receives close code 1011, and an SDK caller receives the empty content error from the event iterator. Requests without nil parts behave as before.

If the session history already contains a nil part, for example because a message with a null part was sent earlier through /run, opening a /run_live connection still triggers a panic at internal/llminternal/contents_processor.go:872, in the goroutine started at internal/llminternal/base_flow.go:401, and the process exits as well. That path is out of scope for this PR and is fixed by #1769: with #1769's change to contents_processor.go applied on top of this PR, a test against a local stub Live endpoint shows that the process no longer exits.

Testing Plan

Unit Tests:

  • All unit tests pass locally.

With your source change reverted and your tests kept, which test fails?

TestRunner_RunLive_SendDropsNilParts. When the test runs as a whole, its first case, nil before text, panics at runner/runner.go:838 and the test binary aborts. When the cases run one at a time, nil before text, nil after text, and only nil each panic at :838, and nil after function response fails its assertion because the forwarded content still contains a nil part. The req.Content != nil check is covered by existing adkrest live tests such as TestRunLiveHandler_ForwardsBinaryAudio, TestRunLiveHandler_ForwardsRealtimeInputVariants, TestRunLiveHandlerEnforcesMessageSizeLimit, and TestRunLiveHandler_KeepsResponsiveClientThroughSlowSend. These tests send frames without content through the real runner, and with the check removed they panic at runner/runner.go:829 on this branch.

On Linux under WSL, go test -shuffle=on ./... passes with go1.26.6. On Windows, every test from go test -race -shuffle=on ./runner/... ./server/adkrest/... ./internal/llminternal/... ./agent/workflowagents/... passes except TestRunnerCompactsAfterInterval, TestCompactionOverlapWidensTheStoredRange, and TestRunnerTailRetentionCompactsMidInvocation in runner/compaction_test.go, which also fail intermittently on main. These tests do not call RunLive, so they do not reach the changed code. golangci-lint run reports no issues.

Manual End-to-End (E2E) Tests:

examples/bidi was built unmodified, once without the fix and once with it, using the example's own model, gemini-3.1-flash-live-preview, on the Gemini API backend. The steps are the same as in the issue's Steps to Reproduce. Each scenario starts a new server process, opens one WebSocket session, and sends one text frame in the same format as the example frontend static/js/app.js; only the parts differ. The log below is printed by a script that runs these scenarios and is not part of this PR: client: is what the client received, server: is the state of the server process, and the lines under server: list each panic the server printed, where the panic happened, and where its goroutine was started.

Before the fix, all three frames with a null part make the process exit with code 2. For each of them, both the goroutine that reads client frames and the base_flow sender goroutine can panic, and how many panics are printed before the process exits depends on scheduling; in this run, [text, null] printed one from each goroutine, and [null, text] and [null] printed only the sender goroutine's. After the fix, [null, text] and [text, null] get a reply, as [text] does; [null] and [] both end with close code 1011 and empty content; and the process keeps running in all five scenarios.

Log
===== base (main 987c7bc0) | s0 parts [text]
frame: {"content":{"role":"user","parts":[{"text":"Say hello in one short sentence."}]}}
client: 11 events, turnComplete, reply: 'Hello there!'
server: still running

===== base (main 987c7bc0) | s1 parts [null, text]
frame: {"content":{"role":"user","parts":[null,{"text":"Say hello in one short sentence."}]}}
client: connection dropped without a close frame after 0 events
server: exited with code 2
  panic: runtime error: invalid memory address or nil pointer dereference
    at internal/llminternal/googlellm/live_connection.go:102, in the goroutine started at internal/llminternal/base_flow.go:592

===== base (main 987c7bc0) | s2 parts [text, null]
frame: {"content":{"role":"user","parts":[{"text":"Say hello in one short sentence."},null]}}
client: connection dropped without a close frame after 0 events
server: exited with code 2
  panic: runtime error: invalid memory address or nil pointer dereference
    at runner/runner.go:838, in the goroutine started at server/adkrest/controllers/runtime.go:577
  panic: interface conversion: interface {} is nil, not map[string]interface {}
    at google.golang.org/[email protected]/common.go:353, reached from internal/llminternal/googlellm/live_connection.go:131, in the goroutine started at internal/llminternal/base_flow.go:592

===== base (main 987c7bc0) | s3 parts [null]
frame: {"content":{"role":"user","parts":[null]}}
client: connection dropped without a close frame after 0 events
server: exited with code 2
  panic: runtime error: invalid memory address or nil pointer dereference
    at internal/llminternal/googlellm/live_connection.go:102, in the goroutine started at internal/llminternal/base_flow.go:592

===== base (main 987c7bc0) | s4 parts []
frame: {"content":{"role":"user","parts":[]}}
client: close frame 1011 'empty content' after 0 events
server: still running

===== fixed (main 987c7bc0 + fix) | s0 parts [text]
frame: {"content":{"role":"user","parts":[{"text":"Say hello in one short sentence."}]}}
client: 12 events, turnComplete, reply: 'Hello there!'
server: still running

===== fixed (main 987c7bc0 + fix) | s1 parts [null, text]
frame: {"content":{"role":"user","parts":[null,{"text":"Say hello in one short sentence."}]}}
client: 17 events, turnComplete, reply: 'Hello, great to chat with you!'
server: still running

===== fixed (main 987c7bc0 + fix) | s2 parts [text, null]
frame: {"content":{"role":"user","parts":[{"text":"Say hello in one short sentence."},null]}}
client: 11 events, turnComplete, reply: 'Hello there!'
server: still running

===== fixed (main 987c7bc0 + fix) | s3 parts [null]
frame: {"content":{"role":"user","parts":[null]}}
client: close frame 1011 'empty content' after 0 events
server: still running

===== fixed (main 987c7bc0 + fix) | s4 parts []
frame: {"content":{"role":"user","parts":[]}}
client: close frame 1011 'empty content' after 0 events
server: still running

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

@wojtas000 wojtas000 self-assigned this Oct 12, 2026

@wojtas000 wojtas000 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.

Two test cases are missing before this can merge. The fix in runnerLiveSession.Send doesn't need to change.

I reverted the fix and kept your test. Three cases panic at runner/runner.go:838 on main, and nil after function response fails on the forwarded content. With the fix, all four pass under -race. The root module suite also passes. I ran it in a sandbox with no network, and telemetry fails there on main too. Breaking the copy, either by dropping slices.Clone or by writing through *req.Content, makes the test fail as it should.

Two other edits to the new branch leave the runner and adkrest suites green, so the test doesn't pin what they would break. The inline comments have the details.

Separately, and not caused by this PR: an SDK caller sending LiveRequest{RealtimeInput: (*genai.Blob)(nil)} still panics the sender goroutine at internal/llminternal/base_flow.go:610-612. The REST handler always builds a non-nil blob, so /run_live can't trigger it. It's worth a separate issue if you're interested.

Comment thread runner/live_runner_test.go Resolved
Comment thread runner/runner.go Resolved
Comment thread runner/runner.go Resolved
@Trainingcqy

Copy link
Copy Markdown
Contributor Author

@wojtas000

Thanks for the review. The three inline comments are addressed in a7d6967; see each reply for details. I'll file a separate issue for the typed nil *genai.Blob in RealtimeInput.

@wojtas000 wojtas000 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.

Thanks, all three cases are in. I ran the same three edits to Send against a7d6967 merged onto current main, and each one now fails its new case: reversing the kept parts fails nil between texts, dropping RealtimeInput fails nil with realtime input, and copying every request fails no nil. The runner, adkrest and llminternal suites pass under -race.

@wojtas000
wojtas000 merged commit 893687b into google:main Oct 13, 2026
14 checks passed
wolo-lab added a commit that referenced this pull request Oct 14, 2026
* fix(runner): preserve buffered live events at stream end (#1547)

(cherry picked from commit 6576191)

* fix(llminternal): classify a dropped live connection by type, not error text (#1603)

(cherry picked from commit ec1b74c)

* fix(runner): drop nil parts from live requests (#1795)

(cherry picked from commit 893687b)
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.

runner: a nil part in a live request crashes the whole process

2 participants