Skip to content

Commit 74cfca5

Browse files
committed
fix(todo): Refetch session after TodoWrite tool completes
Problem: Todo tool updates database but client's currentSession.todos remains stale, causing TodoList UI to show no todos. Root cause: Todo tool only returns summary (not actual todos), and there's no mechanism to update client state after database update. Solution: Refetch session from server when TodoWrite tool completes. Changes: 1. toolHandlers.ts: Added refetch logic in handleToolResult() - Detects when TodoWrite tool completes - Calls refetchCurrentSession() to fetch fresh data 2. Created refetch-session.ts utility - Fetches session from server via tRPC - Updates currentSession signal with fresh data - TodoList component re-renders with new todos Flow: - LLM calls TodoWrite tool - Tool updates database - Tool returns summary result - handleToolResult detects TodoWrite completion - refetchCurrentSession fetches session from server - currentSession signal updated with fresh todos - TodoList component shows todos Result: Todo UI now displays after tool execution
1 parent 802a512 commit 74cfca5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/code/src/screens/chat/streaming/handlers/toolHandlers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ export function handleToolResult(
205205
),
206206
false, // Don't skip for completed - result updates are idempotent
207207
);
208+
209+
// Refetch session if TodoWrite tool completed (todos were updated in database)
210+
if (event.toolName === "TodoWrite" && currentSessionId) {
211+
import("../../../utils/refetch-session.js").then(({ refetchCurrentSession }) => {
212+
refetchCurrentSession(currentSessionId).catch((err) => {
213+
console.error("[handleToolResult] Failed to refetch session after TodoWrite:", err);
214+
});
215+
});
216+
}
208217
}
209218

210219
export function handleToolError(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Session Refetch Utility
3+
* Refetches session from server and updates client state
4+
*/
5+
6+
import { getTRPCClient } from "@sylphx/code-client";
7+
import { updateCurrentSession } from "@sylphx/code-client";
8+
9+
/**
10+
* Refetch current session from server and update local state
11+
* Used when session data changes on server (e.g., todos updated by tool)
12+
*/
13+
export async function refetchCurrentSession(sessionId: string): Promise<void> {
14+
const client = getTRPCClient();
15+
16+
// @ts-expect-error - tRPC router types not fully resolved
17+
const session = await client.session.getById.query({ sessionId });
18+
19+
if (session) {
20+
updateCurrentSession(session);
21+
}
22+
}

0 commit comments

Comments
 (0)