fix: reset message stream when conversation clears#268
Conversation
|
Submitted for the active Ugig testing/fix gig: https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e Scope: real message-stream state bug, issue #267, focused fix plus regression test and validation listed in the PR body. |
Greptile SummaryThis PR fixes stale UI state when a conversation is cleared or switched by replacing per-state boolean/string tracking with an integer stream-ID scheme. Each effect run gets a unique
Confidence Score: 5/5Safe to merge — the stream-ID scheme correctly isolates all connection, error, and typing state per effect run, and the three new regression tests directly exercise the cleared-conversation and same-ID-reconnect paths. The staleness fix is logically sound: every handler (onopen, onmessage, onerror) guards against stale streams by comparing the captured streamId to streamIdRef.current, and the polling effect captures both a cancelled flag and the stream ID to discard in-flight fetches after cleanup. All three derived values resolve correctly across the null to conv-123 and conv-123 to null to conv-123 transitions that were the original bug, and the new tests verify each scenario end-to-end. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Component
participant H as useMessageStream
participant ES as EventSource
participant API as /typing API
C->>H: "conversationId=conv-123"
H->>H: "streamIdRef++ streamId=1"
H->>ES: new EventSource
ES-->>H: onopen
H->>H: "setConnectedStreamId(1), isConnected=true"
H->>API: "start polling streamId=1"
C->>H: "conversationId=null"
H->>ES: close
H->>H: "streamIdRef 1->2->3, setConnectedStreamId(null)"
H->>H: "isConnected=false, cancel poll"
C->>H: "conversationId=conv-123"
H->>H: "streamIdRef 3->4, isConnected=false"
H->>ES: new EventSource
ES-->>H: "onopen streamIdRef===4"
H->>H: "setConnectedStreamId(4), isConnected=true"
H->>API: "start polling streamId=4"
Reviews (2): Last reviewed commit: "fix: reset stale stream state before rec..." | Re-trigger Greptile |
|
Pushed a follow-up fix for the Greptile P1: reset stale connection/error/typing state whenever a new stream attempt starts, and key late SSE/poll updates by stream id so a null -> same conversation reconnect cannot report connected or show stale errors before onopen.\n\nValidation:\n- pnpm vitest run src/hooks/useMessageStream.test.ts -> 13 passed\n- pnpm type-check -> passed |
Summary
EventSourceref during cleanup and ignores late typing-poll completions after effect cleanupconversationIdafter an SSE connection has openedValidation
PNPM_CONFIG_IGNORE_SCRIPTS=true pnpm exec vitest run src/hooks/useMessageStream.test.ts-> 11 passedPNPM_CONFIG_IGNORE_SCRIPTS=true pnpm exec eslint src/hooks/useMessageStream.ts src/hooks/useMessageStream.test.ts-> 0 errors, 0 warningsPNPM_CONFIG_IGNORE_SCRIPTS=true pnpm exec tsc --noEmit-> passedgit diff --check-> passed