Skip to content

fix(openai): decode Responses top_p with arbitrary-precision JSON - #2528

Closed
mzdora wants to merge 1 commit into
0xPlaygrounds:mainfrom
mzdora:fix/2493-responses-arbitrary-precision
Closed

mzdora wants to merge 1 commit into
0xPlaygrounds:mainfrom
mzdora:fix/2493-responses-arbitrary-precision

Conversation

@mzdora

@mzdora mzdora commented Sep 15, 2026

Copy link
Copy Markdown

Description

Fixes #2493.

When a dependency enables serde_json/arbitrary_precision, Serde buffers a fractional top_p as a map through the flattened Responses metadata and the untagged streaming event. Decoding it directly as f64 rejects otherwise valid responses, including the terminal frame carrying token usage.

Deserialize top_p through serde_json::Number before converting it to f64. The public field and serialized request shape stay unchanged; missing/null values remain supported, and invalid types or numbers outside the f64 range still fail.

Changelog

  • (openai) Fix Responses decoding and token-usage preservation when serde_json/arbitrary_precision is enabled.

Migration

None.

Type of change

  • Bug fix

Testing

  • Before the fix: the non-streaming response and completed streaming-event regressions both failed with arbitrary precision enabled; the two compatibility tests passed.
  • cargo test --locked -p rig-core --lib providers::openai::responses_api::tests:: — 92 passed.
  • cargo test --locked -p rig-core --lib --features serde_json/arbitrary_precision providers::openai::responses_api::tests:: — 92 passed.
  • cargo clippy --locked -p rig-core --lib --tests --features serde_json/arbitrary_precision -- -D warnings — passed.
  • cargo fmt --all -- --check and git diff --check — passed.
  • CI now explicitly runs the four regressions with arbitrary precision enabled.

No cassettes were recorded or changed. These tests reproduce a Serde feature-unification failure using raw JSON, without requiring a provider request. Independent full-diff review found no actionable issues. Comprehensive CI has not run on this branch yet.

Checklist

  • My code follows the style guidelines of this project.
  • I have added tests that prove the fix and preserve error handling.
  • I have completed minimal relevant local checks and reported them separately from CI.
  • I did not edit generated changelog or migration files.

@mzdora

mzdora commented Sep 15, 2026

Copy link
Copy Markdown
Author

@gold-silver-copper @joshua-mo-143 hi, could you please review?

@gold-silver-copper

Copy link
Copy Markdown
Contributor

Superseded by #2531

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.

Responses decoder loses token usage when serde_json/arbitrary_precision is enabled (flattened top_p)

2 participants