Skip to content

feat(observability): expose one-hour cache writes - #1189

Merged
ayushag-nv merged 2 commits into
NVIDIA-NeMo:mainfrom
soumilinandi:soumilin/cache-ttl-accounting
Oct 30, 2026
Merged

ayushag-nv merged 2 commits into
NVIDIA-NeMo:mainfrom
soumilinandi:soumilin/cache-ttl-accounting

Conversation

@soumilinandi

@soumilinandi soumilinandi commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Preserves the one-hour cache-write token subset in libsy.client_call observability and forwards it through the Switchyard NeMo Relay plugin.

Why

Switchyard already retains ephemeral_1h_input_tokens internally, but libsy observability exported only the combined cache-creation count. Relay therefore could not distinguish five-minute and one-hour cache writes for precise pricing.

This is an accounting-only change. It does not alter request construction, cache TTL selection, routing, or model behavior.

Notes for reviewers

Start with:

  • crates/libsy-llm-client/src/observability.rs for the new span attribute.
  • crates/switchyard-nemo-relay-plugin/src/span_capture.rs for Relay forwarding.

Focused libsy observability and Relay plugin tests cover propagation of a mixed cache-write split. Existing responses without the optional one-hour field retain their current behavior

Summary by CodeRabbit

  • New Features
    • Usage reporting now includes a separate count of input tokens used to create a one-hour cache, when that count is available. This value is preserved independently from total input tokens and other cache usage counts, making usage details more informative without changing how existing token counts are calculated.

@soumilinandi
soumilinandi requested a review from a team as a code owner October 30, 2026 22:30
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The client now records optional one-hour cache-creation input tokens in tracing. The relay captures the field as ephemeral one-hour cache usage. Tests check the recorded value, the relay mapping, and the input-token calculation.

Changes

One-hour cache token usage

Layer / File(s) Summary
Record one-hour cache usage
crates/libsy-llm-client/src/observability.rs, crates/libsy-llm-client/src/run.rs, crates/libsy-llm-client/tests/observability.rs
The client records the optional one-hour cache-creation token count as gen_ai.usage.cache_creation_1h.input_tokens. The observability test checks that the span contains the value.
Map cache usage to response
crates/switchyard-nemo-relay-plugin/src/span_capture.rs
The relay allowlists the tracing field and maps it to usage.cache_creation.ephemeral_1h_input_tokens. The test checks that this value is kept separate while the input-token count excludes cache-read and standard cache-creation tokens.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 7579c

This change exposes one-hour cache-write counts in observability and forwards them to Relay without altering requests or routing. Cost estimates will not separate five-minute and one-hour writes until the Relay dependency reads the new field; that is a follow-up and does not block merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: exposing one-hour cache writes in observability.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the tracing stream,
One-hour tokens join the scheme.
The relay keeps their count in view,
While input totals stay true.
Then hops away beneath the moon.

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

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

Additional comments: 1
crates/switchyard-nemo-relay-plugin/src/span_capture.rs-187-190: 1

187-190: Major · Data Integrity & Integration · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Preserve the split through Relay pricing.

Relay 0.10.0’s RawAnthropicUsage does not read cache_creation, and its pricing code applies one rate to all cache writes. Mixed five-minute and one-hour writes therefore still receive a single-rate estimate. (raw.githubusercontent.com)

Coordinate Relay codec and pricing support, and add an integration test that checks the resulting cost.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c5dccc2 and 7579ccc.

Files selected for processing: 4
  • crates/libsy-llm-client/src/observability.rs
  • crates/libsy-llm-client/src/run.rs
  • crates/libsy-llm-client/tests/observability.rs
  • crates/switchyard-nemo-relay-plugin/src/span_capture.rs

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@ayushag-nv ayushag-nv 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.

Looks good to me. Please fix the DCO stuff.

Signed-off-by: Soumili Nandi <soumilin@nvidia.com>
Signed-off-by: Soumili Nandi <soumilin@nvidia.com>
@soumilinandi
soumilinandi force-pushed the soumilin/cache-ttl-accounting branch from e69474f to ae69f77 Compare October 30, 2026 22:43
@ayushag-nv
ayushag-nv enabled auto-merge (squash) October 30, 2026 22:49
@ayushag-nv
ayushag-nv merged commit 1faddb4 into NVIDIA-NeMo:main Oct 30, 2026
21 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.

2 participants