Skip to content

Fix audio transcription deserialization when duration field is absent#512

Merged
Evrard-Nil merged 2 commits into
mainfrom
fix/whisper-duration-deserialization
Mar 26, 2026
Merged

Fix audio transcription deserialization when duration field is absent#512
Evrard-Nil merged 2 commits into
mainfrom
fix/whisper-duration-deserialization

Conversation

@Evrard-Nil
Copy link
Copy Markdown
Collaborator

Summary

  • Add #[serde(default)] to AudioTranscriptionResponse.duration field

Root Cause

The duration field uses #[serde(deserialize_with = "deserialize_duration")], which makes serde require the field to be present in the JSON — even though it's Option<f64>. The inference proxy (vllm-proxy-rs) returns:

{"id":"trans-...","text":"...","usage":{"seconds":1,"type":"duration"}}

No top-level duration field → deserialization fails with missing field 'duration'AudioTranscriptionError::TranscriptionError → mapped to HTTP 502.

Reproduction

# Direct to proxy — works:
curl http://160.72.54.198:8010/v1/audio/transcriptions \
  -H "Authorization: Bearer <token>" \
  -F 'file=@silence.wav' -F 'model=openai/whisper-large-v3'
# → 200 OK

# Through cloud-api — fails:
curl https://cloud-api.near.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer sk-..." \
  -F 'file=@silence.wav' -F 'model=openai/whisper-large-v3'
# → 502 "Audio transcription failed"

Fix

#[serde(default)] allows the field to be absent, deserializing as None.

Verified with standalone test: deserialization of the exact proxy response succeeds after the fix.

The `duration` field on `AudioTranscriptionResponse` uses a custom
`deserialize_with`, which makes serde require the field to be present
in the JSON — even though it's `Option<f64>`. When the inference proxy
(vllm-proxy-rs) returns a response without a top-level `duration` field
(it nests it under `usage.seconds`), deserialization fails with
"missing field `duration`", causing a 502.

Fix: add `#[serde(default)]` so missing `duration` deserializes as `None`.
Copilot AI review requested due to automatic review settings March 25, 2026 21:52
@Evrard-Nil Evrard-Nil temporarily deployed to Cloud API test env March 25, 2026 21:52 — with GitHub Actions Inactive
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical deserialization issue within the audio transcription service. By modifying the AudioTranscriptionResponse structure, it ensures that the system can gracefully handle responses where the duration field is omitted, thereby preventing HTTP 502 errors encountered when processing transcription results from the inference proxy.

Highlights

  • Deserialization Fix: Added #[serde(default)] to the duration field in AudioTranscriptionResponse to correctly handle cases where the field is absent in the JSON payload, preventing deserialization failures.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the AudioTranscriptionResponse struct in crates/inference_providers/src/models.rs by adding the #[serde(default)] attribute to the duration field. This change ensures that the duration field defaults to None if it is not present during deserialization. I have no feedback to provide.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes deserialization of audio transcription responses when providers omit the top-level duration field, preventing avoidable transcription failures (and downstream 502s) in the inference providers layer.

Changes:

  • Add #[serde(default)] to AudioTranscriptionResponse.duration so missing duration deserializes to None.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +995 to 998
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(deserialize_with = "deserialize_duration")]
pub duration: Option<f64>,
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Consider adding a regression unit test (in this file’s existing #[cfg(test)] mod tests) that deserializes an AudioTranscriptionResponse payload where the top-level duration field is absent (like the proxy example) and asserts duration == None. This will prevent future changes to deserialize_with/serde attributes from reintroducing the missing field 'duration' failure.

Copilot uses AI. Check for mistakes.
@claude
Copy link
Copy Markdown

claude Bot commented Mar 25, 2026

PR Review: Fix audio transcription deserialization when duration field is absent

Change: +1 line - adds serde(default) to the duration field on AudioTranscriptionResponse.

Analysis:

The fix is correct. When deserialize_with is specified, serde treats the field as required even if the type is Option. Adding serde(default) restores the expected behavior: a missing duration key short-circuits before calling deserialize_duration and returns None directly.

The three-attribute combination is a standard serde pattern:

  • serde(default) - absent key maps to None
  • serde(deserialize_with = "deserialize_duration") - present key uses custom parsing (already handles null, string, and float variants)
  • serde(skip_serializing_if = "Option::is_none") - serialization behavior unchanged

No logic issues, no privacy/logging concerns, no performance impact.

Approved - minimal, correct fix.

@Evrard-Nil Evrard-Nil requested a review from PierreLeGuen March 25, 2026 23:50
@Evrard-Nil Evrard-Nil temporarily deployed to Cloud API test env March 26, 2026 18:59 — with GitHub Actions Inactive
@Evrard-Nil Evrard-Nil merged commit a400363 into main Mar 26, 2026
2 checks passed
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.

3 participants