huskies: merge 646_bug_watchdog_from_bug_624_is_not_actually_enforcing_max_turns_max_budget_usd_in_production

This commit is contained in:
dave
2026-04-26 13:07:02 +00:00
parent 8673e563a9
commit 148c88bd40
5 changed files with 212 additions and 12 deletions
+9 -2
View File
@@ -307,13 +307,20 @@ pub(super) fn tool_get_agent_remaining_turns_and_budget(
}
}
// Compute budget used from completed-session token usage records.
// Compute budget from log-based per-message estimates (works for running
// agents) and completed-session records from token_usage.jsonl.
let log_cost = crate::agents::pool::auto_assign::watchdog::compute_budget_from_logs(
&project_root,
story_id,
agent_name,
);
let all_records = crate::agents::token_usage::read_all(&project_root).unwrap_or_default();
let budget_used_usd: f64 = all_records
let record_cost: f64 = all_records
.iter()
.filter(|r| r.story_id == story_id && r.agent_name == agent_name)
.map(|r| r.usage.total_cost_usd)
.sum();
let budget_used_usd: f64 = log_cost.max(record_cost);
let remaining_turns = max_turns.map(|max| (max as i64) - (turns_used as i64));
let remaining_budget_usd = max_budget_usd.map(|max| max - budget_used_usd);