Skip to content

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

test(todo): migrate todo tool to per-thread storage with workspace isolation

Steven Enamakel9320244037e7
diff --git a/app/src/components/assistant-ui/elements/timeline.tsx b/app/src/components/assistant-ui/elements/timeline.tsx
new file mode 100644
index 0000000000..19b05f6d67
--- /dev/null
+++ b/app/src/components/assistant-ui/elements/timeline.tsx
@@ -0,0 +1,96 @@
+'use client';
+
+/**
+ * Vendored from the assistant-ui `elements-timeline` registry item
+ * (https://r.assistant-ui.com/styles/base-nova/elements-timeline.json).
+ * Changes from upstream:
+ * - `cn` import path (`@/components/assistant-ui/lib/utils`).
+ * - `../utils/range` -> this app's `@/components/assistant-ui/utils/range`
+ * (already vendored from the `elements-range` registry item).
+ *
+ * Note: also considered for WS-D's sub-agent activity feed; check this file
+ * before adding a second copy — it renders any `TimelineEvent[]`, so both
+ * surfaces (the conversation-map outline here, a sub-agent activity feed
+ * there) can share it.
+ */
+import type { ComponentProps } from 'react';
+
+import { cn } from '@/components/assistant-ui/lib/utils';
+import { take } from '@/components/assistant-ui/utils/range';
+
+import { mono, paper } from './surfaces';
+
+export type TimelineWhen = 'past' | 'now' | 'future';
+
+export interface TimelineEvent {
+ id: string;
+ when: TimelineWhen;
+ time: string;
+ title: string;
+ detail?: string;
+}
+
+export function Timeline({
+ events,
+ visibleCount,
+ className,
+ ...props
+}: Omit<ComponentProps<'div'>, 'children' | 'events' | 'visibleCount'> & {
+ events: readonly TimelineEvent[];
+ visibleCount: number;
+}) {
+ return (
+ <div
+ data-slot="timeline"
+ className={cn(paper, 'flex w-full max-w-sm flex-col rounded-2xl p-4', className)}
+ {...props}>
+ {take(events, visibleCount).map((event, i, shown) => (
+ <div
+ key={event.id}
+ className="fade-in slide-in-from-left-1 animate-in fill-mode-both grid grid-cols-[3.5rem_1rem_minmax(0,1fr)] gap-x-2 duration-300">
+ <span
+ className={cn(
+ mono,
+ 'pt-[3px] text-end tabular-nums',
+ event.when === 'future' ? 'text-foreground/25' : 'text-foreground/40'
+ )}>
+ {event.time}
+ </span>
+
+ <span className="flex flex-col items-center">
+ <span
+ className={cn(
+ 'mt-1 size-2 shrink-0 rounded-full',
+ event.when === 'now' && 'bg-blue-500 ring-4 ring-blue-500/15 dark:bg-blue-400',
+ event.when === 'past' && 'bg-foreground/30',
+ event.when === 'future' && 'border-foreground/20 border bg-transparent'
+ )}
+ />
+ {i < shown.length - 1 && (
+ <span
+ className={cn(
+ 'w-px flex-1',
+ event.when === 'future' ? 'bg-foreground/[0.08]' : 'bg-foreground/15'
+ )}
+ />
+ )}
+ </span>
+
+ <div className={cn('flex flex-col gap-0.5', i < shown.length - 1 && 'pb-3')}>
+ <span
+ className={cn(
+ 'text-[13px] break-words',
+ event.when === 'future' ? 'text-foreground/40' : 'text-foreground/90',
+ event.when === 'now' && 'font-medium'
+ )}>
+ {event.title}
+ </span>
+ {event.detail && (
+ <span className="text-foreground/45 text-xs leading-relaxed break-words">{event.detail}</span>
+ )}
+ </div>
+ </div>
+ ))}
+ </div>
+ );
+}
diff --git a/crates/openhuman-core/src/agent/tools/todo_tests.rs b/crates/openhuman-core/src/agent/tools/todo_tests.rs
index 3882df2ca9..2de40f4146 100644
--- a/crates/openhuman-core/src/agent/tools/todo_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/todo_tests.rs
@@ -9,8 +9,17 @@ fn scratch_lock() -> std::sync::MutexGuard<'static, ()> {
crate::agent::todos::ops::scratch_test_lock()
}
-async fn reset_scratch() {
- crate::agent::todos::ops::clear(&TodoScope::Scratch)
+/// A fresh on-disk workspace root for one test's `FileStore`-backed todo
+/// list. Each test gets its own tempdir so tests never see each other's
+/// persisted lists.
+fn test_workspace() -> std::path::PathBuf {
+ let dir = std::env::temp_dir().join(format!("openhuman-todo-test-{}", uuid::Uuid::new_v4()));
+ std::fs::create_dir_all(&dir).expect("create test workspace");
+ dir
+}
+
+async fn reset_scratch(workspace_dir: &std::path::Path) {
+ crate::agent::todos::ops::clear(workspace_dir, &TodoScope::Scratch)
.await
.expect("clear scratch");
}
@@ -22,8 +31,9 @@ fn payload(result: &ToolResult) -> Value {
#[tokio::test]
async fn a_write_replaces_the_whole_list_and_a_read_returns_it() {
let _guard = scratch_lock();
- reset_scratch().await;
- let tool = TodoTool::new();
+ let workspace_dir = test_workspace();
+ reset_scratch(&workspace_dir).await;
+ let tool = TodoTool::new(workspace_dir.clone());
let written = tool
.execute(json!({ "todos": [
@@ -60,14 +70,15 @@ async fn a_write_replaces_the_whole_list_and_a_read_returns_it() {
// An empty list clears it.
let cleared = tool.execute(json!({ "todos": [] })).await.unwrap();
assert!(payload(&cleared)["todos"].as_array().unwrap().is_empty());
- reset_scratch().await;
+ reset_scratch(&workspace_dir).await;
}
#[tokio::test]
async fn two_in_progress_items_are_rejected() {
let _guard = scratch_lock();
- reset_scratch().await;
- let result = TodoTool::new()
+ let workspace_dir = test_workspace();
+ reset_scratch(&workspace_dir).await;
+ let result = TodoTool::new(workspace_dir.clone())
.execute(json!({ "todos": [
{ "content": "a", "status": "in_progress" },
{ "content": "b", "status": "in_progress" }
@@ -75,7 +86,7 @@ async fn two_in_progress_items_are_rejected() {
.await
.unwrap();
assert!(result.is_error, "{}", result.output());
- reset_scratch().await;
+ reset_scratch(&workspace_dir).await;
}
/// Bad input is a tool error the model can correct, never an `Err`: a
@@ -83,7 +94,7 @@ async fn two_in_progress_items_are_rejected() {
/// exactly that way when a model sent the retired `{"cards": …}` shape.
#[tokio::test]
async fn bad_input_is_a_tool_error_not_a_harness_error() {
- let tool = TodoTool::new();
+ let tool = TodoTool::new(test_workspace());
for (args, expect) in [
(
json!({ "todos": [{ "content": " ", "status": "pending" }] }),
@@ -120,7 +131,7 @@ async fn bad_input_is_a_tool_error_not_a_harness_error() {
/// other spellings it lists are aliases of those three, not extra states.
#[test]
fn schema_is_the_claude_shape() {
- let tool = TodoTool::new();
+ let tool = TodoTool::new(test_workspace());
let schema = tool.parameters_schema();
let props = &schema["properties"];
assert!(props.get("todos").is_some());
@@ -160,11 +171,14 @@ fn schema_is_the_claude_shape() {
);
}
-/// The orchestrator's list is its session's list. It used to be routed to one
-/// app-wide `orchestrator-tasks` board that nothing rendered, so the items the
-/// model wrote never showed up in the thread the user was in.
+/// The orchestrator's list is its thread's list — keyed by the chat thread
+/// id, not `ParentExecutionContext::session_id` (which for the web channel is
+/// the `{client_id,thread_id}` JSON blob and would otherwise scatter one
+/// thread's todos across every reconnect). It used to be routed to one
+/// app-wide `orchestrator-tasks` board that nothing rendered, so the items
+/// the model wrote never showed up in the thread the user was in.
#[test]
-fn every_agent_binds_to_its_own_session() {
+fn every_agent_binds_to_its_own_thread() {
struct ThreadContext(&'static str);
impl ToolRunContext for ThreadContext {
fn thread_id(&self) -> Option<&str> {
@@ -202,41 +216,128 @@ fn every_agent_binds_to_its_own_session() {
assert_eq!(
current_scope(Some(&parent), Some(&ThreadContext("thread-live"))).session_id(),
- Some("orchestrator_thread-live"),
- "the parent's session wins over the thread id"
+ Some("thread-live"),
+ "the thread id wins over the parent's legacy session_id"
);
assert_eq!(
current_scope(None, Some(&ThreadContext("thread-live"))).session_id(),
Some("thread-live"),
"a thread-only caller keys on the thread"
);
+ assert_eq!(
+ current_scope(Some(&parent), None).session_id(),
+ Some("orchestrator_thread-live"),
+ "no thread id at all falls back to the legacy parent session_id"
+ );
assert_eq!(current_scope(None, None), TodoScope::Scratch);
}
+/// A list left under the pre-rekey `session_id` key is picked up once by the
+/// new thread-id key, instead of silently disappearing when this file's
+/// scope switched from `session_id`-first to `thread_id`-first.
+#[tokio::test]
+async fn a_legacy_session_keyed_list_is_migrated_forward_once() {
+ let workspace_dir = test_workspace();
+ struct ThreadContext(&'static str);
+ impl ToolRunContext for ThreadContext {
+ fn thread_id(&self) -> Option<&str> {
+ Some(self.0)
+ }
+ }
+ let parent = ParentExecutionContext {
+ agent_definition_id: "orchestrator".into(),
+ allowed_subagent_ids: std::collections::HashSet::new(),
+ turn_model_source: crate::agent::tinyagents::TurnModelSource::from_model(Arc::new(
+ tinyagents_harness::testkit::ScriptedModel::replies(vec!["done"]),
+ )),
+ all_tools: Arc::new(Vec::new()),
+ all_tool_specs: Arc::new(Vec::new()),
+ visible_tool_specs: Arc::new(Vec::new()),
+ visible_tool_names: std::collections::HashSet::new(),
+ subagent_tool_ceiling_names: std::collections::HashSet::new(),
+ model_name: "test-model".into(),
+ temperature: 0.0,
+ workspace_dir: workspace_dir.clone(),
+ workspace_descriptor: None,
+ memory: crate::memory::test_support::noop_memory(),
+ agent_config: crate::config::AgentConfig::default(),
+ workflows: Arc::new(Vec::new()),
+ memory_context: Arc::new(None),
+ session_id: "client-1|thread-legacy".into(),
+ channel: "test".into(),
+ connected_integrations: Vec::new(),
+ tool_call_format: crate::agent::prompts::ToolCallFormat::Native,
+ session_key: "parent-key".into(),
+ session_parent_prefix: None,
+ on_progress: None,
+ run_queue: None,
+ };
+
+ // Seed the legacy session-keyed list directly through the store, as if a
+ // pre-rekey process had written it.
+ let legacy_scope = TodoScope::Session {
+ id: parent.session_id.clone(),
+ };
+ let item = TodoItem::with_status("carried over", TodoStatus::InProgress);
+ crate::agent::todos::ops::replace(&workspace_dir, &legacy_scope, vec![item])
+ .await
+ .unwrap();
+
+ let tool = TodoTool::new(workspace_dir.clone());
+ let read = tool
+ .execute_with_parent_context(
+ json!({}),
+ Some(parent),
+ Some(&ThreadContext("thread-legacy")),
+ )
+ .await
+ .unwrap();
+ let p = payload(&read);
+ let todos = p["todos"].as_array().unwrap();
+ assert_eq!(todos.len(), 1, "{p}");
+ assert_eq!(todos[0]["content"], "carried over");
+
+ // The migrated list now lives under the thread-id key too.
+ let thread_scope = TodoScope::Session {
+ id: "thread-legacy".into(),
+ };
+ let migrated = crate::agent::todos::ops::list(&workspace_dir, &thread_scope)
+ .await
+ .unwrap();
+ assert_eq!(migrated.items.len(), 1);
+}
+
#[tokio::test]
async fn sessions_do_not_see_each_other_and_a_list_survives_across_turns() {
+ let workspace_dir = test_workspace();
let a = TodoScope::Session {
id: "sess-a".into(),
};
let b = TodoScope::Session {
id: "sess-b".into(),
};
- crate::agent::todos::ops::clear(&a).await.unwrap();
- crate::agent::todos::ops::clear(&b).await.unwrap();
+ crate::agent::todos::ops::clear(&workspace_dir, &a)
+ .await
+ .unwrap();
+ crate::agent::todos::ops::clear(&workspace_dir, &b)
+ .await
+ .unwrap();
let item = TodoItem::with_status("only in a", TodoStatus::InProgress);
- crate::agent::todos::ops::replace(&a, vec![item])
+ crate::agent::todos::ops::replace(&workspace_dir, &a, vec![item])
.await
.unwrap();
- let a_again = crate::agent::todos::ops::list(&a).await.unwrap();
+ let a_again = crate::agent::todos::ops::list(&workspace_dir, &a)
+ .await
+ .unwrap();
assert_eq!(
a_again.items.len(),
1,
"a later turn of the same session reads it back"
);
assert_eq!(a_again.thread_id, "sess-a");
- assert!(crate::agent::todos::ops::list(&b)
+ assert!(crate::agent::todos::ops::list(&workspace_dir, &b)
.await
.unwrap()
.items