Skip to content

feat(live): use RunConfig.session_resumption.handle when opening a live session - #6770

Merged
wuliang229 merged 4 commits into
v1from
port-v1-live-session-resumption-handle
Aug 17, 2026
Merged

feat(live): use RunConfig.session_resumption.handle when opening a live session#6770
wuliang229 merged 4 commits into
v1from
port-v1-live-session-resumption-handle

Conversation

@wuliang229

Copy link
Copy Markdown
Collaborator

Summary

Backport of commit eac32c3 (feat(live): use RunConfig.session_resumption.handle when opening a live session, PiperOrigin-RevId: 966066295) from main to v1.

A caller that resumes an earlier live session by passing a handle in RunConfig.session_resumption.handle only got that handle onto the wire. The basic request processor forwards it to LiveConnectConfig, but every other part of the run keys off InvocationContext.live_session_resumption_handle, which was populated exclusively from a server-issued session_resumption_update. The run therefore behaved as if the session were new: it replayed the whole conversation through send_history() even though the server already held that state, declared that history as initial_history_in_client_content, left transparent unset on the Vertex AI backend, and raised instead of reconnecting when the socket dropped before the server issued its first handle.

Seed InvocationContext.live_session_resumption_handle in BaseLlmFlow.run_live from the handle request assembly has already put on llm_request.live_connect_config.session_resumption, before the connect loop, so the first connection is treated as a resumption in the same way as any mid-session reconnect. Reading the assembled request rather than the RunConfig keeps the seed on the same object the reconnect path goes on to write, and honors a handle set by any request processor rather than only one set through RunConfig. Agent transfer is unaffected because it already clears both the invocation handle and the deep-copied run config handle, so a child agent still starts a fresh live session.

Note: Stacks on #6769.

Testing Plan

  • pytest tests/unittests/flows/llm_flows/test_base_llm_flow.py (56 passed)
  • pyink and isort clean.

wuliang229and others added 2 commits August 17, 2026 18:54
Streaming tools and non-blocking tools run as background asyncio tasks that
nothing owns: only an explicit `stop_streaming` call ever cancelled one. When
a live agent run ended for any other reason -- a handoff to another agent,
`task_completed`, the model closing the connection, the caller walking away --
its tools kept running, feeding function responses into a live request queue
that by then belonged to another agent, which never made those calls, or to
nobody at all. The tasks were never awaited either, so a failure in one
surfaced only as a stray asyncio warning.
`BaseLlmFlow.run_live` now cancels the background tools its run started before
it returns, and at a handoff it cancels them before the sub agent takes over
the live request queue rather than when the enclosing run eventually finishes.
Cancellation is best effort: a task that ignores it is logged instead of
stalling the handoff or the caller's teardown.
Stopped tools also give up their registry entry. `_send_to_model` copies every
live request into each registered stream, so a stream left behind by a tool
that is no longer reading kept growing for the rest of the session, one entry
per audio chunk the user spoke.
Co-authored-by: Liang Wu <wuliang@google.com>
PiperOrigin-RevId: 964915958
…ve session
A caller that resumes an earlier live session by passing a handle in
`RunConfig.session_resumption.handle` only got that handle onto the wire. The
basic request processor forwards it to `LiveConnectConfig`, but every other
part of the run keys off `InvocationContext.live_session_resumption_handle`,
which was populated exclusively from a server-issued
`session_resumption_update`. The run therefore behaved as if the session were
new: it replayed the whole conversation through `send_history()` even though
the server already held that state, declared that history as
`initial_history_in_client_content`, left `transparent` unset on the Vertex AI
backend, and raised instead of reconnecting when the socket dropped before the
server issued its first handle.
Seed `InvocationContext.live_session_resumption_handle` in
`BaseLlmFlow.run_live` from the handle request assembly has already put on
`llm_request.live_connect_config.session_resumption`, before the connect loop,
so the first connection is treated as a resumption in the same way as any
mid-session reconnect. Reading the assembled request rather than the
`RunConfig` keeps the seed on the same object the reconnect path goes on to
write, and honors a handle set by any request processor rather than only one
set through `RunConfig`. Agent transfer is unaffected because it already
clears both the invocation handle and the deep-copied run config handle, so a
child agent still starts a fresh live session.
Co-authored-by: Liang Wu <wuliang@google.com>
PiperOrigin-RevId: 966066295
@wuliang229
wuliang229 merged commit 090869b into v1Aug 17, 2026
13 checks passed
@wuliang229
wuliang229 deleted the port-v1-live-session-resumption-handle branch August 17, 2026 19:29
Sign up for freeto 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.

1 participant

@wuliang229