From 4c29482f0a2c8a3011b2bd36fd2cfc8c988605e5 Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Wed, 25 Nov 2026 18:30:32 +0000 Subject: [PATCH] google_ai: Default citation_sources when Gemini omits it (#67474) Last night Gemini models kept failing right before they finished. A chunk carried `citationMetadata` without `citationSources`, deserializing `CitationMetadata` failed, and the response was treated as a failure. The hosted path is fixed in Cloud; this PR adds the same default to the field in Zed's client, so requests made directly to the Gemini API don't fail the same way. Release Notes: - Fixed Gemini responses failing when they included citation metadata without citation sources. --- crates/google_ai/src/google_ai.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/google_ai/src/google_ai.rs b/crates/google_ai/src/google_ai.rs index f2edaad6a7c..c52429cb89f 100644 --- a/crates/google_ai/src/google_ai.rs +++ b/crates/google_ai/src/google_ai.rs @@ -742,6 +742,8 @@ pub struct CitationSource { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CitationMetadata { + /// Omitted by the API when empty. + #[serde(default)] pub citation_sources: Vec, } @@ -1135,6 +1137,27 @@ mod tests { )); } + #[test] + fn citation_metadata_without_sources_deserializes() { + let response: GenerateContentResponse = serde_json::from_value(json!({ + "candidates": [{ + "content": {"role": "model", "parts": [{"text": "Done"}]}, + "finishReason": "STOP", + "citationMetadata": {} + }] + })) + .unwrap(); + let candidate = &response.candidates.unwrap()[0]; + assert!( + candidate + .citation_metadata + .as_ref() + .unwrap() + .citation_sources + .is_empty() + ); + } + fn completion_error(read_error: Option) -> LanguageModelCompletionError { futures::executor::block_on(async { let client = FakeHttpClient::create(move |_| async move {