The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(agent): every todo plan change reaches the UI, and nothing else does
sanil-2346b03c662324
diff --git a/crates/openhuman-core/src/agent/tools/todo.rs b/crates/openhuman-core/src/agent/tools/todo.rsindex 6293186769..9aae3cb6ce 100644--- a/crates/openhuman-core/src/agent/tools/todo.rs+++ b/crates/openhuman-core/src/agent/tools/todo.rs@@ -82,44 +82,52 @@ impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext> for T.map(|c| c.workspace_dir).map_err(|e| anyhow::anyhow!("[tool][todo] load config: {e}"))?,};- let is_write = ["todos", "complete", "cancel"]- .iter()- .any(|key| arguments.get(*key).is_some());+ let writes = writes_plan(&arguments);let scope = current_scope(parent.data.parent.as_ref(), Some(&context));let result = TodoTool::new(workspace_dir).execute_with_parent_context(arguments, parent.data.parent.clone(), Some(&context)).await?;- // Only a write (the whole list, a `complete` or a `cancel`) changes- // anything the frontend's todo drawer needs to hear about; a bare read- // (`{}`) re-reports the same list and would just be a redundant socket- // event.- if is_write && !result.is_error {- if let Some(id) = scope.session_id() {- match serde_json::from_str::<serde_json::Value>(&result.output())- .ok()- .and_then(|payload| payload.get("todos").cloned())- {- Some(todos) => {- crate::core::bus::BUS.publish(- crate::core::events::DomainEvent::ThreadTodosChanged {- thread_id: id.to_string(),- todos,- },- );- }- None => {- tracing::debug!(- thread_id = id,- "[tool][todo] write succeeded but result had no `todos` field — skipping ThreadTodosChanged"- );- }- }- }+ if let (Some(id), Some(todos)) = (scope.session_id(), changed_todos(writes, &result)) {+ crate::core::bus::BUS.publish(crate::core::events::DomainEvent::ThreadTodosChanged {+ thread_id: id.to_string(),+ todos,+ });}Ok(result)}}+/// Whether a `todo` call asks to change the plan: the whole list (`todos`), a+/// `complete` or a `cancel`, in any of their shapes (one step, a list, a list+/// sent as a string, or `complete` and `cancel` together). A read (`{}`) or a+/// call that carries only notes (`facts`, `blockers`, `approach`, `retract`)+/// leaves the plan as it was.+fn writes_plan(arguments: &serde_json::Value) -> bool {+ ["todos", "complete", "cancel"]+ .iter()+ .any(|key| arguments.get(*key).is_some())+}++/// The list to send the frontend's todo drawer after a call, or `None` when+/// the plan did not change: the call did not ask to (`writes` from+/// [`writes_plan`]), or it was refused (an out-of-order tick, a bad step), in+/// which case the list is as it was. A re-sent unchanged list would only be a+/// redundant socket event.+fn changed_todos(writes: bool, result: &ToolResult) -> Option<serde_json::Value> {+ if !writes || result.is_error {+ return None;+ }+ let todos = serde_json::from_str::<serde_json::Value>(&result.output())+ .ok()+ .and_then(|payload| payload.get("todos").cloned());+ if todos.is_none() {+ tracing::debug!(+ "[tool][todo] write succeeded but result had no `todos` field — skipping ThreadTodosChanged"+ );+ }+ todos+}+impl TodoTool {pub fn new(workspace_dir: PathBuf) -> Self {Self {diff --git a/crates/openhuman-core/src/agent/tools/todo_tests.rs b/crates/openhuman-core/src/agent/tools/todo_tests.rsindex 0c49cc062a..777468e3de 100644--- a/crates/openhuman-core/src/agent/tools/todo_tests.rs+++ b/crates/openhuman-core/src/agent/tools/todo_tests.rs@@ -335,3 +335,111 @@ async fn sessions_do_not_see_each_other_and_a_list_survives_across_turns() {.is_empty());}++/// Runs `arguments` through the tool and returns the list the frontend's todo+/// drawer would be sent (`ThreadTodosChanged`), if any.+async fn sent_to_the_drawer(tool: &TodoTool, arguments: Value) -> Option<Value> {+ let writes = writes_plan(&arguments);+ let result = tool.execute(arguments).await.unwrap();+ changed_todos(writes, &result)+}++fn drawer_statuses(todos: &Value) -> Vec<&str> {+ todos+ .as_array()+ .unwrap()+ .iter()+ .map(|item| item["status"].as_str().unwrap())+ .collect()+}++/// Every call that changes the plan reaches the drawer with the new list, in+/// each shape the tool takes (whole list, a `complete` list or one sent as a+/// string, `cancel` and `complete` together, a tick with notes); a read, a+/// notes-only call and a refused call send nothing.+#[tokio::test]+async fn every_plan_change_reaches_the_todo_drawer_and_nothing_else_does() {+ let _guard = scratch_lock_async().await;+ let workspace_dir = test_workspace();+ reset_scratch(&workspace_dir).await;+ let tool = TodoTool::new(workspace_dir.clone());++ let written = sent_to_the_drawer(+ &tool,+ json!({ "todos": [+ { "content": "Inspect", "status": "pending" },+ { "content": "Configure", "status": "pending" },+ { "content": "Create list", "status": "pending" },+ { "content": "Start", "status": "pending" },+ { "content": "Verify", "status": "pending" }+ ] }),+ )+ .await+ .expect("a whole-list write is sent");+ assert_eq!(drawer_statuses(&written)[0], "in_progress");++ let ticked = sent_to_the_drawer(&tool, json!({ "complete": [1, 2] }))+ .await+ .expect("a `complete` list is sent");+ assert_eq!(+ drawer_statuses(&ticked),+ [+ "completed",+ "completed",+ "in_progress",+ "pending",+ "pending"+ ]+ );++ let combined = sent_to_the_drawer(+ &tool,+ json!({ "complete": "[3]", "cancel": 4, "reason": "not needed" }),+ )+ .await+ .expect("`complete` (as a string) with `cancel` is sent");+ assert_eq!(+ drawer_statuses(&combined),+ [+ "completed",+ "completed",+ "completed",+ "cancelled",+ "in_progress"+ ]+ );+ assert_eq!(combined[3]["reason"], "not needed");++ assert!(+ sent_to_the_drawer(&tool, json!({ "facts": ["postfix runs"] }))+ .await+ .is_none(),+ "notes alone leave the plan as it was"+ );+ assert!(+ sent_to_the_drawer(&tool, json!({})).await.is_none(),+ "a read changes nothing"+ );++ let refused = tool.execute(json!({ "complete": 9 })).await.unwrap();+ assert!(refused.is_error, "{}", refused.output());+ assert!(+ changed_todos(true, &refused).is_none(),+ "a refused call leaves the plan as it was"+ );++ let finished = sent_to_the_drawer(&tool, json!({ "complete": 5, "facts": ["eval.py passes"] }))+ .await+ .expect("a tick that carries notes is sent");+ assert_eq!(+ drawer_statuses(&finished),+ [+ "completed",+ "completed",+ "completed",+ "cancelled",+ "completed"+ ]+ );+ reset_scratch(&workspace_dir).await;+}