Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(web_chat): emit throttled turn_cost events during progress

Steven Enamakel071947f19075
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index b06bbd301c..44a45a0fc8 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -1490,6 +1490,39 @@ pub(crate) fn spawn_progress_bridge(
in={input_tokens} out={output_tokens} cached_in={cached_input_tokens} \
total_usd={total_usd:.4} client_id={client_id} thread_id={thread_id}"
);
+
+ // Live cost readout: throttled so a fast multi-round turn
+ // doesn't flood the socket with one `turn_cost` per model
+ // call. `TurnCostUpdated` is the parent's cumulative
+ // rollup only — it carries no per-sub-agent breakdown, so
+ // `subagents` stays empty here; the final `chat_done.usage`
+ // (built from `LastTurnUsage` at delivery) is still where
+ // sub-agent attribution shows up.
+ let should_emit_turn_cost = last_turn_cost_emit
+ .map(|at| at.elapsed() >= TURN_COST_EMIT_MIN_INTERVAL)
+ .unwrap_or(true);
+ if should_emit_turn_cost {
+ last_turn_cost_emit = Some(std::time::Instant::now());
+ publish_seq_stamped(
+ &mut emit_seq,
+ WebChannelEvent {
+ event: "turn_cost".to_string(),
+ client_id: client_id.clone(),
+ thread_id: thread_id.clone(),
+ request_id: request_id.clone(),
+ round: Some(iteration),
+ usage: Some(crate::core::socketio::TurnUsagePayload {
+ input_tokens,
+ output_tokens,
+ cached_input_tokens,
+ cost_usd: total_usd,
+ context_window: 0,
+ subagents: Vec::new(),
+ }),
+ ..Default::default()
+ },
+ );
+ }
}
AgentProgress::TurnContent { .. } => {
// Prompt/reply content is attached to the trace span by the