auto-pause the turn loop after repeated missed get_loose_ends on todo wakes

This commit is contained in:
damocles 2026-08-02 17:40:17 +02:00 committed by mara
commit edb4aa98c6
2 changed files with 100 additions and 6 deletions

View file

@ -44,6 +44,10 @@ pub fn format_wake_prompt(
/// Field-named args for [`build_row`]. Mirrors the turn-stats row
/// columns; `outcome` and `bus` borrow for the duration of the call.
/// `tool_calls` is passed in (rather than pulled from `bus` internally)
/// because the caller needs the same map to check for a `get_loose_ends`
/// call before it's consumed — `Bus::take_tool_calls` resets the counter,
/// so there's only one chance to read it per turn.
pub struct TurnRowArgs<'a> {
pub started_at: i64,
pub ended_at: i64,
@ -52,6 +56,7 @@ pub struct TurnRowArgs<'a> {
pub wake_from: String,
pub outcome: &'a TurnOutcome,
pub bus: &'a Bus,
pub tool_calls: std::collections::HashMap<String, u64>,
pub open_threads_count: Option<u64>,
pub open_reminders_count: Option<u64>,
}
@ -69,6 +74,7 @@ pub fn build_row(args: TurnRowArgs<'_>) -> TurnStatRow {
wake_from,
outcome,
bus,
tool_calls,
open_threads_count,
open_reminders_count,
} = args;
@ -80,7 +86,6 @@ pub fn build_row(args: TurnRowArgs<'_>) -> TurnStatRow {
let model = bus.last_resolved_model().unwrap_or(model);
let cost = bus.last_cost_usage().unwrap_or_default();
let ctx = bus.last_ctx_usage().unwrap_or(cost);
let tool_calls = bus.take_tool_calls();
let tool_call_count: u64 = tool_calls.values().copied().sum();
let tool_call_breakdown_json = if tool_calls.is_empty() {
None