Skip to content

fix: isolate Droid token usage between invocations - #451

Closed
mnajafian-nv wants to merge 48 commits into
NVIDIA:mainfrom
mnajafian-nv:fix/droid-token-usage
Closed

mnajafian-nv wants to merge 48 commits into
NVIDIA:mainfrom
mnajafian-nv:fix/droid-token-usage

Conversation

@mnajafian-nv

@mnajafian-nv mnajafian-nv commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Droid's SDK can fall back to a session-lifetime usage total when a turn reports no usage. Reusing that total can assign earlier work to the current invocation.

Read usage only from the newly completed turn's matching notification. Keep useful positive counts as observations in RunResult.model_usage when Droid's aggregation and zero filling prevent a complete accounting claim.

Dependencies: #442 supplies the shared accounting contract and normalizer. The diff against main includes unmerged prerequisites.

Details

Track completion IDs and accept usage only when the invocation observes one matching new completion. Do not substitute a session-lifetime total when that completion lacks usage.

Track model changes and child-usage signals during the turn. Mixed models, router identities and delegated usage do not become token counts attributed to the configured parent model. Apply cache conventions only when the model and source settings establish them.

Shared accounting in #442 normalizes the observations. Missing fields and zeros inserted by Droid do not become measured zeros. Factory credits and native thinking-token diagnostics remain separate from provider-reported USD cost and normalized reasoning evidence.

Validation

The Droid adapter build and 14 focused usage tests passed. With the adapter contract and common packages built, reproduce them from the repository root:

npm run build --prefix adapters/typescript/droid
node --test adapters/typescript/droid/test/*.test.mjs

Regression tests cover matching completion IDs, missing turn usage, duplicate notifications, mixed models and descendant-inclusive totals. Source tests check the pinned SDK's zero filling and session-total fallback; those tests skip when the required source package is unavailable.

Where should the reviewer start?

Start with observeTurn, matching completion selection and normalizeUsage in adapters/typescript/droid/src/droid-sdk.ts. Review test/droid-sdk.test.mjs for session-total fallback and test/usage-source.test.mjs for source conventions.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • Relates to: none

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.

  • I searched existing issues and open pull requests, and this does not duplicate existing work.

The Deep Agents adapter summed usage_metadata from the AI messages that
reached graph state through the updates stream. Three cases came out
wrong:

- Deep Agents adds SummarizationMiddleware to every agent and subagent.
  Its summary call returns only text, so the summary model's message
  and usage never enter graph state, and an invocation that summarized
  under-reported input, output and total tokens.
- When the invocation raised, including GraphRecursionError, the
  adapter returned no messages, so usage was None even though model
  calls had finished.
- A count was summed over the calls that reported it and returned as
  known. ChatOpenAI also turns an omitted Chat Completions count into 0
  and derives a missing total, so a partial provider report came out as
  measured zeros.

The adapter now records usage from LangChain's chat-model callbacks,
which fire for every chat-model call that runs in the adapter process:
the main agent, declarative subagents and summarization. Agent Protocol
subagents run remotely and are not included. A new recorder is created
for each invocation, so earlier turns are never counted again. It
outlives an exception, so a failed invocation still reports the fields
that every counted call reported.

Each token count and the cost are known only when every counted call
in the invocation reported them, and an explicit zero stays a known
zero. A request the provider rejects with a 4xx status (other than 408)
contributes no usage. A 5xx response, timeout, cancellation or
unfinished call leaves the invocation's counts and cost unknown,
because the provider may have done work without reporting usage.
OpenAI SDK retries happen inside one LangChain call, so a 5xx the SDK
retries to success is not visible to the recorder, and only the final
response's reported usage counts. When
a response carries OpenAI-shaped raw usage, the raw counts decide what
was reported: an omitted count stays unknown, the provider's total is
used when present, and a derived total counts only when input and
output were both reported.

The graph tests run the real Deep Agents graph and ChatOpenAI against
a scripted Chat Completions endpoint for summarization, parallel task
subagents, 400, 408, 503 and timeout failures, the recursion limit,
partial reports and explicit zeros. Separate ChatOpenAI.with_retry
tests cover 429 then success and 503 then success. The existing usage tests
now produce their messages through a LangChain chat-model call so the
callbacks fire.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
The Droid adapter put cache reads and writes only in adapter-private
usage extension keys, so standard usage consumers saw no cache
counts. Droid also stores a count that the provider omits as 0, and
the adapter copied those zeros, so a provider that sent no output
count produced 0 output tokens.

Cache reads now go in cached_input_tokens, and cache writes go in the
nemo_fabric.detailed_token_usage.v1 extension as
cache_write_input_tokens. The descriptor and the adapter catalog
declare that extension, and the private cache keys are removed
because nothing reads them.

Droid's input count does not follow one cache convention. Its Gemini
handler keeps Google's prompt count, which includes cache reads. Its
Responses and Chat Completions handlers subtract cache reads. Its
Anthropic Messages and Bedrock Converse handlers keep provider input
that excludes cache reads and writes. Droid picks the handler from
the model's provider. The adapter reads the session's current model
from the SDK, picks the convention from the model ID or a custom
model's provider in Droid's settings, and reports inclusive input
with input_tokens_include_cache set to true and a total.

Some turns cannot be normalized with one convention. Droid adds Task
subagent usage to the turn's counters without saying which model each
subagent used, and a model can change during a turn. The adapter
watches the session's notifications for the whole invocation: a turn
whose completion carries child usage, or that touches models with
different conventions, keeps Droid's counters and leaves the flag
and, when the turn has cache counts, the total unset. So do the auto
routers, models without a known convention, and Responses turns with
cache writes.

A 0 count is unknown, and so is a total built from it. The exception
is a 0 cache read count for Anthropic, OpenAI Responses, Bedrock
Converse and Gemini models, whose usage reports carry the count or,
for Gemini, omit it only when it is 0. Zero Factory credits are
omitted, because Droid also uses 0 for missing credits. The
thinking-token count and Factory credits stay as adapter extensions,
because Droid estimates thinking tokens from the thinking text for
Anthropic, Google and Bedrock models, and credits have no standard
field.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a9fd48c and 4e09d50.

Files ignored due to path filters: 2
  • adapter-contract/typescript/src/generated/usage-accounting.ts is excluded by !**/generated/**
  • adapter-contract/typescript/test/generated/usage-accounting-vectors.ts is excluded by !**/generated/**
Files selected for processing: 15
  • adapter-contract/python/src/nemo_fabric_adapter_contract/usage.py
  • adapter-contract/typescript/src/usage.ts
  • adapter-contract/typescript/test/usage-reducer.test.js
  • crates/fabric-core/src/model_usage.rs
  • crates/fabric-core/src/runtime.rs
  • crates/fabric-core/src/usage_accounting.rs
  • docs/index.yml
  • docs/sdk/python.mdx
  • sdk/python/nemo-fabric-adapter-catalog/src/nemo_fabric_adapter_catalog/catalog.json
  • sdk/python/nemo-fabric-runtime/src/nemo_fabric/types.py
  • skills/nemo-fabric-build-adapter/SKILL.md
  • tests/adapters/test_deepagents_accounting.py
  • tests/fixtures/usage_accounting/reducer-cases.json
  • tests/python/test_model_usage.py
  • tests/python/test_usage_reducer_parity.py

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

Recent review details
Additional context used
Code guidelines: 6
.agents/skills/review-doc-style/SKILL.md — configured
AGENTS.md — configured
.agents/skills/prepare-pr/SKILL.md — configured
schemas/SCHEMA.md — auto-discovered
.agents/skills/contribute-docs/SKILL.md — configured
skills/README.md — auto-discovered
Path-based instructions: 20
Review Python SDK changes for typed API consistency, import-time dependency neutrality, async/session behavior, and parity with the native extension.

CodeRabbit configuration file

Files:

  • sdk/python/nemo-fabric-runtime/src/nemo_fabric/types.py
Review the Rust core for runtime lifecycle correctness, handle validation, capability routing accuracy, schema stability, and error semantics.

CodeRabbit configuration file

Files:

  • crates/fabric-core/src/runtime.rs
  • crates/fabric-core/src/usage_accounting.rs
  • crates/fabric-core/src/model_usage.rs
Review documentation for technical accuracy against the current API, command correctness, and consistency with generated schemas.

CodeRabbit configuration file

Files:

  • docs/index.yml
  • docs/sdk/python.mdx
Enforce the product name in user-facing prose: use "NVIDIA NeMo Fabric" on first use and "NeMo Fabric" thereafter.

CodeRabbit configuration file

Files:

  • docs/sdk/python.mdx
  • skills/nemo-fabric-build-adapter/SKILL.md
Do not flag SKILL.md files for missing SPDX headers.

CodeRabbit configuration file

Files:

  • skills/nemo-fabric-build-adapter/SKILL.md
Tests should cover the behavior promised by the changed API surface, including error paths, lifecycle cleanup, and SDK/native parity where relevant.

CodeRabbit configuration file

Files:

  • tests/python/test_usage_reducer_parity.py
  • tests/python/test_model_usage.py
  • tests/adapters/test_deepagents_accounting.py
  • tests/fixtures/usage_accounting/reducer-cases.json
Source excerpt: Treat these as blocking issues: MDX top-of-file SPDX comments use HTML comment delimiters instead of `{/* ...

CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

Files:

  • docs/sdk/python.mdx
Source excerpt: For links between files under `docs/`, use paths relative to the source file and include the target file's `.mdx` extension.

CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

Files:

  • docs/index.yml
  • docs/sdk/python.mdx
Source excerpt: Keep public bindings current when the API changes: `docs/sdk/python.mdx` for the Python SDK; `adapter-contract/python/` and `adapter-contract/typescript/` for the southbound adapter contract; the JSON Schema notes in `schema...

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/sdk/python.mdx
  • skills/nemo-fabric-build-adapter/SKILL.md
Source excerpt: Key conventions for the two tiers: **Discovery wiring:** `.claude/skills` symlinks to `.agents/skills/` (the maintainer set) for Claude Code; integration skills under `skills/` are copied into another project rather than aut...

CodeRabbit inference engine (AGENTS.md)

Files:

  • skills/nemo-fabric-build-adapter/SKILL.md
Source excerpt: [ ] Any Rust change ran `just test-rust` Source excerpt: [ ] Any Rust change ran `cargo fmt --all -- --check` Source excerpt: [ ] `crates/fabric-core` changes ran both the Rust and Python suites

CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)

Files:

  • crates/fabric-core/src/runtime.rs
Source excerpt: Keep the tiers separate: do not add external integration guidance to the maintainer set, or repository-internal contribution steps to the integration set.

CodeRabbit inference engine (AGENTS.md)

Files:

  • skills/nemo-fabric-build-adapter/SKILL.md
Applicability reference: AGENTS.md: # AGENTS.md Keep public bindings current when the API changes: `docs/sdk/python.mdx` for the Python SDK; `adapter-contract/python/` and `adapter-contract/typescript/` for the southbound...

CodeRabbit inference engine (schemas/SCHEMA.md)

Files:

  • crates/fabric-core/src/runtime.rs
  • crates/fabric-core/src/usage_accounting.rs
  • crates/fabric-core/src/model_usage.rs
Source excerpt: [ ] New or regenerated MDX files use `{/* ...

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

Files:

  • docs/sdk/python.mdx
Source excerpt: Keep the stable public wrapper `scripts/generate_api_docs.sh` at the `scripts/` root in docs and examples.

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/index.yml
  • docs/sdk/python.mdx
Source excerpt: Update user-facing entry points when public behavior, the `nemo-fabric` package (imported as `nemo_fabric`), examples, or supported bindings change: `README.md`, the Fern docs under `docs/` (navigation in `docs/index.yml`, s...

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/index.yml
Source excerpt: [ ] `README.md` or `docs/index.yml` updated when entry points changed

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

Files:

  • docs/index.yml
Applicability reference: AGENTS.md: # AGENTS.md NeMo Fabric ships two tiers of agent skills.

CodeRabbit inference engine (skills/README.md)

Files:

  • skills/nemo-fabric-build-adapter/SKILL.md
Source excerpt: Key conventions for the two tiers: **Portability strategy:** integration skills link to public GitHub documentation and example URLs rather than a docs-site domain, so they keep working when exported.

CodeRabbit inference engine (AGENTS.md)

Files:

  • skills/nemo-fabric-build-adapter/SKILL.md
Source excerpt: In MDX files, top-of-file comments must use JSX comment delimiters: `{/*` to open and `*/}` to close.

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

Files:

  • docs/sdk/python.mdx
Learnings: 2
Learning: 2026-10-24T20:28:22.270Z
Learnt from: CR
Repo: NVIDIA/NeMo-Fabric PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-10-24T20:28:22.270Z
Learning: Applies to docs/sdk/python.mdx : Source excerpt:
# AGENTS.md

## Documentation And Contribution Workflow

- Keep public bindings current when the API changes: `docs/sdk/python.mdx` for
  the Python SDK; `adapter-contract/python/` and
  `adapter-contract/typescript/` for the southbound adapter contract; the JSON
  Schema notes in `schemas/SCHEMA.md`;
  the generated references under `docs/reference/api/`; and the integration
  skills under `skills/` (which restate public contracts and must be kept in
  parity). Regenerate docs with `just docs` after changing the docs site.

Applied to files:

  • docs/sdk/python.mdx
Learning: 2026-10-20T16:11:43.359Z
Learnt from: CR
Repo: NVIDIA/NeMo-Fabric PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2026-10-20T16:11:43.359Z
Learning: Source excerpt:
# Contributing to NVIDIA NeMo Fabric

## SPDX License Headers

All source files must include an SPDX license header. Use the appropriate
comment syntax for the file type.

Applied to files:

  • adapter-contract/python/src/nemo_fabric_adapter_contract/usage.py
  • crates/fabric-core/src/usage_accounting.rs
ast-grep (0.45.3)
tests/python/test_usage_reducer_parity.py

[error] 81-87: Command coming from incoming request
Context: subprocess.run(
[node, "--input-type=module", "-e", source, str(module)],
input=json.dumps(VECTORS),
capture_output=True,
text=True,
check=True,
)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(subprocess-from-request)

[info] 83-83: use jsonify instead of json.dumps for JSON output
Context: json.dumps(VECTORS)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

tests/python/test_model_usage.py

[info] 496-496: use jsonify instead of json.dumps for JSON output
Context: json.dumps(rates)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

tests/adapters/test_deepagents_accounting.py

[info] 539-544: use jsonify instead of json.dumps for JSON output
Context: json.dumps(
{
"description": f"Echo {index}.",
"subagent_type": "general-purpose",
}
)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

[info] 620-620: use jsonify instead of json.dumps for JSON output
Context: json.dumps(chunk)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

[warning] 837-837: Do not make http calls without encryption
Context: "http://api.openai.com/v1"
Note: [CWE-319] Cleartext Transmission of Sensitive Information.

(requests-http)

SkillSpector (2.12.0)
skills/nemo-fabric-build-adapter/SKILL.md

[warning] 1: [TR2] Shadow Command Trigger: Shadow Command Trigger: description clause 'ng adapter or target descriptors, mapping AgentConfig into an agent harness or custom-agent runtime, implementing start/invoke/stop, declaring schemas and capabilities, packaging discovery metadata, or assessing adapter conformance' conflicts with built-in command 'stop'

Remediation: Choose triggers that do not conflict with built-in commands or other skills. Prefix with a unique namespace if necessary.

(Trigger Abuse (TR2))

Additional comments: 16
crates/fabric-core/src/runtime.rs: 2

148-153: LGTM!

Also applies to: 2321-2339, 2352-2352

4121-4121: LGTM!

Also applies to: 4373-4404, 4640-4640, 6116-6135, 6662-6695

crates/fabric-core/src/usage_accounting.rs: 1

1-373: LGTM!

sdk/python/nemo-fabric-runtime/src/nemo_fabric/types.py: 1

2522-2907: LGTM!

docs/index.yml: 1

105-106: LGTM!

docs/sdk/python.mdx: 1

1183-1183: LGTM!

Also applies to: 1220-1263

tests/fixtures/usage_accounting/reducer-cases.json: 1

1-487: LGTM!

tests/python/test_model_usage.py: 1

1-585: LGTM!

tests/python/test_usage_reducer_parity.py: 1

1-137: LGTM!

tests/adapters/test_deepagents_accounting.py: 1

1-879: LGTM!

skills/nemo-fabric-build-adapter/SKILL.md: 1

233-235: LGTM!

adapter-contract/python/src/nemo_fabric_adapter_contract/usage.py: 1

1-238: LGTM!

adapter-contract/typescript/src/usage.ts: 1

1-193: LGTM!

adapter-contract/typescript/test/usage-reducer.test.js: 1

1-60: LGTM!

sdk/python/nemo-fabric-adapter-catalog/src/nemo_fabric_adapter_catalog/catalog.json: 1

597-936: LGTM!

crates/fabric-core/src/model_usage.rs: 1

244-244: 🩺 Stability & Availability

The expect is unreachable with accounting == None.

normalize_model_usage first requires UsageAccounting::from_usage(usage) to return Some. describe_model_usage then reads the same immutable usage and stores that evidence with evidence.map(...). Legacy usage without the accounting extension returns before view, so the expect does not panic on that path.

Walkthrough

This PR adds invocation-scoped usage accounting across adapter contracts, Droid, Deep Agents, Fabric Core, and the Python SDK. It preserves unknown values, records observations and gaps, normalizes model usage, updates schemas, and adds tests and documentation.

Changes

Usage accounting contracts and reducers

Layer / File(s) Summary
Accounting evidence contract
adapter-contract/python/..., adapter-contract/typescript/..., schemas/extensions/...
Adds typed reported usage, observations, model and request evidence, gap reasons, completeness flags, and validation rules.
Shared reducers and fixtures
adapter-contract/python/.../usage.py, adapter-contract/typescript/src/usage.ts, tests/fixtures/usage_accounting/*
Aggregates observations while preserving unknown versus zero values, conventions, gaps, model attribution, and independently reported costs.
Fabric Core normalization
crates/fabric-core/src/{usage_accounting,usage_normalization,model_usage}.rs, crates/fabric-core/src/runtime.rs
Validates accounting extensions, derives normalized complete and observed values, and exposes optional RunResult.model_usage.
Adapter integrations
adapters/python/deepagents/..., adapters/typescript/droid/...
Deep Agents records callback and HTTP evidence per invocation. Droid records matching turn-completion usage and resolves provider conventions.
SDK summaries and validation
sdk/python/nemo-fabric-runtime/src/nemo_fabric/{types,accounting}.py, tests/python/*
Adds typed model-usage contracts and summarizes results against an explicit invocation inventory.
Schemas, tests, and documentation
schemas/*, tests/*, docs/*, adapters/*/README.md
Synchronizes descriptor schemas and documents accounting semantics, limitations, gaps, observations, and model attribution.

Priority: Normal

Estimated code review effort: 5 (Critical) | ~90 minutes

Possibly related issues

  • NVIDIA/NeMo-Fabric#422 — The PR adds per-invocation and per-request usage evidence, model attribution, cost fields, and explicit unknown measurements.
Merge Risk: Minimal · up to 4e09d

This change scopes token usage to each invocation and reports it consistently across the Python and TypeScript adapter contracts. The two previously open concerns, cost-summation parity and the documentation of when model_usage is present, are fixed in the current code. No remaining merge-blocking issue was found.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title uses the allowed fix type, provides a concise imperative summary, matches the Droid usage-isolation change, contains no trailing period, and is 50 characters long.
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.
Description check Passed The pull request description is complete and follows the repository template. It includes an overview, reviewer starting point, validation details, related-issue information, and both required confirm…
Full details: Description check

Explanation

The pull request description is complete and follows the repository template. It includes an overview, reviewer starting point, validation details, related-issue information, and both required confirmation checkboxes.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

Copy link
Copy Markdown

coderabbitai[bot]

This comment was marked as outdated.

Droid stores an omitted cache read count as 0. For Grok, Factory-hosted
models, and anthropic, openai and generic-chat-completion-api custom
models, the endpoint is not shown to report cache reads on every
response, so that 0 may hide cache hits that belong in the input. The
adapter already withheld cached_input_tokens there, but still added
the 0 to the input, set input_tokens_include_cache and derived a
total, so a glm-5 turn with omitted cache hits reported a known input
and total that were too small.

Inclusive input now needs a known cache read count: a positive count,
or a provider that reports cache reads on every response. Otherwise
the turn keeps Droid's input count, leaves input_tokens_include_cache
unset and derives no total. Claude, GPT, Bedrock Converse and Gemini
turns with 0 cache reads stay fully known.

The other fallback turns (the auto routers, turns with subagent usage
and turns that switch conventions) derived a total from Droid's input
when both cache counters were 0. That 0 can be an omission too, so
those turns now derive no total either.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
LangChain carries cache reads per model call in
usage_metadata.input_token_details.cache_read, and OpenAI raw usage
carries them in prompt_tokens_details.cached_tokens, but the adapter
never reported cached_input_tokens.

Sum cached input per call with the same rule as the other counts: one
call without a cache count leaves the sum unknown, and a reported 0
stays 0. Raw OpenAI usage is read first because ChatOpenAI renames the
cache key for priority and flex service tiers.

Report input_tokens_include_cache=True whenever input tokens are known.
LangChain's UsageMetadata.input_tokens counts every input token type;
langchain-anthropic adds cache reads and writes back into it, and
OpenAI's prompt_tokens already includes cached tokens.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
The adapter drops a model call that the provider rejects with a 4xx
status other than 408, because the provider spent no tokens on it. When
every call was rejected, or no call started, the call list was empty and
the usage was reported as unknown, although the invocation provably
spent no tokens. The adapter now reports 0 for every token count and the
cost in that case.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Deep Agents routes a subagent spec with graph_id to its async subagent
middleware, which starts and updates tasks on a remote Agent Protocol
server. Those model calls never reach the adapter's callbacks, so the
reported counts left them out while appearing complete. The adapter
blocked such subagents only when a tools policy was configured.

When the configured subagents include one with graph_id, the adapter now
reports the invocation's token counts and cost as unknown. The local
sums stay in output.usage.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
The usage notes said that after a 5xx response, timeout, or cancelled
call the provider may have done work. The reason the counts stay unknown
is narrower: the provider may have billed the call without reporting
usage. The README, the recorder docstring, and a test comment now say
that.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Apply ruff format to the check added in the previous commit.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
…gent

The adapter reports 0 when its callbacks observed no billed model call.
That 0 holds for the invocation only when every model call runs through
those callbacks. Deep Agents runs declarative subagents and summarization
inside the graph, where the run config's callbacks reach them, but an
Agent Protocol subagent (graph_id) runs on a remote server that the
callbacks never see. The adapter already reports unknown usage for a
runtime with such a subagent; this test pins that for an invocation
whose only observed call was rejected, and the docstring and README
state the condition.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv
mnajafian-nv marked this pull request as draft October 20, 2026 19:53
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Separate complete invocation totals from available observations and preserve accounting gaps. Add the first collector in Deep Agents.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv mnajafian-nv changed the title fix: report Droid cache tokens in the standard usage fields fix: isolate Droid token usage between invocations Oct 22, 2026
coderabbitai[bot]

This comment was marked as outdated.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv
mnajafian-nv marked this pull request as ready for review October 23, 2026 15:45
@mnajafian-nv
mnajafian-nv marked this pull request as draft October 23, 2026 15:52
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv
mnajafian-nv marked this pull request as ready for review October 23, 2026 16:32
Use the system Bash path so macOS tests exercise Bash 3.2 even when PATH contains a newer Bash. This keeps the empty-array regression meaningful in CI.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Include the current shared accounting validation while preserving the adapter collectors and canonical catalog declarations.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
✅ 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.

Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv
mnajafian-nv marked this pull request as draft October 27, 2026 02:33
Signed-off-by: mnajafian-nv <mnajafian@nvidia.com>
@mnajafian-nv

Copy link
Copy Markdown
Contributor Author

This PR preserves the Droid invocation-isolation approach. I’m closing the current branch so future work can follow the shared accounting design.

This branch was previously deployed

1 inactive deployment
fern — 1be7eb79 Deployed Oct 27, 2026 by copy-pr-bot[bot] via Preview docs #2610
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.

1 participant