Skip to content

fix(pydantic-ai): record audio duration usage - #815

Merged
Abhijeet Prasad (AbhiPrasad) merged 3 commits into
mainfrom
abhi/sdk-431-record-pydantic-ai-audio-duration-usage
Oct 1, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 3 commits into
mainfrom
abhi/sdk-431-record-pydantic-ai-audio-duration-usage

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Preserve Pydantic AI audio_seconds under metadata.pydantic_ai_usage.audio_seconds, outside canonical metrics.
  • Feature-detect the usage field so older supported Pydantic AI versions remain unaffected.

Validation

  • mise exec -- nox -s 'test_pydantic_ai_integration(latest)' -- -k test_audio_seconds_is_recorded_as_metadata — passed with Pydantic AI 2.51.0.
  • mise exec -- nox -s 'test_pydantic_ai_integration(1.10.0)' -- -k test_audio_seconds_is_recorded_as_metadata — passed; confirms older usage objects remain unaffected.
  • The focused extraction test uses Pydantic AI's actual RequestUsage and ModelResponse types. It does not make a provider request or use VCR.
  • Commit hooks passed: Ruff format/check, codespell, and stale-cassette checks.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T20:24:25.920517Z 1cc7a8e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfae3b4550

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment on lines +1403 to +1405
audio_seconds = getattr(usage, "audio_seconds", None)
if audio_seconds is not None:
metrics["audio_seconds"] = float(audio_seconds)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Store nonstandard audio duration outside metrics

For every response that supplies RequestUsage.audio_seconds, this introduces audio_seconds as a new top-level metric even though it is not part of the standardized Braintrust integration metric schema. Downstream usage reporting will not recognize it consistently; preserve this provider-specific value in deliberately named metadata, or first add a sanctioned normalized metric to the instrumentation specification.

Useful? React with 👍 / 👎.

Comment on lines +1403 to +1405
audio_seconds = getattr(usage, "audio_seconds", None)
if audio_seconds is not None:
metrics["audio_seconds"] = float(audio_seconds)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add regression coverage for audio duration extraction

This new response-shaping branch has no test proving that a current RequestUsage records the intended value while older supported Pydantic AI versions remain unaffected, so a provider model or attribute-shape change can silently drop the metric or make float(audio_seconds) fail without CI detecting it. Add a reproducing integration test before relying on this compatibility path, as required for bug fixes.

AGENTS.md reference: AGENTS.md:L25-L28

Useful? React with 👍 / 👎.

@lforst Luca Forstner (lforst) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would love if we put this into the spec too!

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit b4a204c into main Oct 1, 2026
83 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi/sdk-431-record-pydantic-ai-audio-duration-usage branch October 1, 2026 15:39
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.

2 participants