@@ -191,10 +191,18 @@ export function DashboardAgentPanel({
191191 // Bumped on each open so a slower earlier open can't overwrite a newer one.
192192 const openChatRequestSeq = useRef ( 0 ) ;
193193
194+ // Bound to its chat, which remounts with a fresh guard ref on every switch.
195+ const [ sendRequest , setSendRequest ] = useState <
196+ { text : string ; seq : number ; chatId : string } | undefined
197+ > ( undefined ) ;
198+
194199 // The one way the panel changes chat: it invalidates any in-flight open and abandons a
195200 // half-configured watch card, which would otherwise be submitted against the new chat.
196201 const claimChatSlot = useCallback ( ( ) => {
197202 dispatchWatchCard ( { type : "chat-changed" } ) ;
203+ // A request belongs to the chat it was made in: the remounting chat has a fresh guard ref,
204+ // so a kept request would be sent a second time.
205+ setSendRequest ( undefined ) ;
198206 return ++ openChatRequestSeq . current ;
199207 } , [ ] ) ;
200208
@@ -345,10 +353,6 @@ export function DashboardAgentPanel({
345353 onUnreadWorkChange ?.( unreadWorkCount ( chats , active ?. chatId ) ) ;
346354 } , [ chats , chatsLoaded , active ?. chatId , onUnreadWorkChange ] ) ;
347355
348- // Bound to its chat, which remounts with a fresh guard ref on every switch.
349- const [ sendRequest , setSendRequest ] = useState <
350- { text : string ; seq : number ; chatId : string } | undefined
351- > ( undefined ) ;
352356 const handledRequestSeq = useRef < number | undefined > ( undefined ) ;
353357 useEffect ( ( ) => {
354358 if ( ! requestedMessage || handledRequestSeq . current === requestedMessage . seq ) return ;
0 commit comments