Skip to content

feat: enforce global budget cap across all agents#7

Merged
kaissb merged 1 commit into
stagingfrom
feature/0.1.1-global-budget
May 31, 2026
Merged

feat: enforce global budget cap across all agents#7
kaissb merged 1 commit into
stagingfrom
feature/0.1.1-global-budget

Conversation

@kaissb

@kaissb kaissb commented May 31, 2026

Copy link
Copy Markdown
Contributor

What changed

  • internal/budget/manager.go — BudgetManager now tracks a global running total (globalState.spentUSD). CheckBudgetDetailed checks the global limit before per-agent limits; if limit_usd > 0 and spentUSD + estimatedCost > limit → reject with code global_budget_exceeded.
  • Period-based auto-reset: maybeResetGlobalPeriodLocked resets the global counter when the current period expires (hourly / daily / weekly / monthly).
  • GetGlobalBudget() exposes a GlobalBudgetView snapshot consumed by the API.
  • internal/api/server.go — GET /budgets now uses GetGlobalBudget() and returns the enriched global object (period_starts_at, period_resets_at, percentage_used). Removed redundant globalPeriod/globalLimitUSD fields from Server.
  • dashboard/svelte — Overview page fetches /budgets and renders a Global Budget KPI card (spend bar + % used) when limit_usd > 0.
  • scripts/install.sh — fixed to handle .tar.gz release archives.
  • Dockerfile — added WORKDIR /data.

Tests

  • 6 new unit tests in internal/budget/manager_test.go: not-configured → no enforcement, under limit → allow, exceeded → rejects all agents, global checked before per-agent, period reset, GetGlobalBudget view.
  • All packages pass: go test -race ./... (83.4% total coverage).
  • golangci-lint: 0 issues. go vet: clean. Dashboard build + svelte-check + tsc: clean.
  • Integration test: scripts/dev/test-global-budget.sh

- Track total spending across all agents
- Reject all requests when global limit exceeded
- Support period-based resets (hourly/daily/weekly/monthly)
- Expose global budget in GET /budgets API
- Add Global Budget KPI card to dashboard
- Fix install.sh to handle .tar.gz release archives
- Fix Dockerfile WORKDIR to /data
@kaissb
kaissb merged commit a9153ce into staging May 31, 2026
5 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.

1 participant