Skip to content

Commit 88a8ee5

Browse files
authored
fix (ai): support abort during retry waits (#7661)
## Background Abort was delayed during the delays when retrying. ## Summary * add abort signal support to delay * pass abort signal into delay from the retry function ## Related Issues Fixes #7656
1 parent 721775e commit 88a8ee5

File tree

16 files changed

+344
-47
lines changed

16 files changed

+344
-47
lines changed

‎.changeset/three-humans-report.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@ai-sdk/provider-utils': patch
3+
'ai': patch
4+
---
5+
6+
fix (ai): support abort during retry waits

‎packages/ai/src/embed/embed-many.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ Only applicable for HTTP-based providers.
9292
});
9393
}
9494

95-
const { maxRetries, retry } = prepareRetries({ maxRetries: maxRetriesArg });
95+
const { maxRetries, retry } = prepareRetries({
96+
maxRetries: maxRetriesArg,
97+
abortSignal,
98+
});
9699

97100
const baseTelemetryAttributes = getBaseTelemetryAttributes({
98101
model,

‎packages/ai/src/embed/embed.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ Only applicable for HTTP-based providers.
7979
});
8080
}
8181

82-
const { maxRetries, retry } = prepareRetries({ maxRetries: maxRetriesArg });
82+
const { maxRetries, retry } = prepareRetries({
83+
maxRetries: maxRetriesArg,
84+
abortSignal,
85+
});
8386

8487
const baseTelemetryAttributes = getBaseTelemetryAttributes({
8588
model,

‎packages/ai/src/generate-image/generate-image.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ Only applicable for HTTP-based providers.
122122
});
123123
}
124124

125-
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
125+
const { retry } = prepareRetries({
126+
maxRetries: maxRetriesArg,
127+
abortSignal,
128+
});
126129

127130
// default to 1 if the model has not specified limits on
128131
// how many images can be generated in a single call

‎packages/ai/src/generate-object/generate-object.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ Default and recommended: 'auto' (best mode for the model).
243243
enumValues,
244244
});
245245

246-
const { maxRetries, retry } = prepareRetries({ maxRetries: maxRetriesArg });
246+
const { maxRetries, retry } = prepareRetries({
247+
maxRetries: maxRetriesArg,
248+
abortSignal,
249+
});
247250

248251
const outputStrategy = getOutputStrategy({
249252
output,

‎packages/ai/src/generate-object/stream-object.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class DefaultStreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM>
427427

428428
const { maxRetries, retry } = prepareRetries({
429429
maxRetries: maxRetriesArg,
430+
abortSignal,
430431
});
431432

432433
const callSettings = prepareCallSettings(settings);

‎packages/ai/src/generate-speech/generate-speech.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ Only applicable for HTTP-based providers.
121121
});
122122
}
123123

124-
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
124+
const { retry } = prepareRetries({
125+
maxRetries: maxRetriesArg,
126+
abortSignal,
127+
});
125128

126129
const result = await retry(() =>
127130
model.doGenerate({

‎packages/ai/src/generate-text/generate-text.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ A function that attempts to repair a tool call that failed to parse.
226226
}): Promise<GenerateTextResult<TOOLS, OUTPUT>> {
227227
const model = resolveLanguageModel(modelArg);
228228
const stopConditions = asArray(stopWhen);
229-
const { maxRetries, retry } = prepareRetries({ maxRetries: maxRetriesArg });
229+
const { maxRetries, retry } = prepareRetries({
230+
maxRetries: maxRetriesArg,
231+
abortSignal,
232+
});
230233

231234
const callSettings = prepareCallSettings(settings);
232235

‎packages/ai/src/generate-text/stream-text.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT, PARTIAL_OUTPUT>
944944

945945
const { maxRetries, retry } = prepareRetries({
946946
maxRetries: maxRetriesArg,
947+
abortSignal,
947948
});
948949

949950
const tracer = getTracer(telemetry);

‎packages/ai/src/transcribe/transcribe.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ Only applicable for HTTP-based providers.
8787
});
8888
}
8989

90-
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
90+
const { retry } = prepareRetries({
91+
maxRetries: maxRetriesArg,
92+
abortSignal,
93+
});
94+
9195
const audioData =
9296
audio instanceof URL
9397
? (await download({ url: audio })).data

0 commit comments

Comments
 (0)