Skip to content

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

refactor(web_chat): align work tracking with tinyagents runner

Steven Enamakelf564b036c030
diff --git a/crates/openhuman-core/src/web_chat/README.md b/crates/openhuman-core/src/web_chat/README.md
index 42d9571e3b..586f5d9195 100644
--- a/crates/openhuman-core/src/web_chat/README.md
+++ b/crates/openhuman-core/src/web_chat/README.md
@@ -112,7 +112,7 @@ subscriber all listen to.
6. **Progress, projected once.** The agent's `AgentProgress` stream goes
through a tap (`turn_host::tap_progress`) that folds each event into the
idle record and tells the runner when model or tool work opens and closes
- (`WorkStarted` / `WorkFinished`, `turn_activity::WorkTracker`), then
+ (`WorkStarted` / `WorkFinished`, TinyAgents' `turn_runner::WorkTracker`), then
hands it to the runner, which calls `WebEvents::progress` in order. That is
`ProgressProjection::on_event` (`progress.rs`), the one consumer: it maps the
event to the canonical output vocabulary (`progress_map.rs`), publishes it
@@ -214,7 +214,7 @@ endless heartbeat stream (#4746), both owned by the runner:
- The **idle guard** ends a turn that has emitted no progress event, with no
model or tool call in flight, for 900 s (`OPENHUMAN_WEB_TURN_IDLE_SECS`, `0`
disables it). The host feeds it: every event is progress, and
- `turn_activity::WorkTracker` reports open calls, so a silent provider retry
+ TinyAgents' `turn_runner::WorkTracker` reports open calls, so a silent provider retry
or a long shell build is never idle. What it catches is silence nothing else
bounds: session checkout, the persistence plumbing, or a harness that
stopped with no call open.
@@ -263,7 +263,7 @@ and artifact bridges itself (`openhuman-tui/src/runner.rs`).
| [`ingress.rs`](./ingress.rs) | `WebIngress`: the runner's ingress policy (attachments, guardrail, approval reply, hook). |
| [`turn_host.rs`](./turn_host.rs) | `WebHost`: session checkout/checkin and the agent run, the progress tap, the heartbeat. |
| [`turn_events.rs`](./turn_events.rs) | `WebEvents` (progress and the terminal event), `WebFailures` (error copy), `WebReplies` (reply store), `WebSummarizer` (grounded close). Sentry suppression and timeout tagging. |
-| [`turn_activity.rs`](./turn_activity.rs) | The idle guard's inputs (`WorkTracker`) and where a turn got stuck (`TurnActivity`, `StuckPoint`). |
+| [`turn_activity.rs`](./turn_activity.rs) | Where a turn got stuck (`TurnActivity`, `StuckPoint`) and its reply context. Work-liveness folding lives in TinyAgents' `turn_runner::WorkTracker`. |
| [`turn_close.rs`](./turn_close.rs) | The reply that closes a turn a guard stopped. |
| [`progress.rs`](./progress.rs) | `ProgressProjection`, the single consumer of a turn's progress, and `spawn_progress_bridge`. |
| [`progress_map.rs`](./progress_map.rs) | `AgentProgress` to the canonical `ChannelOutputEvent`, with payload caps. |
diff --git a/crates/openhuman-core/src/web_chat/turn_activity.rs b/crates/openhuman-core/src/web_chat/turn_activity.rs
index 0f47f26988..afeffbff05 100644
--- a/crates/openhuman-core/src/web_chat/turn_activity.rs
+++ b/crates/openhuman-core/src/web_chat/turn_activity.rs
@@ -1,27 +1,19 @@
//! What one web-chat turn last did, kept for the reply that closes it when a
-//! guard stops it, and the open-call tracking that feeds the idle guard.
+//! guard stops it.
//!
//! The idle guard itself is TinyAgents' turn runner: it ends a turn that has
//! been **silent with nothing in flight** for the idle window. Two inputs are
//! this host's:
//!
-//! * [`WorkTracker`] reports, as `WorkStarted` / `WorkFinished`, whether a
-//! parent-scope model call (`IterationStarted` -> `ModelCallCompleted`) or a
-//! tool call (`ToolCallStarted` -> `ToolCallCompleted`) is open. A silent
-//! provider retry or a long shell build is in flight, not idle. A completion
-//! event can be lost under backpressure, so later events also close what
-//! they prove finished: a `ToolCallStarted` means the model call that asked
-//! for it returned, an `IterationStarted` that the previous tool round did.
//! * [`TurnActivity`] remembers the last step, so the stop reply can say where
//! the turn got stuck ([`StuckPoint`]), and the config and reply locale the
//! turn resolved, so it is written to the turn's own workspace.
+//! * TinyAgents' [`tinyagents_harness::turn_runner::WorkTracker`] folds generic
+//! progress into the balanced work signals consumed by its idle guard.
use std::borrow::Cow;
-use std::collections::HashSet;
use std::sync::{Arc, Mutex};
-use tinyagents_harness::turn_runner::TurnSignal;
-
use tinyagents_harness::progress::AgentProgress;
/// Default idle window for a web-chat turn, in seconds.
@@ -176,53 +168,6 @@ impl TurnActivity {
}
}
-/// Whether a parent-scope model or tool call is open, reported to the idle
-/// guard as balanced `WorkStarted` / `WorkFinished` signals.
-#[derive(Debug, Default)]
-pub(crate) struct WorkTracker {
- model_call_open: bool,
- open_tool_calls: HashSet<String>,
-}
-
-impl WorkTracker {
- fn open(&self) -> bool {
- self.model_call_open || !self.open_tool_calls.is_empty()
- }
-
- /// Fold one event in; the signal, if the turn went from idle to working
- /// or back.
- pub(crate) fn observe(&mut self, event: &AgentProgress) -> Option<TurnSignal> {
- let was_open = self.open();
- match event {
- AgentProgress::IterationStarted { .. } => {
- self.open_tool_calls.clear();
- self.model_call_open = true;
- }
- AgentProgress::ModelCallCompleted {
- subagent_task_id: None,
- ..
- } => self.model_call_open = false,
- AgentProgress::ToolCallStarted { call_id, .. } => {
- self.model_call_open = false;
- self.open_tool_calls.insert(call_id.clone());
- }
- AgentProgress::ToolCallCompleted { call_id, .. } => {
- self.open_tool_calls.remove(call_id);
- }
- AgentProgress::TurnCompleted { .. } => {
- self.open_tool_calls.clear();
- self.model_call_open = false;
- }
- _ => {}
- }
- match (was_open, self.open()) {
- (false, true) => Some(TurnSignal::WorkStarted),
- (true, false) => Some(TurnSignal::WorkFinished),
- _ => None,
- }
- }
-}
-
#[cfg(test)]
#[path = "turn_activity_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rs
index 3c4e846db3..8099f44f17 100644
--- a/crates/openhuman-core/src/web_chat/turn_host.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host.rs
@@ -18,7 +18,7 @@ use std::time::Duration;
use async_trait::async_trait;
use tinyagents_harness::run_queue::RunQueue;
use tinyagents_harness::turn_runner::{
- QueueDisposition, TurnHost, TurnRequest, TurnResult, TurnSession, TurnSignal,
+ QueueDisposition, TurnHost, TurnRequest, TurnResult, TurnSession, TurnSignal, WorkTracker,
};
use tinyagents_harness::CancellationToken;
use tinyinference_llm::failure::is_empty_provider_response_text;
@@ -31,7 +31,7 @@ use super::session::{
checkin_session_agent, checkout_session_agent, normalize_model_override, CheckoutPolicy,
};
use super::surface::TurnIds;
-use super::turn_activity::{TurnActivity, WorkTracker};
+use super::turn_activity::TurnActivity;
use super::types::WebChatTaskResult;
use super::web_errors::{
inference_budget_exceeded_user_message, is_inference_budget_exceeded_error,