Skip to content

feat(llc): parse CLI token usage and report to LLC budget (#10220) - #10242

Merged
mrveiss merged 4 commits into
Dev_new_guifrom
issue-10220-token-budget
Jun 17, 2026
Merged

mrveiss merged 4 commits into
Dev_new_guifrom
issue-10220-token-budget

Conversation

@mrveiss

@mrveiss mrveiss commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Thinking Path

From the #9008/#9033 adapter audit (decomposed into #10217–10220). The subprocess CLI adapters — claude_code and the subscription variants that inherit it — never parsed token usage from their output, so those agents accrued zero tracked budget, unlike autobot_agent_adapter which calls BudgetService.ingest_cost_event. This closes that gap (#9008 AC5, #9033 AC4).

What Changed

  • AdapterRunStatus gains tokens_in / tokens_out.
  • subprocess_support.extract_usage() — pure helper parsing the stream-json result event's usage block: tokens_in = input + cache_read + cache_creation, tokens_out = output_tokens; returns (None, None) when no usage (so we never record bogus zeros).
  • ClaudeCodeAdapter._status attaches parsed usage on a clean-success run (subscription adapters inherit it).
  • _await_adapter_completion now returns the full AdapterRunStatus; on COMPLETED, _dispatch_registry_adapter forwards usage to BudgetService.ingest_cost_event(session, agent_id, tokens_in, tokens_out, model) — best-effort, except BudgetExhausted which is re-raised (GH#8215 hard-stop → run marked FAILED). Token-vs-dollar mode is handled by the budget service per the agent's config (feat(llc/budget): token-based budget mode — track agent budgets in token counts alongside dollar amounts #8997), so subscription agents bill in tokens automatically.

Verification

  • pytest llc/tests/test_heartbeat_scheduler.py llc/adapters/tests/test_subprocess_support.py llc/adapters/tests/test_claude_code_adapter.py llc/adapters/tests/test_subscription_adapters.py llc/tests/test_registry_adapter_rate_limit.py → 120 passed; rate-limit + liveness suites → 18 passed
  • New tests: extract_usage (cache-sum / basic / none / all-zero / non-int) and _ingest_adapter_usage (bills with model, no-ops on unknown usage, BudgetExhausted propagates, other errors best-effort); existing dispatch tests updated for the new return type
  • flake8 clean; import smoke OK

Model Used

Claude Opus 4.8

Closes #10220 (part of #9923)

mrveiss added 3 commits June 16, 2026 23:32
CLI/subprocess adapters (claude_code + the subscription variants that inherit
it) never parsed token usage from their output, so those agents accrued ZERO
tracked budget — unlike autobot_agent_adapter which calls ingest_cost_event.

- AdapterRunStatus gains tokens_in/tokens_out
- subprocess_support.extract_usage() parses the stream-json result event's
  usage block (input + cache-read + cache-creation = tokens_in; output_tokens)
- ClaudeCodeAdapter._status attaches usage on a clean-success run
- _await_adapter_completion returns the full AdapterRunStatus; on COMPLETED,
  _dispatch_registry_adapter forwards usage to BudgetService.ingest_cost_event
  (best-effort; BudgetExhausted re-raised → GH#8215 hard-stop marks run FAILED)

Tests: extract_usage (cache-sum/basic/none/zero/non-int) + _ingest_adapter_usage
(bills with model, no-ops when usage unknown, BudgetExhausted propagates, other
errors best-effort) + updated dispatch tests for the new return type. 120 pass.

Closes #10220 (part of #9923).
@github-actions

github-actions Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No hardcoded values detected that have SSOT config equivalents!

@mrveiss
mrveiss merged commit 5773733 into Dev_new_gui Jun 17, 2026
30 checks passed
@mrveiss
mrveiss deleted the issue-10220-token-budget branch June 17, 2026 08:41
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