fix(google): report a bad tool schema instead of ending the session in silence - #2548
rosetta-livekit-bot[bot] wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 2cc4c63 The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| if (schema[field] !== undefined && typeof schema[field] !== 'number') { | ||
| throw new TypeError(`${field} must be a number`); | ||
| } |
There was a problem hiding this comment.
🟡 Invalid numeric constraints evade attribution
Non-finite numbers and invalid count constraints pass validateGeminiSchema. Gemini rejects them later, so the connection error omits the originating tool name.
Learn more
JSON Schema count constraints such as minLength, maxItems, and minProperties accept only nonnegative integers. Numeric bounds such as minimum and maximum still require finite numbers. JavaScript reports NaN, Infinity, negative numbers, and fractions as number, so the current check accepts values Gemini rejects. The rejection then occurs after toFunctionDeclarations has returned, outside the per-tool wrapper.
Example: A raw tool schema with minLength: -1 passes this validator. Gemini rejects the Live connection, and the emitted error cannot name that tool. The same happens with minimum: NaN; serialization can also turn that value into null.
Recommended fix: Validate all numeric fields with Number.isFinite. Additionally require Number.isInteger(value) && value >= 0 for item, length, and property count constraints. Add regression cases for negative, fractional, NaN, and infinite values.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
@livekit/agents-plugin-googlePorts livekit/agents#7371.
Source diff coverage
Source diff classification
livekit-agents/livekit/agents/llm/_provider_format/google.pyplugins/google/src/utils.ts. The JS target already has the source refactor's unified raw/generated conversion intoFunctionDeclarations; declaration conversion remains shared, and schema failures are now associated with the current tool.livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/realtime_api.pyplugins/google/src/realtime/realtime_api.ts. Connect-config construction now runs inside the existingtry, so schema failures reach realtime error reporting and connection failure handling.livekit-plugins/livekit-plugins-google/livekit/plugins/google/utils.pyplugins/google/src/utils.ts. The JS SDK has TypeScript interfaces instead of Pydantic runtime validation, so the missing runtime validation is implemented for Gemini's numeric schema constraints and wrapped with the tool name.tests/test_schema_gemini.pyplugins/google/src/utils.test.ts. The same invalidminLength: "many"raw schema asserts that the error names toolbad, adapted to Vitest and JS tool APIs.No source files were classified as not applicable.
Validation
pnpm test plugins/google(71 passed, 2 skipped)pnpm buildpnpm --filter @livekit/agents-plugin-google lint(passes; 3 pre-existing warnings)pnpm format:checkpnpm lintwas run but remains blocked by the pre-existing@typescript-eslint/no-misused-promiseserror inplugins/openai/src/ws/llm.ts:127.cue-clivoice-mode validation was attempted with a temporary malformed-schema Gemini agent, but the Cue room connection failed before dispatch with401 Unauthorized - invalid API key; no framework events were produced.Ported from livekit/agents#7371
Original PR description
Problem: The Gemini realtime session built its connect config one line above the
trythat wraps the connection, so a tool schema the plugin cannot convert raised past the retry loop and past_emit_error.@utils.log_exceptionswrote one line to the worker log and swallowed the rest, so the agent joined the room, published its microphone track, and then never heard or spoke.Fix: The config is now built inside the
try, so the failure reaches_emit_error(recoverable=False)andAPIConnectionErrorlike any other connect failure. The error also names the tool, which until now pointed only at a JSON Schema keyword.Follows #7353. Refs #7349.
Context for reviewing and coding agents