Skip to content

fix(litellm): retain normalized cache creation usage in telemetry - #4888

Merged
gabsprogrammer merged 4 commits into
Osmantic:public-betafrom
tang-vu:fix/beta-litellm-cache-write-usage-20260913
Sep 15, 2026
Merged

gabsprogrammer merged 4 commits into
Osmantic:public-betafrom
tang-vu:fix/beta-litellm-cache-write-usage-20260913

Conversation

@tang-vu

@tang-vu tang-vu commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Why this matters

When the switchboard is in observe/disabled mode, the LiteLLM success callback owns Token Spy telemetry. LiteLLM 1.90.7 reports Anthropic cache creation under usage.prompt_tokens_details.cache_creation_tokens; ODS currently reads only usage.cache_write_tokens, so a real 4,096-token cache creation is sent to /api/ingest/routed as zero. The cache-write history loses that activity.

Read the normalized detail field through the existing bounded counter conversion. Keep the previous top-level key for callers without the detail, and preserve an explicit measured zero. Input/output totals, cache reads, metadata-only payloads, queue behavior and the switchboard's exactly-once suppression remain unchanged. This corrects telemetry attribution; it does not change pricing or reinterpret total input tokens.

Overlap check

Searched all open/closed PR titles, bodies and changes to ods_token_spy_callback.py, plus LiteLLM cache creation/write telemetry. #2035 introduced routed telemetry; #2086 corrects endpoint labels; #2354 and related variants cover worker cleanup; #3755 concerns non-finite durations. #2519 changes cached-input billing in Token Spy's OpenAI provider, not this callback mapping. No existing PR preserves the normalized cache-creation field here.

Contract and validation

Provider completion → LiteLLM's normalized Usage/ModelResponse → async_log_success_event → bounded queue → authenticated metadata-only POST → existing Token Spy ingest counter/storage contract. The pinned source Usage mapping and Anthropic transformation were checked.

  • New callback tests exercise the actual success hook, worker and outgoing HTTP request: creation count, explicit zero versus legacy value, legacy compatibility, invalid/bounded counters, unchanged input/output/read counts and absence of prompt/answer text. Three cases failed before the change.
  • pytest -q ods/extensions/services/litellm/tests — 11 passed, 1 opt-in skipped in the ordinary Python 3.11 environment.
  • ODS_TEST_LITELLM_PIN=1 LITELLM_LOCAL_MODEL_COST_MAP=True pytest -q ods/extensions/services/litellm/tests with litellm==1.90.7 — 12 passed, including a real ModelResponse(usage=Usage(cache_creation_input_tokens=4096, ...)) reaching the HTTP ingest payload.
  • pytest -q ods/extensions/services/token-spy/tests/test_routed_telemetry.py — 9 passed.
  • Scoped pre-commit and git diff --check passed.

This tests the exact LiteLLM Python release and the outgoing HTTP boundary using MockTransport; it does not call a paid provider, launch the full proxy image, or claim an end-to-end cloud billing test. Shared Python code applies across hosts; executed evidence is Linux/WSL. No stored events are rewritten. Revert restores the prior mapping without migration. Base is public-beta c03e0809, which now includes eight earlier batch fixes merged upstream. Remaining shared baseline gate limitations are documented for the batch.

Follow-up validation

Merged the current beta base in commit 31d60c2. The scoped diff still contains only the LiteLLM callback and its regression test. All 12 pinned-LiteLLM tests passed on this exact candidate. GitHub checks on this head: 32 success, 4 skipped. The earlier unrelated RemoteProvider frontend failure is no longer present; no duplicate UI fix was added (canonical follow-up: #4570).

Batch integration evidence

This exact candidate is included in the 30-PR integration receipt, on code integration commit a38a38a2303724b2b2a3bfba6324fc40a67154ba over public-beta d49ad4bbc760be319de7f4c9b9a93b1f18fe3922. The receipt lists all candidate SHAs, suggested merge order and additive catalog/README reconciliation.

The integration passed 2,858 API tests (3 skipped), 1,069 UI tests, build/lint, schema and four backend Compose plans. The combined live suite passed 52 cases and hit one Uptime Kuma Docker-start timeout; the unchanged Kuma cases passed in a separate rerun on the same commit. The negative cold-start observation remains recorded. Root/WSL fixture failures and the existing macOS fixture PR #3160 are explicitly separated from passing smoke/simulation checks. These receipts do not qualify every hardware platform or a simultaneous service load.

The report distinguishes completed CI from the queued Memos follow-up. Gitea #4909 remains draft for independent migration review.

@gabsprogrammer
gabsprogrammer merged commit 340f629 into Osmantic:public-beta Sep 15, 2026
40 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