akseljoonas HF Staff Claude Opus 4.6 commited on
Commit
7554f29
Β·
1 Parent(s): f8e758f

fix: clear global activity state when switching away from a session

Browse files

When a session becomes inactive, reset isProcessing, activityStatus,
and panel state so the next session doesn't inherit stale UI (e.g.
shimmering banner from a background tool execution).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

frontend/src/components/SessionChat.tsx CHANGED
@@ -35,9 +35,11 @@ export default function SessionChat({ sessionId, isActive, onSessionDead }: Sess
35
 
36
  // When this session becomes active, sync ALL global agentStore state
37
  // so the UI correctly reflects this session's current state.
 
38
  const prevActiveRef = useRef(isActive);
39
  useEffect(() => {
40
  if (isActive && !prevActiveRef.current) {
 
41
  const store = useAgentStore.getState();
42
 
43
  // SSE transport has no persistent connection β€” always connected
@@ -101,6 +103,12 @@ export default function SessionChat({ sessionId, isActive, onSessionDead }: Sess
101
  store.setProcessing(false);
102
  }
103
  }
 
 
 
 
 
 
104
  }
105
  prevActiveRef.current = isActive;
106
  }, [isActive, messages]);
 
35
 
36
  // When this session becomes active, sync ALL global agentStore state
37
  // so the UI correctly reflects this session's current state.
38
+ // When it becomes inactive, clear global state so the next session starts clean.
39
  const prevActiveRef = useRef(isActive);
40
  useEffect(() => {
41
  if (isActive && !prevActiveRef.current) {
42
+ // ── Becoming active: restore this session's state ──
43
  const store = useAgentStore.getState();
44
 
45
  // SSE transport has no persistent connection β€” always connected
 
103
  store.setProcessing(false);
104
  }
105
  }
106
+ } else if (!isActive && prevActiveRef.current) {
107
+ // ── Becoming inactive: clear global state so the next session starts clean ──
108
+ const store = useAgentStore.getState();
109
+ store.setActivityStatus({ type: 'idle' });
110
+ store.setProcessing(false);
111
+ store.clearPanel();
112
  }
113
  prevActiveRef.current = isActive;
114
  }, [isActive, messages]);