Skip to content

Commit fb6d433

Browse files
committed
fix: avoid retrying aborted LLM requests during shutdown
Treat aborted inference LLM streams as expected cancellation so session shutdown does not reclassify them as retryable failures and trigger noisy retries.
1 parent 27c091d commit fb6d433

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

agents/src/inference/llm.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ export class LLMStream extends llm.LLMStream {
354354
},
355355
);
356356

357+
if (this.abortController.signal.aborted) {
358+
return;
359+
}
360+
357361
for await (const chunk of stream) {
358362
if (this.abortController.signal.aborted) {
359363
break;
@@ -382,6 +386,10 @@ export class LLMStream extends llm.LLMStream {
382386
}
383387
}
384388
} catch (error) {
389+
if (this.abortController.signal.aborted) {
390+
return;
391+
}
392+
385393
if (error instanceof OpenAI.APIConnectionTimeoutError) {
386394
throw new APITimeoutError({ options: { retryable } });
387395
} else if (error instanceof OpenAI.APIError) {

0 commit comments

Comments
 (0)