Skip to content

feat(llmobs): report Nova Sonic text token counts - #20819

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 33 commits into
mainfrom
codex/novasonic-token-breakdown
Oct 29, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 33 commits into
mainfrom
codex/novasonic-token-breakdown

Conversation

@ZStriker19

@ZStriker19 ZStriker19 commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Preserves Nova Sonic 2 cumulative input/output text counters as per-turn input_text_tokens and output_text_tokens alongside the existing audio counts. Each modality uses an independent baseline. Reported zeros are retained, and missing or invalid counter fields remain absent.

Validates combined audio/text deltas against the inclusive aggregate. Conflicting text is omitted while independently valid audio is retained. Recovery from observed aggregate-counter gaps spanning turns suppresses ambiguous aggregate/modality counts while reestablishing their baselines.

Updates Nova integration/test ownership to MLObs and documents the named-token rules under .agents/skills, preserving .claude/skills as the shared symlink. Includes current main and retains its native UUID implementation, registration updates, and supported Python matrix.

Testing

  • scripts/run-tests -r --venv 25344eb73ed4: 215 passed, Python 3.12.15 and aws-sdk-bedrock-runtime 0.11.0, after rebuilding against the merged main.
  • Regressions cover input/output joint overflow, the valid 8-audio/2-text boundary, multiple usage events, recovery across turns, and named modality behavior across observed aggregate-counter gaps.
  • scripts/lint checks: passed, including mypy, security, and structural checks.
  • The repository CODEOWNERS parser resolves both Nova implementation and test/fixture paths to @DataDog/ml-observability; diff whitespace checks pass.

Risks

Optional text counts remain absent when attribution is incomplete or inconsistent. Inclusive totals and independently valid audio retain their existing semantics.

An entire turn without any usageEvent can still have its unknown usage included in the next turn's cumulative delta. This pre-existing aggregate/audio accounting case is tracked separately in #21344; this PR does not claim to fix it.

Additional Notes

The initial Nova Sonic integration from #20524 is already merged into main. Its existing release note remains unchanged; the new Feature note covers the additional named text-token metrics. The PR is based on main and no longer requires that prerequisite to merge first.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

.agents/skills/llmobs-integrations/references/nova-sonic.md             @DataDog/ml-observability
.github/CODEOWNERS                                                      @DataDog/python-guild @DataDog/apm-core-python
ddtrace/contrib/internal/aws_sdk_bedrock_runtime/__init__.py            @DataDog/python-guild @DataDog/apm-idm-python
ddtrace/llmobs/_integrations/aws_sdk_bedrock_runtime_utils.py           @DataDog/ml-observability
releasenotes/notes/llmobs-nova-sonic-text-tokens-16c552223a5b7cc3.yaml  @DataDog/apm-python
tests/contrib/aws_sdk_bedrock_runtime/test_sonic.py                     @DataDog/python-guild @DataDog/apm-idm-python
tests/contrib/aws_sdk_bedrock_runtime/test_sonic_llmobs.py              @DataDog/python-guild @DataDog/apm-idm-python

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 106 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 106 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=122)
ddtrace.llmobs._integrations.openai_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.aiguard._api_client -×-> ddtrace.trace  (product:aiguard -> product:tracing, score=120)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._integrations.pydantic_ai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 1 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2ff069b | Docs | View more details | Give us feedback!

@ZStriker19
ZStriker19 force-pushed the codex/novasonic-audio-turns branch from ab9d7b2 to 1919a75 Compare October 5, 2026 20:52
ZStriker19 and others added 11 commits October 6, 2026 12:10
Move the Python 3.12 and 3.13 locks from the retired .riot directory to tests/requirements_locks without changing dependency pins. This matches the suitespec lock paths and existing CODEOWNERS rule.

Validation: scripts/test-requirements check validated all 2208 concrete locks; scripts/lint checks passed.
Snapshot caller LLMObs identity and metadata before the SDK invocation can
outlive its caller. Scope turn emission to that snapshot and restore the
receiver context on every exit, using the turn root for each direct child.
Preserve application tags in propagated contexts and remove the obsolete
post-creation parent-ID repair from the integration base.

Keep late audio on an interrupted response while user speech is unfinished,
and ignore late END_TURN events that would extend its interruption boundary.
Respect configured event-size limits when allocating shared audio payload
budget. Finalize input, output, and duplex context-entry failures without
replacing SDK exceptions or cancellation.

Validation: 99 Nova tests pass on each of Python 3.12 and 3.13; 92 shared
propagation/agent-attribution tests pass. Full scripts/lint checks pass.
Import analysis finds no new cycles or violating dependency edges versus
the prior PR head; all existing tests and recorded-session replays pass.
Only populate aggregate token metrics after a valid usage counter arrives.
Preserve explicit zeros, derive totals only from two known directions, and
reset presence with each turn without changing cumulative deduplication.

Track observed audio per turn and direction independently of byte retention.
Keep empty error/tool-only content empty, use fallback markers only for
observed audio that cannot be attached, and preserve real inline audio.

Add usage, close/error/cancellation, audio-presence and restart regressions.
The restart tests confirm that distinct LLMObs provider objects share the
same ContextVar and preserve caller identity/application/sampling context.

Validation: 127 Nova Sonic tests passed on each of Python 3.12 and 3.13;
full scripts/lint checks passed.
@ZStriker19
ZStriker19 marked this pull request as ready for review October 20, 2026 21:06
Base automatically changed from codex/novasonic-audio-turns to main October 22, 2026 21:59
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot requested a review from a team as a code owner October 22, 2026 21:59
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot requested review from BridgeAR and removed request for a team October 22, 2026 21:59

@datadog-prod-us1-6 datadog-prod-us1-6 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.

Bits Code Review: FAIL

A turn with no usage event bypasses gap tracking, causing the next reported cumulative increase—including audio and text tokens—to be attributed entirely to a later turn.

Open Bits AI session

🤖 Bits Code Review · Commit 548c0e4

Comment thread ddtrace/llmobs/_integrations/aws_sdk_bedrock_runtime_utils.py

@XG-xin XG-xin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just the question from bot's review, otherwise looks good to me!

@brettlangdon brettlangdon 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.

should you also update CODEOWNERS for ddtrace/contrib/internal/aws_sdk_bedrock_runtime and tests/contrib/aws_sdk_bedrock_runtime to be for MLObs?

Comment thread .claude/skills/llmobs-integrations/references/implementation-guide.md Outdated
@ZStriker19
ZStriker19 requested a review from a team as a code owner October 28, 2026 21:02
@ZStriker19
ZStriker19 requested review from brettlangdon and removed request for a team October 28, 2026 21:02
@ZStriker19

Copy link
Copy Markdown
Collaborator Author

The missing-usage-event finding is confirmed in the existing aggregate/audio accounting and is tracked in #21344. This PR keeps that correction separate from the named text counters.

@datadog-prod-us1-6 datadog-prod-us1-6 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.

Bits Code Review: PASS

More details

The text-token accounting preserves explicit zeros and omits conflicting text without discarding independently valid audio. Static inspection supports the handling of aggregate gaps; runtime behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 0d15be4

@ZStriker19
ZStriker19 force-pushed the codex/novasonic-token-breakdown branch from 9c072b2 to 2ff069b Compare October 28, 2026 21:52
@ZStriker19
ZStriker19 requested a review from juanjux October 28, 2026 21:55
@ZStriker19

Copy link
Copy Markdown
Collaborator Author

/code blockers

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-29 03:43:00 UTC ℹ️ Start processing command /code blockers


2026-10-29 03:43:01 UTC

Checking merge blockers for #20819...


2026-10-29 03:43:02 UTC

No merge blockers detected.

@ZStriker19

Copy link
Copy Markdown
Collaborator Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-29 03:43:16 UTC ℹ️ Start processing command /merge


2026-10-29 03:43:20 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 1h (p90).


2026-10-29 04:14:41 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 9a1b0e1 into main Oct 29, 2026
491 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the codex/novasonic-token-breakdown branch October 29, 2026 04:14
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.

4 participants