Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/server-core/src/handlers/agent.handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,25 @@ export async function handleChatStream(
);
}

if (resumableStreamEnabled) {
options.abortSignal = undefined;
}

options.resumableStream = resumableStreamEnabled;

const resumableStreamAdapter = deps.resumableStream;
if (resumableStreamEnabled && resumableStreamAdapter && conversationId && userId) {
try {
await resumableStreamAdapter.clearActiveStream({ conversationId, agentId, userId });
} catch (error) {
logger.warn("Failed to clear active resumable stream", { error });

if (resumableStreamEnabled) {
// Preserve abortSignal so client can still cancel the LLM stream.
const clientSignal = options.abortSignal;

// Make clearActiveStream fire-and-forget — don't await it on the hot path,
// and don't let client abort block this cleanup.
if (resumableStreamAdapter && conversationId && userId) {
resumableStreamAdapter.clearActiveStream({ conversationId, agentId, userId }).catch((error) => {
logger.warn("Failed to clear active resumable stream", { error });
});
}

// Restore signal so streamText can still be cancelled by the client.
options.abortSignal = clientSignal;
}

options.resumableStream = resumableStreamEnabled;
const result = await agent.streamText(input, options);
let activeStreamId: string | null = null;

Expand Down