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(threads): handle missing turn state in mirror observer
Steven Enamakel7d55e8a8111d
diff --git a/app/src/components/assistant-ui/elements/message-timing.aui.tsx b/app/src/components/assistant-ui/elements/message-timing.aui.tsxnew file mode 100644index 0000000000..05878d78ce--- /dev/null+++ b/app/src/components/assistant-ui/elements/message-timing.aui.tsx@@ -0,0 +1,125 @@+'use client';++/**+ * Vendored from the assistant-ui `elements-message-timing` registry item+ * (https://r.assistant-ui.com/styles/base-nova/elements-message-timing.json).+ * Changes from upstream:+ * - `cn` import path (`@/components/assistant-ui/lib/utils`).+ * - `Tooltip`/`TooltipContent`/`TooltipProvider`/`TooltipTrigger` import path+ * (`@/components/assistant-ui/ui/tooltip`).+ * - "First token"/"Total"/"Speed"/"Chunks" and the "tok/s" suffix are now+ * `firstTokenLabel`/`totalLabel`/`speedLabel`/`chunksLabel`/+ * `tokensPerSecondSuffix` props; the "Message timing" aria-label is+ * `ariaLabel`; all with English defaults, for `useT()`.+ */+import { useMessageTiming } from '@assistant-ui/react';+import { cn } from '@/components/assistant-ui/lib/utils';+import {+ Tooltip,+ TooltipContent,+ TooltipProvider,+ TooltipTrigger,+} from '@/components/assistant-ui/ui/tooltip';+import type { FC } from 'react';++const formatTimingMs = (ms: number | undefined): string => {+ if (ms === undefined) return '—';+ if (ms < 1000) return `${Math.round(ms)}ms`;+ return `${(ms / 1000).toFixed(2)}s`;+};++/**+ * Shows streaming stats (TTFT, total time, tok/s, chunks) as a badge with a+ * hover/focus tooltip. Renders nothing until the stream completes.+ *+ * Place it inside `ActionBarPrimitive.Root` in your `thread.tsx` so it+ * inherits the action bar's autohide behaviour:+ *+ * ```tsx+ * import { MessageTiming } from "@/components/assistant-ui/elements/message-timing.aui";+ *+ * <ActionBarPrimitive.Root >+ * <ActionBarPrimitive.Copy />+ * <ActionBarPrimitive.Reload />+ * <MessageTiming /> // <-- add this+ * </ActionBarPrimitive.Root>+ * ```+ *+ * @param side - Side of the tooltip relative to the badge trigger.+ * @default "right"+ */+export const MessageTiming: FC<{+ className?: string;+ side?: 'top' | 'right' | 'bottom' | 'left';+ firstTokenLabel?: string;+ totalLabel?: string;+ speedLabel?: string;+ chunksLabel?: string;+ ariaLabel?: string;+ tokensPerSecondSuffix?: string;+ formatTiming?: (ms: number | undefined) => string;+}> = ({+ className,+ side = 'right',+ firstTokenLabel = 'First token',+ totalLabel = 'Total',+ speedLabel = 'Speed',+ chunksLabel = 'Chunks',+ ariaLabel = 'Message timing',+ tokensPerSecondSuffix = 'tok/s',+ formatTiming = formatTimingMs,+}) => {+ const timing = useMessageTiming();+ if (timing?.totalStreamTime === undefined) return null;++ return (+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ data-slot="message-timing-trigger"+ aria-label={ariaLabel}+ className={cn(+ 'text-muted-foreground hover:bg-accent hover:text-accent-foreground flex items-center rounded-md p-1 font-mono text-xs tabular-nums transition-colors',+ className+ )}+ />+ }>+ {formatTiming(timing.totalStreamTime)}+ </TooltipTrigger>+ <TooltipContent+ side={side}+ sideOffset={8}+ data-slot="message-timing-popover"+ className="bg-popover text-popover-foreground border px-3 py-2 [&_[data-slot=tooltip-arrow]]:hidden">+ <div className="grid min-w-35 gap-1.5 text-xs">+ {timing.firstTokenTime !== undefined && (+ <div className="flex items-center justify-between gap-4">+ <span className="text-muted-foreground">{firstTokenLabel}</span>+ <span className="font-mono tabular-nums">{formatTiming(timing.firstTokenTime)}</span>+ </div>+ )}+ <div className="flex items-center justify-between gap-4">+ <span className="text-muted-foreground">{totalLabel}</span>+ <span className="font-mono tabular-nums">{formatTiming(timing.totalStreamTime)}</span>+ </div>+ {timing.tokensPerSecond !== undefined && (+ <div className="flex items-center justify-between gap-4">+ <span className="text-muted-foreground">{speedLabel}</span>+ <span className="font-mono tabular-nums">+ {timing.tokensPerSecond.toFixed(1)} {tokensPerSecondSuffix}+ </span>+ </div>+ )}+ <div className="flex items-center justify-between gap-4">+ <span className="text-muted-foreground">{chunksLabel}</span>+ <span className="font-mono tabular-nums">{timing.totalChunks}</span>+ </div>+ </div>+ </TooltipContent>+ </Tooltip>+ </TooltipProvider>+ );+};diff --git a/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs b/crates/openhuman-core/src/threads/turn_state/mirror/observe.rsindex 8c98a4e48e..c7b8861f99 100644--- a/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs+++ b/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs@@ -133,10 +133,30 @@ impl TurnStateMirror {dedicated_thread,worker_thread_id,display_name,+ parent_call_id,..} => {self.state.phase = Some(TurnPhase::Subagent);self.state.active_subagent = Some(agent_id.clone());+ // Derive the real invoking tool's name from the parent row+ // (`spawn_parallel_agents`, `spawn_async_subagent`,+ // `continue_subagent`, a synthesized `delegate_*`, …) instead+ // of hardcoding `spawn_subagent`, which was wrong for every+ // other delegation path. Falls back to the historical+ // default when there's no `parent_call_id` (e.g.+ // `orchestration::ops`) or no matching row (e.g. it already+ // scrolled out of the timeline).+ let source_tool_name = parent_call_id+ .as_deref()+ .and_then(|id| {+ self.state+ .tool_timeline+ .iter()+ .rev()+ .find(|entry| entry.id == id)+ })+ .map(|entry| entry.name.clone())+ .unwrap_or_else(|| "spawn_subagent".to_string());let seq = self.next_tool_seq();self.state.tool_timeline.push(ToolTimelineEntry {id: format!("subagent:{task_id}"),@@ -146,7 +166,7 @@ impl TurnStateMirror {args_buffer: None,display_name: display_name.clone().or_else(|| Some(agent_id.clone())),detail: None,- source_tool_name: Some("spawn_subagent".to_string()),+ source_tool_name: Some(source_tool_name),subagent: Some(SubagentActivity {task_id: task_id.clone(),agent_id: agent_id.clone(),@@ -159,6 +179,8 @@ impl TurnStateMirror {elapsed_ms: None,output_chars: None,worker_thread_id: worker_thread_id.clone(),+ parent_call_id: parent_call_id.clone(),+ output: None,tool_calls: Vec::new(),transcript: Vec::new(),}),@@ -174,6 +196,7 @@ impl TurnStateMirror {elapsed_ms,iterations,output_chars,+ output,..} => {if let Some(entry) = self.find_subagent_entry_mut(task_id) {@@ -182,6 +205,7 @@ impl TurnStateMirror {activity.elapsed_ms = Some(*elapsed_ms);activity.iterations = Some(*iterations);activity.output_chars = Some(*output_chars);+ activity.output = cap_persisted_output(output);}}self.state.active_subagent = None;