Skip to content

fix(batch): count CostTracker requests even without litellm#5

Merged
StressTestor merged 1 commit into
mainfrom
fix/costtracker-litellm-optional
Jun 16, 2026
Merged

fix(batch): count CostTracker requests even without litellm#5
StressTestor merged 1 commit into
mainfrom
fix/costtracker-litellm-optional

Conversation

@StressTestor

Copy link
Copy Markdown
Owner

why

CI is red on main. tests/test_batch.py::TestCostTracker has 3 failing tests (KeyError: 'test-model'), and they fail on a clean checkout too - this is pre-existing, not caused by any recent change.

root cause: CostTracker.record() and record_from_usage() both early-return when LITELLM_AVAILABLE is false. litellm is an optional dependency and isn't installed in the CI test environment, so every call was a no-op, self.costs stayed empty, and summary()["per_model"] came back with no keys. callers that index by model name then KeyError.

fix

always create the per-model entry and increment the request count; gate only the cost computation on litellm (cost stays 0.0 when it's absent). request counting is the part that should never depend on an optional pricing library.

verification

  • the 4 TestCostTracker tests pass
  • full suite green locally: 173 passed (excluding test_api_launcher.py, which needs cachetools not installed in my local env; it passes in CI)
  • no behavior change when litellm IS installed - cost is still computed and added

record() and record_from_usage() early-returned when LITELLM_AVAILABLE was
false, so with litellm uninstalled (the CI environment) nothing was ever
recorded and summary()['per_model'] came back empty - KeyError in callers and
3 failing tests. now the request count and per-model entry are always tracked;
only the cost figure depends on litellm (stays 0.0 without it).
@github-actions

Copy link
Copy Markdown

codex review

Codex review is not configured for this repository yet.

Missing required secret: CODEX_ACCESS_TOKEN.

@StressTestor StressTestor merged commit 18cdd3d into main Jun 16, 2026
5 checks passed
@StressTestor StressTestor deleted the fix/costtracker-litellm-optional branch June 16, 2026 02:52
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