feat(guardrails): implement Per-Session and Per-Org Cost Budgets #675
No reviewers
Labels
No labels
auto/needs-reevaluation
controller-managed
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cleveragents/cleveragents-core!675
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/m6plus-per-session-per-org-cost-budgets"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implements Forgejo issue #584: Per-Session and Per-Org Cost Budgets.
Adds a three-tier budget hierarchy (per-plan → per-session → per-org) with the tightest limit winning.
Changes
Domain Models (
cost_budget.py)BudgetLevelenum: PLAN, SESSION, ORGBudgetCheckResult: frozen Pydantic model withexceeded_levelandwarningfieldsSessionCostBudget: tracks per-session accumulated cost withutilization(),remaining(),is_exceeded(),would_exceed()methodsOrgCostAccumulator: tracks per-org accumulated cost, requiresorg_id(min_length=1)ThreadSafeOrgCostAccumulator: thread-safe wrapper withsnapshot()methodApplication Services (
cost_budget_service.py)CostBudgetService: manages budget state for sessions and orgs, enforces the three-tier hierarchy, emitsBUDGET_WARNING(once per session) andBUDGET_EXCEEDEDevents via the event busAutonomyGuardrailService Integration
associate_plan_with_session(): links a plan to a session for budget trackingcheck_budget_hierarchy(): checks plan → session → org hierarchyrecord_plan_cost_to_session(): records cost against session (and org if linked)Configuration (
settings.py)session_max_cost_usd: default session budget caporg_max_cost_usd: default org budget capbudget_warning_threshold: utilisation ratio for warning events (default 0.8)Integration
cost_budgetfield,as_cli_dict()includes budget dataCostBudgetServiceregistered as Singletonsession show: cost budget panel displayTests
features/cost_budgets.feature)robot/cost_budgets.robot)benchmarks/bench_budget_check.py)Verification
nox -s lint✓nox -s typecheck✓nox -s unit_tests✓ (9809 scenarios pass)nox -s coverage_report✓ (98% >= 97% threshold)nox -s integration_tests- all new cost budget tests pass; pre-existing failures unchangedCloses #584
882dde79304e435cbc804e435cbc805f938f50ea5f938f50ea876217d0ca