๐ง Streaming Debug Guide
๐จ Emergency Fixes Appliedโ
Issue 1: React Hooks Order Error โ FIXEDโ
Problem: "React has detected a change in the order of Hooks called by SessionContainer" Cause: WebSocket subscription hook was re-subscribing on every state change Fix:
- Removed unstable dependencies from
useSubscribeChatCompletion
- Made message handler truly stable with only
sessionId
andqueryClient
dependencies - Removed problematic telemetry hooks that caused order changes
Issue 2: WebSocket JSON Parse Errors โ FIXEDโ
Problem: SyntaxError: Unexpected token 'T', "This funct"... is not valid JSON
Cause: SST dev environment sending non-JSON error messages to WebSocket
Fix:
- Added robust pre-parsing checks for JSON format
- Graceful handling of SST infrastructure messages
- Better error logging for actual parsing issues
Issue 3: Streaming Freeze After First Chunk ๐ง INVESTIGATINGโ
Symptoms: Response freezes at "The world of cocktail", full response appears on page reload Suspected Causes:
- Server throttling too aggressive
- Client-side rendering bottlenecks
- WebSocket message loss during subscription changes
๐ Diagnostic Tools Addedโ
Client-Side Telemetryโ
Console logs now show:
๐ [STREAMING] WebSocket subscription created with ID: abc123
๐ [STREAMING] First chunk received for subscription abc123
โก [STREAMING] Chunk 10: 45ms since last (avg: 52ms)
๐ [STREAMING] Quest completed for subscription abc123:
- Total messages: 157
- Total time: 8,234ms
- Average interval: 52ms
Server-Side Telemetryโ
Console logs now show:
โฑ๏ธ [STREAMING] Server throttling enabled: 5ms interval
๐ค [STREAMING] Chunk sent: +67 chars (total: 342), interval: 8ms
๐ค [STREAMING] Final message sent, content length: 1,847
๐งช Testing Environment Variablesโ
Disable Server Throttling (Testing Only)โ
export DISABLE_SERVER_THROTTLING=true
This removes ALL server-side throttling and sends every 5+ character change immediately to test if server throttling is causing client issues.
Development Optimizationsโ
Already active in development:
- Reduced throttling: 5ms (vs 25ms production)
- Verbose logging enabled
- History count reduced to 5 for faster processing
๐ต๏ธ Current Investigation Planโ
Step 1: Test Server Throttlingโ
- Set
DISABLE_SERVER_THROTTLING=true
- Restart dev server
- Test streaming - does it still freeze?
Step 2: Monitor WebSocket Messagesโ
- Open browser DevTools โ Network โ WS (WebSocket)
- Start streaming request
- Watch for:
- Message frequency
- Connection drops
- Large gaps in timing
Step 3: Check React Renderingโ
- Use React DevTools Profiler
- Monitor component re-renders during streaming
- Look for expensive render cycles
Step 4: Database Query Analysisโ
- Check server logs for quest status queries
- Verify our database optimizations are working
- Look for any blocking operations
๐ฏ Success Metricsโ
Before Fixes:
- โ React hooks error breaking subscriptions
- โ WebSocket JSON parse errors flooding console
- โ Streaming freezes after first chunk
- โ Full response only visible after page reload
After Fixes:
- โ Clean WebSocket subscription lifecycle
- โ Robust message parsing with SST compatibility
- ๐ง Testing: Streaming should continue smoothly
- ๐ง Testing: Real-time updates without reload needed
๐ Next Stepsโ
- Test the fixes - Start a new streaming request
- Monitor console - Look for our new telemetry logs
- Check for errors - Should see no more hooks/JSON errors
- Verify streaming - Response should update in real-time
If streaming still freezes, we have comprehensive telemetry to identify exactly where the problem occurs!