Spaces:
Sleeping
Sleeping
Claw Web
fix: add retry with exponential backoff for 429 errors, revert default to MiMo-V2-Flash
b8ba5a3 Bug Analysis - Chat Message Flow
Bug 1: Auth fails on /api/chat/stream (FIXED)
getAuthUser()in chat-endpoint.ts used SDK auth which requires JWT cookie- In dev mode, no cookie is set → returns null → 401 Unauthorized
- Fix: Added dev-mode bypass matching tRPC context.ts
Bug 2: Race condition in Home.tsx session creation
- When user sends first message with no session:
handleSend()callscreateSession.mutate()with inlineonSuccessthat callssendMessage(content, session.id)- But
createSessionalso has a globalonSuccessthat callsclearMessages() - Race:
sendMessageadds user msg + assistant placeholder →clearMessages()wipes them
- Fix: Remove
clearMessages()from global createSession.onSuccess when it's triggered by handleSend
Bug 3: sessionMessages useEffect overwrites optimistic state
- When
currentSessionIdchanges,trpc.messages.list.useQueryfires - The useEffect unconditionally calls
setMessages(mapped) - This can overwrite the optimistic user message added by useChat before the DB message is visible
- Fix: Don't overwrite messages during streaming
Bug 4: "done" SSE event with empty data gets skipped
- Line 123 in useChat.ts:
if (!dataStr || dataStr === "{}") continue; - The "done" event sends
data: {}which gets skipped - this is fine - But the "done" event should trigger cleanup
Action items:
- ✅ Fix auth bypass in chat-endpoint.ts
- Fix race condition in Home.tsx
- Guard sessionMessages effect during streaming
- Test end-to-end