Skip to content

Commit c02115a

Browse files
committed
fix(sdk): request the caught-up settle on AgentChat.reconnect()
The server-to-server AgentChat client's reconnect() now sends X-Peek-Settled, so resuming an .out that is already at a turn-complete tail closes promptly instead of holding the full SSE long-poll window. This matches the browser transport's reconnectToStream and gives server-to-server consumers the same fast tail-close. The active send-message path is unchanged (no peek, so it never races a newly-triggered turn's first chunk).
1 parent f202ccc commit c02115a

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

.changeset/chat-session-caught-up-resume.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"@trigger.dev/sdk": patch
44
---
55

6-
Chat sessions now close a resumed stream as soon as it has caught up to the latest output, instead of holding the connection open for the full long-poll window. Reloading or reconnecting to an idle chat settles faster.
6+
Chat sessions now close a resumed stream as soon as it has caught up to the latest output, instead of holding the connection open for the full long-poll window. Reloading or reconnecting to an idle chat settles faster. This applies to the server-to-server `AgentChat` client's `reconnect()` too, not just the browser transport.

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,18 @@ export class AgentChat<TAgent = unknown> {
576576
}
577577
}
578578

579-
/** Reconnect to the response stream (e.g. after a disconnect). */
579+
/**
580+
* Reconnect to the response stream (e.g. after a disconnect). Requests the
581+
* caught-up settle probe (`X-Peek-Settled`) so a resumed stream already at a
582+
* turn-complete tail closes promptly instead of holding the full SSE window,
583+
* mirroring the browser transport's `reconnectToStream`.
584+
*/
580585
async reconnect(abortSignal?: AbortSignal): Promise<ReadableStream<UIMessageChunk> | null> {
581586
if (!this.state.started) return null;
582-
return this.subscribeToSessionStream(abortSignal, { sendStopOnAbort: false });
587+
return this.subscribeToSessionStream(abortSignal, {
588+
sendStopOnAbort: false,
589+
peekSettled: true,
590+
});
583591
}
584592

585593
// ─── Private ───────────────────────────────────────────────────
@@ -681,7 +689,7 @@ export class AgentChat<TAgent = unknown> {
681689

682690
private subscribeToSessionStream(
683691
abortSignal: AbortSignal | undefined,
684-
options?: { sendStopOnAbort?: boolean }
692+
options?: { sendStopOnAbort?: boolean; peekSettled?: boolean }
685693
): ReadableStream<UIMessageChunk> {
686694
const state = this.state;
687695
const accessToken = apiClientManager.accessToken ?? "";
@@ -743,6 +751,7 @@ export class AgentChat<TAgent = unknown> {
743751
...(apiClientManager.branchName
744752
? { "x-trigger-branch": apiClientManager.branchName }
745753
: {}),
754+
...(options?.peekSettled ? { "X-Peek-Settled": "1" } : {}),
746755
},
747756
signal: combinedSignal,
748757
timeoutInSeconds: this.streamTimeoutSeconds,

0 commit comments

Comments
 (0)