UAT: SessionCostBudget.utilization() returns None when max_cost_usd=0.0 — zero-budget sessions appear uncapped in warning threshold checks #5610

Open
opened 2026-04-09 07:47:34 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature Area: cost-session-budgets-safety-profiles
Severity: Low — edge case where zero-budget sessions bypass warning threshold


What Was Tested

Code-level analysis of SessionCostBudget.utilization() and OrgCostAccumulator.utilization() in cost_budget.py.

Expected Behavior

When max_cost_usd=0.0 (a zero-dollar budget), any cost recorded should immediately trigger the warning threshold (utilization = infinity or 100%+). A zero-budget session/org should be treated as "always at limit."

Actual Behavior (from code analysis)

src/cleveragents/domain/models/core/cost_budget.py:

def utilization(self) -> float | None:
    """Fraction of the budget consumed (0.0-1.0+)."""
    if self.max_cost_usd is None:
        return None  # Correct: unlimited budget
    if self.max_cost_usd == 0.0:
        return None  # ← Bug: zero budget treated same as unlimited
    return self.total_cost / self.max_cost_usd

When max_cost_usd == 0.0, utilization() returns None — the same as an unlimited budget. This causes:

  1. CostBudgetService._check_warning() skips the warning check (because util is None)
  2. A zero-budget session never triggers a BUDGET_WARNING event
  3. The Session.as_cli_dict() shows "utilization": "N/A" for a zero-budget session, which is misleading

Note: is_exceeded() correctly handles this case (total_cost > 0.0 > 0.0True), so budget blocking still works. The issue is only with the warning threshold.

Code Locations

  • src/cleveragents/domain/models/core/cost_budget.pySessionCostBudget.utilization() and OrgCostAccumulator.utilization() (both have the same issue)
  • src/cleveragents/application/services/cost_budget_service.py_check_warning() relies on utilization() returning non-None to emit warnings

Steps to Reproduce

from cleveragents.domain.models.core.cost_budget import SessionCostBudget

budget = SessionCostBudget(max_cost_usd=0.0)
budget.record_cost(0.01)  # Any cost

print(budget.is_exceeded())   # True (correct)
print(budget.utilization())   # None (misleading — should be infinity or 1.0+)

Fix Suggestion

Return a meaningful value for zero-budget:

if self.max_cost_usd == 0.0:
    # Zero budget: any cost means 100%+ utilization
    return float('inf') if self.total_cost > 0.0 else 1.0

Or alternatively, treat zero budget as "always exceeded" and return 1.0 to trigger warnings.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature Area**: cost-session-budgets-safety-profiles **Severity**: Low — edge case where zero-budget sessions bypass warning threshold --- ## What Was Tested Code-level analysis of `SessionCostBudget.utilization()` and `OrgCostAccumulator.utilization()` in `cost_budget.py`. ## Expected Behavior When `max_cost_usd=0.0` (a zero-dollar budget), any cost recorded should immediately trigger the warning threshold (utilization = infinity or 100%+). A zero-budget session/org should be treated as "always at limit." ## Actual Behavior (from code analysis) `src/cleveragents/domain/models/core/cost_budget.py`: ```python def utilization(self) -> float | None: """Fraction of the budget consumed (0.0-1.0+).""" if self.max_cost_usd is None: return None # Correct: unlimited budget if self.max_cost_usd == 0.0: return None # ← Bug: zero budget treated same as unlimited return self.total_cost / self.max_cost_usd ``` When `max_cost_usd == 0.0`, `utilization()` returns `None` — the same as an unlimited budget. This causes: 1. `CostBudgetService._check_warning()` skips the warning check (because `util is None`) 2. A zero-budget session never triggers a `BUDGET_WARNING` event 3. The `Session.as_cli_dict()` shows `"utilization": "N/A"` for a zero-budget session, which is misleading Note: `is_exceeded()` correctly handles this case (`total_cost > 0.0 > 0.0` → `True`), so budget blocking still works. The issue is only with the warning threshold. ## Code Locations - `src/cleveragents/domain/models/core/cost_budget.py` — `SessionCostBudget.utilization()` and `OrgCostAccumulator.utilization()` (both have the same issue) - `src/cleveragents/application/services/cost_budget_service.py` — `_check_warning()` relies on `utilization()` returning non-None to emit warnings ## Steps to Reproduce ```python from cleveragents.domain.models.core.cost_budget import SessionCostBudget budget = SessionCostBudget(max_cost_usd=0.0) budget.record_cost(0.01) # Any cost print(budget.is_exceeded()) # True (correct) print(budget.utilization()) # None (misleading — should be infinity or 1.0+) ``` ## Fix Suggestion Return a meaningful value for zero-budget: ```python if self.max_cost_usd == 0.0: # Zero budget: any cost means 100%+ utilization return float('inf') if self.total_cost > 0.0 else 1.0 ``` Or alternatively, treat zero budget as "always exceeded" and return `1.0` to trigger warnings. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.6.0 milestone 2026-04-09 07:56:02 +00:00
Author
Owner

Label compliance fix applied:

  • Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: backlog-groomer

Label compliance fix applied: - Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: backlog-groomer
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#5610
No description provided.