Skip to content

Commit 98654da

Browse files
wdvrclaude
andauthored
Fix stream continuation on navigation to historic chats (#6813)
## Summary - Cancel active streaming when loading a historic chat session - Cancel active streaming when starting a new chat - Prevent streams from continuing in background when user navigates away - Add console logging for debugging stream cancellation - Ensure clean state transitions between active and historic chats ## Test plan - [x] Test stream stops when navigating to historic chat - [x] Test stream stops when starting new chat - [x] Run `yarn test` - all pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 5a55454 commit 98654da

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

torchci/components/TorchAgentPage.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ export const TorchAgentPage = () => {
147147
};
148148

149149
const loadChatSession = async (sessionId: string) => {
150+
// Cancel any active stream first
151+
if (fetchControllerRef.current && isLoading) {
152+
console.log("Cancelling active stream to load historic chat");
153+
fetchControllerRef.current.abort();
154+
fetchControllerRef.current = null;
155+
setIsLoading(false);
156+
}
157+
150158
setIsSessionLoading(true);
151159
setParsedResponses([]);
152160
setResponse("");
@@ -201,6 +209,14 @@ export const TorchAgentPage = () => {
201209
};
202210

203211
const startNewChat = () => {
212+
// Cancel any active stream first
213+
if (fetchControllerRef.current && isLoading) {
214+
console.log("Cancelling active stream to start new chat");
215+
fetchControllerRef.current.abort();
216+
fetchControllerRef.current = null;
217+
setIsLoading(false);
218+
}
219+
204220
setQuery("");
205221
setResponse("");
206222
setParsedResponses([]);

0 commit comments

Comments
 (0)