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(conversations): refresh thread todos and goal when a turn settles
Steven Enamakeld185f2dbc956
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex bca1b9ff99..6239497532 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -1769,8 +1769,9 @@ const Conversations = ({// `thread_goal_updated` core events (`aui/useThreadTodos.ts` /// `aui/useThreadGoal.ts`), primed on thread open by the RPC pair below.// Progress cards are presented in the transcript by TurnTaskProvider.- useLoadThreadTodos(selectedThreadId ?? null);- useLoadThreadGoal(selectedThreadId ?? null);+ const harnessStateRevision = selectedThreadId ? inferenceTurnLifecycleByThread[selectedThreadId] ?? 'idle' : '';+ useLoadThreadTodos(selectedThreadId ?? null, harnessStateRevision);+ useLoadThreadGoal(selectedThreadId ?? null, harnessStateRevision);// A plan the orchestrator parked for interactive review (request_plan_review// gate). When present, the PlanReviewCard renders above the composer and// resolves the parked turn.diff --git a/app/src/features/conversations/aui/useThreadGoal.ts b/app/src/features/conversations/aui/useThreadGoal.tsindex 2f5a805442..04f74b39bb 100644--- a/app/src/features/conversations/aui/useThreadGoal.ts+++ b/app/src/features/conversations/aui/useThreadGoal.ts@@ -1,3 +1,5 @@+import { useStore } from 'react-redux';+import type { RootState } from '../../../store';/*** The thread's current goal, read from `threadGoalSlice` (populated by the* `thread_goal_updated` / `thread_goal_cleared` socket events via@@ -26,18 +28,21 @@ export function useThreadGoal(threadId: string | null): ThreadGoalView | null {* Loads the thread's current goal once per `threadId` via* `openhuman.threads_goal_get`, mirroring {@link useLoadThreadTodos}.*/-export function useLoadThreadGoal(threadId: string | null): void {+export function useLoadThreadGoal(threadId: string | null, revision = ''): void {+ const store = useStore<RootState>();const dispatch = useAppDispatch();const requestedFor = useRef<string | null>(null);useEffect(() => {- if (!threadId || requestedFor.current === threadId) return;- requestedFor.current = threadId;+ const key = `${threadId}:${revision}`;+ if (!threadId || requestedFor.current === key) return;+ requestedFor.current = key;+ const before = store.getState().threadGoal.byThread[threadId];let cancelled = false;void (async () => {try {const goal = await threadApi.getGoal(threadId);- if (cancelled) return;+ if (cancelled || store.getState().threadGoal.byThread[threadId] !== before) return;dispatch(setThreadGoal({ threadId, goal }));} catch {// Older core without the RPC, or a transient failure — the live@@ -47,5 +52,5 @@ export function useLoadThreadGoal(threadId: string | null): void {return () => {cancelled = true;};- }, [threadId, dispatch]);+ }, [threadId, revision, dispatch, store]);}diff --git a/app/src/features/conversations/aui/useThreadTodos.test.tsx b/app/src/features/conversations/aui/useThreadTodos.test.tsxindex 50b928f924..d13c3a8f40 100644--- a/app/src/features/conversations/aui/useThreadTodos.test.tsx+++ b/app/src/features/conversations/aui/useThreadTodos.test.tsx@@ -1,11 +1,11 @@import { combineReducers, configureStore } from '@reduxjs/toolkit';-import { renderHook, waitFor } from '@testing-library/react';+import { act, renderHook, waitFor } from '@testing-library/react';import type { ReactNode } from 'react';import { Provider } from 'react-redux';import { beforeEach, describe, expect, it, vi } from 'vitest';import { threadApi } from '../../../services/api/threadApi';-import threadTodosReducer from '../../../store/threadTodosSlice';+import threadTodosReducer, {setThreadTodos} from '../../../store/threadTodosSlice';import { useLoadThreadTodos, useThreadTodos } from './useThreadTodos';vi.mock('../../../services/api/threadApi', () => ({ threadApi: { getTodos: vi.fn() } }));@@ -63,3 +63,23 @@ describe('useLoadThreadTodos', () => {expect(threadApi.getTodos).not.toHaveBeenCalled();});});+++it('refreshes the finished plan when a turn settles without a todo push', async () => {+ const {store, wrapper} = setup();+ vi.mocked(threadApi.getTodos).mockReset().mockResolvedValueOnce([{content: 'Step', status: 'in_progress'}]).mockResolvedValueOnce([{content: 'Step', status: 'completed'}]);+ const {rerender} = renderHook(({revision}) => useLoadThreadTodos('t1', revision), {wrapper, initialProps: {revision: 'running'}});+ await waitFor(() => expect(store.getState().threadTodos.byThread.t1?.[0].status).toBe('in_progress'));+ rerender({revision: 'idle'});+ await waitFor(() => expect(store.getState().threadTodos.byThread.t1?.[0].status).toBe('completed'));+});++it('does not let a delayed hydration overwrite a newer live todo event', async () => {+ const {store, wrapper} = setup();+ let resolve!: (todos: {content: string; status: 'pending'}[]) => void;+ vi.mocked(threadApi.getTodos).mockReset().mockReturnValueOnce(new Promise(done => {resolve = done;}));+ renderHook(() => useLoadThreadTodos('t1'), {wrapper});+ await act(async () => store.dispatch(setThreadTodos({threadId: 't1', todos: [{content: 'Step', status: 'completed'}]})));+ await act(async () => resolve([{content: 'Step', status: 'pending'}]));+ expect(store.getState().threadTodos.byThread.t1?.[0].status).toBe('completed');+});diff --git a/app/src/features/conversations/aui/useThreadTodos.ts b/app/src/features/conversations/aui/useThreadTodos.tsindex d6145ff999..d3802a28b4 100644--- a/app/src/features/conversations/aui/useThreadTodos.ts+++ b/app/src/features/conversations/aui/useThreadTodos.ts@@ -1,3 +1,5 @@+import { useStore } from 'react-redux';+import type { RootState } from '../../../store';/*** The thread's live todo list, read from `threadTodosSlice` (populated by the* `thread_todos_changed` socket event via `ChatRuntimeProvider`, and primed@@ -23,18 +25,21 @@ export function useThreadTodos(threadId: string | null): ThreadTodoItemView[] |* 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 {+export function useLoadThreadTodos(threadId: string | null, revision = ''): void {+ const store = useStore<RootState>();const dispatch = useAppDispatch();const requestedFor = useRef<string | null>(null);useEffect(() => {- if (!threadId || requestedFor.current === threadId) return;- requestedFor.current = threadId;+ const key = `${threadId}:${revision}`;+ if (!threadId || requestedFor.current === key) return;+ requestedFor.current = key;+ const before = store.getState().threadTodos.byThread[threadId];let cancelled = false;void (async () => {try {const todos = await threadApi.getTodos(threadId);- if (cancelled) return;+ if (cancelled || store.getState().threadTodos.byThread[threadId] !== before) return;dispatch(setThreadTodos({ threadId, todos }));} catch {// Older core without the RPC, or a transient failure — the live@@ -44,5 +49,5 @@ export function useLoadThreadTodos(threadId: string | null): void {return () => {cancelled = true;};- }, [threadId, dispatch]);+ }, [threadId, revision, dispatch, store]);}