diff --git a/frontend/app/components/assistant-ui/thread.tsx b/frontend/app/components/assistant-ui/thread.tsx index fce6998..ca3573f 100644 --- a/frontend/app/components/assistant-ui/thread.tsx +++ b/frontend/app/components/assistant-ui/thread.tsx @@ -402,10 +402,12 @@ function useCurrentThreadSessionId({ clearPendingWorkspaceSessionId(); } }, [currentRun.sessionId, pendingSessionId]); + const replayRunSessionId = currentRun.active ? currentRun.sessionId : null; return ( - currentRun.sessionId ?? + replayRunSessionId ?? (includePending ? pendingSessionId : null) ?? - (includeActive ? activeSessionId : null) + (includeActive ? activeSessionId : null) ?? + currentRun.sessionId ); } @@ -1286,13 +1288,13 @@ function useComposerContextStatus() { useEffect(() => { const cleanLatestSessionId = normalizeSessionId(latestSessionId); - if (cleanLatestSessionId) { + if (cleanLatestSessionId && !isRunning) { writeActiveSessionId(cleanLatestSessionId); window.setTimeout(() => { window.dispatchEvent(new Event("claw-sessions-changed")); }, 0); } - }, [latestSessionId]); + }, [isRunning, latestSessionId]); useEffect(() => { if (wasRunningRef.current && !isRunning) { @@ -1315,9 +1317,12 @@ function useComposerContextStatus() { const statePayload = stateResponse.ok ? ((await stateResponse.json()) as ClawState) : {}; + const activeSessionId = normalizeSessionId(readActiveSessionId()); + const latestMessageSessionId = normalizeSessionId(latestSessionId); let sessionId = normalizeSessionId( - normalizeSessionId(latestSessionId) || - normalizeSessionId(readActiveSessionId()) || + (isRunning + ? activeSessionId || latestMessageSessionId + : latestMessageSessionId || activeSessionId) || normalizeSessionId(statePayload.active_session_id), ); if (sessionId) writeActiveSessionId(sessionId);