Skip to content

Commit 8a1e9e9

Browse files
committed
fix(sdk,chat): make isStreaming optional in reconnectToStream short-circuit
TriggerChatTransport.reconnectToStream previously returned null any time state.isStreaming was falsy, which included undefined. That meant a caller who dropped isStreaming from their ChatSession persistence (a reasonable simplification now that the server can tell the client when a session is settled via X-Session-Settled on the session.out SSE) would get null on every reconnect and the UI would never resume streaming. Tighten the check to state.isStreaming === false so only an explicit false triggers the fast-path skip. Undefined now falls through to open the SSE and let the server decide — on a settled session the server already closes the connection in ~1s via wait=0, so there is no 60s hang to worry about. Backward compatible: callers who still persist and hydrate isStreaming (true/false) keep today's behavior exactly; callers who drop the flag now get the server-authoritative path.
1 parent 4c3a039 commit 8a1e9e9

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
---
4+
5+
`TriggerChatTransport.reconnectToStream` no longer requires callers to persist an `isStreaming` flag in `ChatSession` state. Previously, any falsy `isStreaming` (including `undefined` when the flag was dropped from persistence) short-circuited reconnect to `null` and left the UI hanging on incomplete streams. Now the short-circuit only triggers on an explicit `isStreaming === false`, so callers can drop the flag entirely and let the server decide via the session's own `.out` tail. Existing callers that still persist `isStreaming` are unaffected.

packages/trigger-sdk/src/v3/chat.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,13 @@ export class TriggerChatTransport implements ChatTransport<UIMessage> {
827827
const state = this.sessions.get(options.chatId);
828828
if (!state) return null;
829829

830-
// No active stream — the last turn completed before the page refreshed.
831-
// Return null so useChat settles into "ready" state instead of hanging.
832-
if (!state.isStreaming) return null;
830+
// Fast-path: if the caller still tracks `isStreaming` in their
831+
// persisted state and knows the last turn completed, skip the SSE
832+
// open. Undefined (caller dropped the flag) falls through and the
833+
// server decides via the peek-tail-settled path — on a settled
834+
// session the SSE uses wait=0 and closes immediately, so there's
835+
// no 60s hang to worry about.
836+
if (state.isStreaming === false) return null;
833837

834838
// Deduplicate: if there's already an active stream for this chatId,
835839
// return null so the second caller no-ops.

0 commit comments

Comments
 (0)