Stream Reconnection and Cancellation Not Working in Production
Environment
- Framework: Next.js (App Router)
- LangGraph SDK:
@langchain/langgraph-sdk/react - Hosting: Vercel
- Browser: Chrome 138
Issue Description
In my Next.js application using the LangGraph React SDK, stream reconnection and cancellation work perfectly in local development but fail silently in the production environment.
Specifically:
-
Working locally:
- Stream reconnection (via
reconnectOnMount: true) successfully rejoins existing streams when reloading a tab - Cancellation (via the
stop()function) successfully terminates running threads
- Stream reconnection (via
-
Not working in production:
- No API calls are made to the reconnection endpoint (
/threads/{id}/runs/{id}/stream) - No API calls are made to the cancellation endpoint (
/threads/{id}/runs/{id}/cancel) - No errors appear in the console
- No API calls are made to the reconnection endpoint (
What I’ve Tried
- Verified environment variables are correctly set in production
- Confirmed authentication is working (can create new threads and interact normally)
- Added detailed logging to the custom fetch implementation
- Confirmed the
stop()function exists and is being called
Code Example
const { isLoading, messages, values, submit, stop } = useStream<AgentGraphState>({
apiUrl: LANGGRAPH_DEPLOYMENT_URL,
assistantId: AGENT_NAME,
messagesKey: 'messages',
threadId: tab.threadId,
onThreadId: (threadId) => onThreadIdChange(tab.id, threadId),
callerOptions: {
fetch: customFetch // Custom fetch implementation with auth headers
},
reconnectOnMount: true,
});
// Stop handler
const handleStopBotResponse = useCallback(() => {
stop(); // This works locally but not in production
// Reset UI state...
}, [messages, stop]);
Any insights on why these specific endpoints might fail in production while other LangGraph API calls work correctly would be greatly appreciated!