Skip to content

docs: document and stabilize token/cost field semantics#317

Closed
zhongxuanwang-nv wants to merge 1 commit into
NVIDIA:mainfrom
zhongxuanwang-nv:docs/relay-243-token-cost-semantics
Closed

docs: document and stabilize token/cost field semantics#317
zhongxuanwang-nv wants to merge 1 commit into
NVIDIA:mainfrom
zhongxuanwang-nv:docs/relay-243-token-cost-semantics

Conversation

@zhongxuanwang-nv

@zhongxuanwang-nv zhongxuanwang-nv commented Jun 26, 2026

Copy link
Copy Markdown
Member

Superseded by #330 (recreated with a clean branch name; identical diff).

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: c7e338c1-8de1-4423-a8d8-89a40e1866c5

📥 Commits

Reviewing files that changed from the base of the PR and between 45c2bb2 and 2ec7e1c.

📒 Files selected for processing (7)
  • crates/core/tests/unit/codec/openai_chat_tests.rs
  • crates/core/tests/unit/codec/response_tests.rs
  • crates/core/tests/unit/observability/otel_tests.rs
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
  • docs/observability-plugin/atif.mdx
  • docs/observability-plugin/openinference.mdx
  • docs/observability-plugin/opentelemetry.mdx

Walkthrough

Adds codec round-trip tests for unknown and unmodeled usage fields, an OTEL test for cost-only LLM end attributes, and documentation for token/cost semantics, exporter field mapping, and per-exporter expected output fields.

Changes

Token and cost semantics

Layer / File(s) Summary
Usage and cost contract
docs/integrate-into-frameworks/provider-response-codecs.mdx, crates/core/tests/unit/codec/response_tests.rs, crates/core/tests/unit/codec/openai_chat_tests.rs
Docs define token/cost granularity, usage field normalization rules, CostEstimate provenance, and missing-vs-zero behavior. Tests verify unknown top-level usage keys and completion_tokens_details are dropped on deserialize/serialize round-trips.
Exporter mapping and OTel emission
docs/integrate-into-frameworks/provider-response-codecs.mdx, crates/core/tests/unit/observability/otel_tests.rs
The exporter mapping matrix and stability section document how token/cost fields project across ATIF, OpenInference, and OpenTelemetry. The new OTEL test asserts cost-only nemo_relay.llm.cost.* attributes are emitted with no token or gen_ai keys for an unannotated chat response.
Per-exporter output docs
docs/observability-plugin/atif.mdx, docs/observability-plugin/openinference.mdx, docs/observability-plugin/opentelemetry.mdx
Each exporter doc adds expected output field names for token counts and cost, with links to the canonical semantics reference.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits and accurately summarizes the PR's documentation and stability focus.
Description check ✅ Passed The description includes the required overview, details, reviewer start point, checklist items, and related issue reference.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size:M PR is medium Documentation documentation-related lang:rust PR changes/introduces Rust code labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown

@zhongxuanwang-nv zhongxuanwang-nv self-assigned this Jun 26, 2026
@zhongxuanwang-nv zhongxuanwang-nv added this to the 0.5 milestone Jun 26, 2026
@zhongxuanwang-nv zhongxuanwang-nv added the DO NOT MERGE PR should not be merged; see PR for details label Jun 26, 2026
@zhongxuanwang-nv

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@willkill07 willkill07 changed the title docs: document and stabilize token/cost field semantics (RELAY-243) docs: document and stabilize token/cost field semantics Jun 26, 2026
@zhongxuanwang-nv zhongxuanwang-nv marked this pull request as ready for review June 29, 2026 20:29
@zhongxuanwang-nv zhongxuanwang-nv requested review from a team and lvojtku as code owners June 29, 2026 20:29
@zhongxuanwang-nv zhongxuanwang-nv removed the DO NOT MERGE PR should not be merged; see PR for details label Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/about-nemo-relay/release-notes/known-issues.mdx`:
- Around line 46-50: The known-issues note overstates codec-only cost support in
OpenInference; update the bullet tied to the annotated_response.usage discussion
so it says OpenInference cost attributes are emitted only for USD-denominated
values, while non-USD annotated costs should not be described as appearing
there. Keep the rest of the ATIF vs codec wording consistent, and adjust the
surrounding release-notes text in the same section so it matches the current
canonical mapping for OpenInference and cost handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 8ed92c4d-e566-462e-b014-36676164572b

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5813c and 44d07cf.

📒 Files selected for processing (3)
  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
  • docs/observability-plugin/atif.mdx
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Preview docs
🧰 Additional context used
📓 Path-based instructions (12)
{docs/**,README.md,CONTRIBUTING.md}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

{docs/**,README.md,CONTRIBUTING.md}: For docs-only changes, run targeted checks only if commands, package names, or examples changed. Use just docs for docs-site builds and just docs-linkcheck when links changed
Run docs site build with just docs

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
{docs/**,README.md,CONTRIBUTING.md,**/*.md}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

Run docs link validation with just docs-linkcheck when links change

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
{docs/**,README.md}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

Verify README and docs entry points still match current package names and paths for large or public-facing changes

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
{docs/**,examples/**,README.md}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

Verify examples still run with documented commands for large or public-facing changes

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
{docs/**,README.md,**/Cargo.toml,**/package.json,**/*.md}

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

Ensure renamed public surfaces are reflected consistently in manifests and docs for large or public-facing changes

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
**/*.{md,mdx,py,sh,yaml,yml,toml,json}

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Keep package names, repo references, and build commands current

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
**/*.mdx

📄 CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

In MDX files, top-of-file comments must use JSX comment delimiters: {/* to open and */} to close. Do not use HTML comments for MDX SPDX headers.

MDX top-of-file SPDX comments must use {/* ... */} delimiters instead of HTML comment delimiters (Must-Fix)

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
**/*.{html,md,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Include SPDX license header in HTML and Markdown files using HTML comment syntax

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Update embedded documentation snippets, patch docs, and binding-support notes if examples or supported bindings changed

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
docs/**

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Run just docs or ./scripts/build-docs.sh html to regenerate ignored Fern API reference pages before validation for documentation site changes

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
**

⚙️ CodeRabbit configuration file

**:

AGENTS.md

This file provides guidance to agents, including Claude Code and OpenAI Codex, when working in this repository.

Project Overview

NeMo Relay is a multi-language agent runtime framework for execution scopes, lifecycle events, middleware, plugins, and observability around tool and LLM calls. The core runtime is Rust. Primary supported bindings are Rust, Python, and Node.js. Go, WebAssembly, and the raw C FFI are experimental and source-first.

The shared runtime model is:

  1. Scope stacks decide where work belongs and which scope-local behavior is visible.
  2. Middleware registries decide what guardrails and intercepts run around managed calls.
  3. Plugins install reusable runtime behavior from configuration.
  4. Events record runtime behavior in ATOF form.
  5. Subscribers and exporters consume events in-process or export them to ATIF, OpenTelemetry, OpenInference, or other backends.

Repository Structure

The repository layout separates the Rust runtime, language bindings, documentation,
integration patches, and agent-facing skills.

crates/
  core/       # Rust core runtime crate, published as nemo-relay
  adaptive/   # Adaptive runtime primitives and plugin components
  python/     # PyO3 native extension for the Python package
  ffi/        # Raw C ABI layer used by downstream bindings such as Go
  node/       # NAPI Node.js binding and JavaScript/TypeScript entry points
  wasm/       # wasm-bindgen WebAssembly binding and JS wrappers
python/
  nemo_relay/  # Python wrapper package: scopes, tools, LLM, middleware, typed helpers, plugins, adaptive helpers
  tests/      # Python tests
go/
  nemo_relay/  # Experimental Go CGo binding and tests
fern/         # Fern documentation site
scripts/      # Stable wrappers and helper scripts; build/test/docs entry points live in justfile
third_party/  # P...

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}

⚙️ CodeRabbit configuration file

{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}: Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.
Flag stale examples, missing SPDX headers where required, and instructions that no longer match CI or pre-commit behavior.

Files:

  • docs/about-nemo-relay/release-notes/known-issues.mdx
  • docs/observability-plugin/atif.mdx
  • docs/integrate-into-frameworks/provider-response-codecs.mdx
🔇 Additional comments (2)
docs/integrate-into-frameworks/provider-response-codecs.mdx (1)

318-409: LGTM!

docs/observability-plugin/atif.mdx (1)

202-207: LGTM!

Comment thread docs/about-nemo-relay/release-notes/known-issues.mdx Outdated
Add a canonical Token and Cost Field Semantics section to the provider response codecs page: a Usage/CostEstimate field reference, the per-provider token normalization table, granularity (per-call values vs the per-trajectory final_metrics aggregate), an exporter field-mapping table (ATOF/ATIF/OpenInference/OpenTelemetry), and a stability contract. Add brief field pointers and back-links on the OpenTelemetry, OpenInference, and ATIF exporter pages.

Lock the contract with characterization tests: the OpenTelemetry LLM span emits cost only (no token attributes), Usage ignores unmodeled provider subfields, and OpenAIChatCodec drops completion_tokens_details. No runtime behavior change.

Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
@zhongxuanwang-nv zhongxuanwang-nv force-pushed the docs/relay-243-token-cost-semantics branch from 45c2bb2 to 2ec7e1c Compare June 29, 2026 23:01
@zhongxuanwang-nv zhongxuanwang-nv deleted the docs/relay-243-token-cost-semantics branch June 29, 2026 23:01
@zhongxuanwang-nv

Copy link
Copy Markdown
Member Author

Superseded by #330 (recreated with a clean branch name; identical diff). Closing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation documentation-related lang:rust PR changes/introduces Rust code size:M PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant