fix(quota): provider-aware budget gating and per-provider usage tracking#1837
Conversation
PR Review — fix(quota): provider-aware budget gating and per-provider usage trackingClean, well-tested provider-aware quota implementation.
🟡 Important1. Hardcoded mode display may be inaccurate (`koan/app/tui_dashboard.py`, L883)When provider has no API quota, the TUI displays The Suggested fix: try:
mode = t.decide_mode()
lines.append(f"Mode [{_MINT}]{mode}[/] [dim](budget disabled for {_provider_name()})[/]")
except Exception as exc:
lines.append(f"Mode [{_MINT}]deep[/] [dim](budget disabled for {_provider_name()})[/]")Checklist
Silent Failure Analysis🟡 **MEDIUM** — silent fallback on error (`koan/app/tui_dashboard.py:94-101`)Risk: When provider quota check fails, returns True (has quota) which could incorrectly apply budget gating to local providers that should be exempt. Fix: Consider logging at WARNING level since this affects budget gating behavior, or document why fail-closed (True) is the safe default. 🟡 **MEDIUM** — silent fallback on error (`koan/app/usage_tracker.py:285-291`)Risk: If provider quota check throws, budget_mode falls back to config value instead of forcing 'disabled' - local providers could get incorrectly gated on stale usage. Fix: Log at WARNING level since incorrect budget gating blocks agent iterations, or consider fail-safe behavior that assumes no quota when check fails. Automated review by Kōan (Ollama-launch · model qwen3.5:cloud) |
When using ollama-launch or local providers, Kōan was displaying stale 100%/100% quota numbers from previous Claude API usage because the usage_state.json was shared across all providers without reset. This fix: 1. Adds CLIProvider.has_api_quota() — returns False for ollama-launch and LocalLLMProvider (no metered API quota). 2. Makes _get_budget_mode() provider-aware: when the active provider has no API quota, budget_mode is forced to 'disabled' so stale usage.md never gates the agent into wait/review mode. 3. Adds per-provider tracking to usage_estimator.py: stores the cli_provider name in usage_state.json and resets session/weekly counters when the provider changes. This prevents stale Claude numbers from polluting ollama-launch display. 4. Updates TUI dashboard to show 'no API quota' messages for no-quota providers instead of misleading usage bars. Closes Anantys-oss#319 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rebase with requested adjustmentsBranch Changes applied
StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
1b1fcbf to
d586fb6
Compare
Problem
When using ollama-launch provider, Kōan displayed incorrect 100%/100% quota numbers from previous regular Claude API usage. The usage_state.json accumulated tokens across provider switches without resetting, causing stale data to persist.
Root Cause
Fix
Add CLIProvider.has_api_quota() — returns False for ollama-launch and LocalLLMProvider (no metered API quota). Base class defaults to True.
Make _get_budget_mode() provider-aware — when the active provider has no API quota, budget_mode is forced to 'disabled' so stale usage.md never gates the agent into wait/review mode.
Add per-provider tracking to usage_estimator.py — stores name in and resets session/weekly counters when the provider changes. This prevents stale Claude numbers from polluting ollama-launch display.
Update TUI dashboard — shows 'no API quota' messages for no-quota providers instead of misleading usage bars.
Verification
Related
Quality Report
Changes: 11 files changed, 228 insertions(+), 21 deletions(-)
Code scan: clean
Tests: passed (403
tests)
Branch hygiene: clean
Generated by Kōan