You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SECURITY] Per-org LLM token and cost budgets to stop runaway spend #226
Nothing limits how many LLM tokens, or how much money, the agent spends per org. Every incident runs a reasoning loop of up to MAX_AGENT_STEPS, and every tool result goes back to the model. Possible causes of runaway spend:
prompt-injection attempts that try to keep the agent busy.
When an org has no LLM key of its own, the platform pays. services/metrics.py already counts tokens, but nothing acts on the count.
Proposed fix
Per-org budgets in org config or env: LLM_MAX_TOKENS_PER_INCIDENT, LLM_MAX_TOKENS_PER_DAY, LLM_MAX_TOKENS_PER_MONTH, plus optional LLM_COST_PER_1K_INPUT/_OUTPUT to report estimated spend.
Track usage in storage per org and day ({org}/usage/<yyyy>/<mm>/<dd>.json) from the provider's usage fields (agent/llm.py).
Per-incident cap: stop the loop, set partial_result, and escalate with reason token_budget.
Daily or monthly cap: new incidents go to suggest_fix-only or straight to escalation, with one Slack warning at 80% and at 100%.
GET /orgs/{org}/usage (viewer) and a Prometheus metric devops_agent_llm_tokens_total{org}.
Tests: the loop stops at the cap; counters persist; the 80% warning is sent once.
Activity