Skip to content

Commit b3c0116

Browse files
fix(api): attribute poe timeouts only to the timeout this method configured
The reviewer reads abortedByTimeout() as reporting a timeout whenever the merged signal's reason is named TimeoutError, and AbortSignal.timeout() produces exactly that reason: a caller that passes a timeout signal without timeoutMs was reported as this provider timing out, which is the wrong contract for a caller-side abort. Classification now requires a timeout this method actually configured (hasUsableTimeout(options?.timeoutMs)) on top of the aborted flag and the reason name, so a caller-only timeout abort lands on the AbortError contract. Where a caller timeout signal and our own timeoutMs both exist the two reasons are indistinguishable and the timeout reading still wins, matching the series contract; that residual is stated in the comment at the classification site. Control measured in src: the new case 'reports a caller timeout abort as AbortError when no per-request timeout is configured' is red without the added condition (1 failed of 44) and green with it (44 passed); the suite at HEAD was 43 passed, so the delta is exactly the new case. Verified on this head: tsc -p tsconfig.json --noEmit clean, eslint --max-warnings=0 clean on the two touched files, prettier --check clean, poe spec 44/44 with --no-file-parallelism. src/eslint-suppressions.json untouched; no changeset, no CHANGELOG.
1 parent 0a23408 commit b3c0116

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎src/api/providers/__tests__/poe.spec.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,25 @@ describe("PoeHandler", () => {
863863
expect(callArgs.abortSignal.aborted).toBe(true)
864864
})
865865

866+
it("reports a caller timeout abort as AbortError when no per-request timeout is configured", async () => {
867+
// A caller that passes AbortSignal.timeout(ms) aborts with a reason whose name is
868+
// "TimeoutError". With no timeoutMs of our own this method created no timeout
869+
// source, so that abort must stay on the caller-abort contract (AbortError) and
870+
// not be reported as this provider timing out. Red without the hasUsableTimeout
871+
// condition in abortedByTimeout().
872+
const handler = new PoeHandler({ poeApiKey: "key", apiModelId: "openai/gpt-4o" })
873+
const controller = new AbortController()
874+
mockGenerateText.mockImplementationOnce(async (args: { abortSignal?: AbortSignal }) => {
875+
await new Promise<void>((resolve) => {
876+
args.abortSignal?.addEventListener("abort", () => resolve(), { once: true })
877+
})
878+
return { text: "late result" }
879+
})
880+
const promise = handler.completePrompt("test prompt", { abortSignal: controller.signal })
881+
controller.abort(new DOMException("caller deadline exceeded", "TimeoutError"))
882+
await expect(promise).rejects.toMatchObject({ name: "AbortError" })
883+
})
884+
866885
it("does not apply a timeout when the caller supplies no options", async () => {
867886
const handler = new PoeHandler({ poeApiKey: "key", apiModelId: "openai/gpt-4o" })
868887
mockGenerateText.mockResolvedValueOnce({ text: "response" })

‎src/api/providers/poe.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ import type {
3333
ModelCacheScope,
3434
} from "../index"
3535
import { getModels, getModelsFromCache } from "./fetchers/modelCache"
36-
import { bridgeExternalAbortSignal, createAbortError, mergeAbortSignalAndTimeout } from "./utils/abort-signal"
36+
import {
37+
bridgeExternalAbortSignal,
38+
createAbortError,
39+
hasUsableTimeout,
40+
mergeAbortSignalAndTimeout,
41+
} from "./utils/abort-signal"
3742
import { createTimeoutError } from "./utils/request-timeout"
3843
import { getPoeModels } from "./fetchers/poe"
3944

@@ -249,8 +254,16 @@ export class PoeHandler extends BaseProvider implements SingleCompletionHandler
249254
// The merged signal keeps the FIRST abort reason. A timeout that fires before the caller
250255
// aborts must stay a TimeoutError even if the caller signal aborts before the late result
251256
// settles, so classify by the signal's reason rather than the caller signal's later state.
257+
// A reason named TimeoutError is not proof of our own deadline: AbortSignal.timeout()
258+
// produces exactly that reason, so a caller that passes a timeout signal without
259+
// timeoutMs would otherwise be reported as this provider timing out. The reading is
260+
// sound only when this method configured a timeout, so a caller-only timeout abort
261+
// stays on the AbortError contract. Where a caller timeout signal and our own
262+
// timeoutMs both exist the two reasons are indistinguishable and the timeout reading
263+
// wins, which is the series contract.
252264
const abortedByTimeout = () =>
253265
Boolean(mergedAbortSignal?.aborted) &&
266+
hasUsableTimeout(options?.timeoutMs) &&
254267
(mergedAbortSignal?.reason as { name?: string } | undefined)?.name === "TimeoutError"
255268
let text: string
256269
try {

0 commit comments

Comments
 (0)