fix(web): reset streaming UI state when background job completes - #521
Conversation
The getActiveStreamJob query only returns jobs with 'running' or 'pending' status. When a job completes, it returns null. The useEffect wasn't handling this case properly - it would just return early when activeStreamJob was null, leaving the UI stuck in 'streaming' state. Now when activeStreamJob becomes null and status is still 'streaming' or 'submitted', we properly reset the UI state to 'ready'.
|
🚅 Environment openchat-pr-521 in OpenChat has no services deployed. |
Greptile SummaryFixed a bug where the chat UI remained stuck in "streaming" state after message completion. The root cause was that Key changes:
Minor issue:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as usePersistentChat Hook
participant Convex as getActiveStreamJob Query
participant Backend as Background Stream Action
participant DB as Convex Database
User->>UI: Send message
UI->>Backend: startBackgroundStream()
Backend->>DB: Insert streamJob (status: "pending")
Backend->>Backend: Schedule executeStream action
UI->>UI: setStatus("streaming")
Note over Backend,DB: Stream execution starts
Backend->>DB: Update job status to "running"
Backend->>Backend: Fetch from OpenRouter API
loop Streaming chunks
Backend->>DB: Update job content
Convex->>UI: Return activeStreamJob (status: "running")
UI->>UI: Update UI with streamed content
end
Backend->>DB: completeStream() - Update job status to "completed"
Note over Convex: Query filters out completed jobs
Convex->>UI: Return null (no running/pending jobs)
Note over UI: BUG FIX: Previously returned early here!
UI->>UI: Check: status is "streaming" && activeStreamJob is null
UI->>UI: setStatus("ready") + cleanup
User->>User: Input re-enabled, UI ready
|
There was a problem hiding this comment.
Additional Comments (1)
-
apps/web/src/hooks/use-persistent-chat.ts, line 164-171 (link)style: Redundant code - this block is unreachable since
getActiveStreamJobonly returns jobs with "running" or "pending" status, never "completed" or "error". When a job completes, the query returnsnulland is handled above (lines 154-162).
1 file reviewed, 1 comment
Summary
getActiveStreamJobConvex query only returns jobs with "running" or "pending" statusnull- but the useEffect wasn't handling this case properlyactiveStreamJobbecomesnullRoot Cause
The useEffect in
use-persistent-chat.tshad this logic:When the backend stream completed,
getActiveStreamJobreturnednull(because it only queries running/pending jobs), but the UI status remained stuck at "streaming".Fix
Now when
activeStreamJobbecomesnullAND status is still "streaming" or "submitted", we properly callsetStatus("ready")and clean up the streaming state.Testing