huskies: merge 646_bug_watchdog_from_bug_624_is_not_actually_enforcing_max_turns_max_budget_usd_in_production
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user