Spaces:
AiCoderv2
/
Sleeping

akhaliq HF Staff commited on
Commit
4748143
·
1 Parent(s): c77d732

Comprehensive streaming fix: Eliminate all buffering sources

Browse files

Issue: Code streaming still not working - chunks arriving but not displaying
Root causes identified:
1. React 18 automatic batching delays state updates
2. Potential proxy/nginx buffering at various levels
3. DeepSeek using InferenceClient instead of OpenAI client

Complete fix across full stack:

Backend (backend_api.py):
- Convert DeepSeek to use OpenAI client for consistent streaming
- Add comprehensive anti-buffering headers:
* Cache-Control: no-cache, no-transform
* Content-Encoding: none
* Transfer-Encoding: chunked
* X-Accel-Buffering: no (prevents nginx buffering)
- Add logging for MiniMax and DeepSeek initialization
- All models now use OpenAI client (OpenRouter, MiniMax, DeepSeek)

Frontend (page.tsx):
- Import flushSync from react-dom
- Wrap setGeneratedCode in flushSync() to bypass React 18 batching
- Forces immediate synchronous DOM updates for each chunk
- No more delayed/batched state updates

How streaming works now:
1. Backend: LLM generates chunk → yield immediately (no buffer)
2. HTTP: Headers prevent all proxy/nginx buffering
3. Frontend: SSE receives chunk → flushSync forces immediate React update
4. Monaco: Editor updates character-by-character in real-time

This ensures true streaming where every single chunk appears immediately
as it's generated, with zero buffering at any layer of the stack.

2 files changed +21 -10
Files changed (2)
backend_api.py+12-4
frontend/src/app/page.tsx+9-6