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
fix(agent): correct thread todo state handling in run mode
Steven Enamakelf63c123d34a6
diff --git a/app/src/features/conversations/aui/useThreadTodos.ts b/app/src/features/conversations/aui/useThreadTodos.tsnew file mode 100644index 0000000000..c0d23e9bc3--- /dev/null+++ b/app/src/features/conversations/aui/useThreadTodos.ts@@ -0,0 +1,47 @@+/**+ * The thread's live todo list, read from `threadTodosSlice` (populated by the+ * `thread_todos_changed` socket event via `ChatRuntimeProvider`, and primed+ * on thread open by {@link useLoadThreadTodos}).+ */+import { useEffect, useRef } from 'react';++import { threadApi } from '../../../services/api/threadApi';+import { setThreadTodos } from '../../../store/threadTodosSlice';+import { useAppDispatch, useAppSelector } from '../../../store/hooks';+import type { ThreadTodoItemView } from '../../../store/threadTodosSlice';++/** `null` when the thread has no live entry yet (not "empty list"). */+export function useThreadTodos(threadId: string | null): ThreadTodoItemView[] | null {+ return useAppSelector(state => (threadId ? state.threadTodos.byThread[threadId] ?? null : null));+}++/**+ * Loads the thread's current todo list once per `threadId` via+ * `openhuman.threads_todos_get`, so a freshly opened thread doesn't wait for+ * the next live `thread_todos_changed` event. Any failure (older core, RPC+ * error) leaves the slice untouched — the live event stream is still the+ * primary source once a turn runs.+ */+export function useLoadThreadTodos(threadId: string | null): void {+ const dispatch = useAppDispatch();+ const requestedFor = useRef<string | null>(null);++ useEffect(() => {+ if (!threadId || requestedFor.current === threadId) return;+ requestedFor.current = threadId;+ let cancelled = false;+ void (async () => {+ try {+ const todos = await threadApi.getTodos(threadId);+ if (cancelled) return;+ dispatch(setThreadTodos({ threadId, todos }));+ } catch {+ // Older core without the RPC, or a transient failure — the live+ // socket event (or the next thread open) will still populate this.+ }+ })();+ return () => {+ cancelled = true;+ };+ }, [threadId, dispatch]);+}diff --git a/crates/openhuman-core/src/agent/tinyagents/run_mode.rs b/crates/openhuman-core/src/agent/tinyagents/run_mode.rsindex b10b638479..a8e3438fa0 100644--- a/crates/openhuman-core/src/agent/tinyagents/run_mode.rs+++ b/crates/openhuman-core/src/agent/tinyagents/run_mode.rs@@ -89,6 +89,138 @@ pub fn parse_mode_label(label: &str) -> Option<RunMode> {}}+// ── JSON-RPC surface ────────────────────────────────────────────────────────+//+// `agent.set_run_mode { thread_id, mode }` / `agent.get_run_mode { thread_id }`+// — lets the composer flip a thread into Plan mode (or read it back) without+// going through a tool call. Colocated here rather than a separate+// `schemas.rs` because this module IS the domain's entire surface (registry+// + RPC), not a multi-file domain directory.++use serde::de::DeserializeOwned;+use serde::Deserialize;+use serde_json::{Map, Value};++use crate::core::all::{ControllerFuture, RegisteredController};+use crate::core::{ControllerSchema, FieldSchema, TypeSchema};++pub fn all_controller_schemas() -> Vec<ControllerSchema> {+ vec![schema("set_run_mode"), schema("get_run_mode")]+}++pub fn all_registered_controllers() -> Vec<RegisteredController> {+ vec![+ RegisteredController {+ schema: schema("set_run_mode"),+ handler: handle_set_run_mode,+ },+ RegisteredController {+ schema: schema("get_run_mode"),+ handler: handle_get_run_mode,+ },+ ]+}++fn schema(function: &str) -> ControllerSchema {+ match function {+ "set_run_mode" => ControllerSchema {+ namespace: "agent",+ function: "set_run_mode",+ description: "Set a thread's Plan/Build run mode. Plan mode hides and denies \+ side-effecting tools (except plan_exit, request_plan_review, todo, \+ and goal_*) until the thread exits plan mode.",+ inputs: vec![+ FieldSchema {+ name: "thread_id",+ ty: TypeSchema::String,+ comment: "The thread to set the mode for.",+ required: true,+ },+ FieldSchema {+ name: "mode",+ ty: TypeSchema::String,+ comment: "One of `plan` | `build`.",+ required: true,+ },+ ],+ outputs: vec![FieldSchema {+ name: "mode",+ ty: TypeSchema::String,+ comment: "The mode now in effect for the thread.",+ required: true,+ }],+ },+ "get_run_mode" => ControllerSchema {+ namespace: "agent",+ function: "get_run_mode",+ description: "Read a thread's current Plan/Build run mode.",+ inputs: vec![FieldSchema {+ name: "thread_id",+ ty: TypeSchema::String,+ comment: "The thread to read the mode for.",+ required: true,+ }],+ outputs: vec![FieldSchema {+ name: "mode",+ ty: TypeSchema::String,+ comment: "One of `plan` | `build`.",+ required: true,+ }],+ },+ _ => ControllerSchema {+ namespace: "agent",+ function: "unknown",+ description: "Unknown agent run-mode controller function.",+ inputs: vec![],+ outputs: vec![FieldSchema {+ name: "error",+ ty: TypeSchema::String,+ comment: "Lookup error details.",+ required: true,+ }],+ },+ }+}++#[derive(Debug, Deserialize)]+struct ThreadModeParams {+ thread_id: String,+ mode: String,+}++#[derive(Debug, Deserialize)]+struct ThreadIdParams {+ thread_id: String,+}++fn handle_set_run_mode(params: Map<String, Value>) -> ControllerFuture {+ Box::pin(async move {+ let p = parse::<ThreadModeParams>(params)?;+ let Some(mode) = parse_mode_label(&p.mode) else {+ return Err(format!("invalid mode '{}' (expected plan|build)", p.mode));+ };+ tracing::debug!(+ thread_id = %p.thread_id,+ mode = %p.mode,+ "[rpc][agent] set_run_mode entry"+ );+ set_mode(&p.thread_id, mode);+ Ok(serde_json::json!({ "mode": mode_label(mode) }))+ })+}++fn handle_get_run_mode(params: Map<String, Value>) -> ControllerFuture {+ Box::pin(async move {+ let p = parse::<ThreadIdParams>(params)?;+ let mode = get_mode(&p.thread_id);+ Ok(serde_json::json!({ "mode": mode_label(mode) }))+ })+}++fn parse<T: DeserializeOwned>(params: Map<String, Value>) -> Result<T, String> {+ serde_json::from_value(Value::Object(params)).map_err(|e| format!("invalid params: {e}"))+}+#[cfg(test)]#[path = "run_mode_tests.rs"]mod tests;