Skip to content

fix: preserve Google LLM fallback timeouts#5999

Closed
he-yufeng wants to merge 1 commit into
livekit:mainfrom
he-yufeng:fix/google-llm-http-timeout-merge
Closed

fix: preserve Google LLM fallback timeouts#5999
he-yufeng wants to merge 1 commit into
livekit:mainfrom
he-yufeng:fix/google-llm-http-timeout-merge

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Fixes #5972.

Summary

  • preserve caller-provided Google HttpOptions while injecting LiveKit connection timeouts when no timeout is set
  • copy the caller options before adding LiveKit headers/timeouts so the original options object is not mutated
  • add a regression test that captures the outgoing GenerateContentConfig

To verify

  • PYTHONPATH=livekit-agents;livekit-plugins/livekit-plugins-google python -m pytest tests/test_plugin_google_llm.py -q
  • python -m ruff check livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py tests/test_plugin_google_llm.py
  • python -m ruff format --check livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py tests/test_plugin_google_llm.py
  • git diff --check

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +479 to +484
if is_given(self._llm._opts.http_options):
http_options = self._llm._opts.http_options.model_copy(deep=True)
else:
http_options = types.HttpOptions()
if http_options.timeout is None:
http_options.timeout = int(self._conn_options.timeout * 1000)

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.

🚩 Realtime API has the same mutation bug that this PR fixes in LLM

The realtime_api.py:465-472 still uses the old or pattern without deep copy:

http_options = self._opts.http_options or types.HttpOptions(
    timeout=int(self._opts.conn_options.timeout * 1000)
)

This mutates the original self._opts.http_options object when adding headers at line 471-472 and setting api_version at line 469. While the header mutation is idempotent (same key overwritten with same value), the api_version mutation could be more consequential if the model is reused across sessions with different api_version requirements. The same fix applied here (deep copy + timeout merge) should likely be applied to realtime_api.py as well.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@he-yufeng

Copy link
Copy Markdown
Contributor Author

Closing because current main now preserves caller HTTP options and only fills in the connection timeout when the caller left it unset. Main also copies the headers before adding the LiveKit client header, which is stricter than this branch by avoiding mutation of caller-owned data. The original timeout-loss bug is therefore already fixed upstream.

@he-yufeng he-yufeng closed this Jun 9, 2026
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.

livekit-plugins-google: caller-set http_options silently drops conn_options.timeout (disables FallbackAdapter timeout)

1 participant