Skip to content

fix(google): omit session_resumption when handle is None - #7254

Open
rrfunde wants to merge 5 commits into
livekit:mainfrom
rrfunde:fix/google-realtime-session-resumption-handle-none
Open

fix(google): omit session_resumption when handle is None#7254
rrfunde wants to merge 5 commits into
livekit:mainfrom
rrfunde:fix/google-realtime-session-resumption-handle-none

Conversation

@rrfunde

@rrfunde rrfunde commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Summary

When connecting to the Gemini Realtime API, _build_connect_config unconditionally set:

session_resumption=types.SessionResumptionConfig(
    handle=self._session_resumption_handle
)

On initial connect, self._session_resumption_handle is None. Passing SessionResumptionConfig(handle=None) causes Gemini Realtime (e.g. gemini-2.5-flash-native-audio-latest) to reject the WebSocket connection with error 1008 (policy violation).

This change only includes session_resumption in LiveConnectConfig when _session_resumption_handle is not None, preserving transparent if configured.

Fixes #5102

Testing

  • Added unit tests in tests/test_plugin_google_realtime.py verifying that:
    1. session_resumption is None when connecting without a prior handle.
    2. session_resumption is populated when a handle is configured.
  • uv run pytest tests/test_plugin_google_realtime.py passed (28 tests).
  • uv run ruff check passed.

Passing SessionResumptionConfig(handle=None) on initial connection causes
Gemini Realtime API to reject the connection with 1008 policy violation.
Only include SessionResumptionConfig in LiveConnectConfig when a handle is
present.

Fixes livekit#5102
@rrfunde
rrfunde requested a review from a team as a code owner September 12, 2026 11:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-12T16:22:04.327029Z c27b2ae New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

devin-ai-integration[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46535fa255

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1299 to +1300
if self._session_resumption_handle is not None
else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve explicit resumption config before a handle exists

When a caller explicitly enables session resumption for a fresh supported Live session, for example with SessionResumptionConfig(transparent=True), the handle is necessarily None until the server issues the first one. This condition silently drops the caller's entire configuration, so the server is not asked to provide resumption updates and a later reconnect cannot resume the session. Omit the field only when no configuration was supplied and no handle exists; an explicitly supplied handle-less configuration still needs to be sent.

Useful? React with 👍 / 👎.

@rrfunde

rrfunde commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback:

  • Updated the session_resumption condition in _build_connect_config to include session_resumption if self._session_resumption_handle is not None or is_given(self._opts.session_resumption).
  • Explicitly provided handle-less configurations (e.g. SessionResumptionConfig(transparent=True)) are now preserved on initial connection to request resumption updates, while still omitting session_resumption by default when neither a handle nor explicit config is provided.
  • Added a unit test in tests/test_plugin_google_realtime.py covering explicit handle-less resumption configuration.

devin-ai-integration[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 807eccfddc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1301 to +1302
is_given(self._opts.session_resumption)
and self._opts.session_resumption.transparent is not None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve explicit empty resumption requests

On a supported Live model, SessionResumptionConfig() is the normal initial opt-in for nontransparent session resumption: it has neither a prior handle nor a transparent value, but its presence requests the updates that will supply the first handle. This condition treats that explicit request exactly like NOT_GIVEN, so the server is never asked for updates and the session can never acquire a handle to resume with. The newly added test_empty_session_resumption_config_is_omitted is fresh evidence for this remaining case after the earlier comment's transparent=True example was fixed; distinguish an explicitly supplied empty config from an omitted option.

Useful? React with 👍 / 👎.

@rrfunde

rrfunde commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Fixed: Guarded against empty SessionResumptionConfig() by checking that transparent is not None when is_given, preventing empty sessionResumption payload from being sent to Gemini.

@rrfunde

rrfunde commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Addressed review feedback: preserved explicitly provided session_resumption configuration (SessionResumptionConfig()) even when handle is not yet available, allowing clients to opt in to receiving session resumption updates and initial handles from Gemini.

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.

bug(google): session_resumption with handle=None causes 1008 on gemini-2.5-flash-native-audio-latest

1 participant