Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e61feb1
feat(api): add throwIfAborted helper and completePrompt options regre…
easonliang28 Aug 19, 2026
4497268
feat(api): abort-signal wiring for lm-studio and qwen-code (round 2)
easonliang28 Aug 20, 2026
9d2942f
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Aug 20, 2026
e272e4d
fix(api): align lm-studio specs with abort-signal call shape and addr…
easonLiangWorldedtech Aug 20, 2026
abd9827
test(api): cover LM Studio reasoning_content delta in abort-signal spec
easonLiangWorldedtech Aug 20, 2026
6e1e1af
test(api): cover qwen-code degenerate stream shapes for full branch c…
easonLiangWorldedtech Aug 20, 2026
a0117fb
feat(api): add shared isRequestAborted and createAbortError helpers t…
easonLiangWorldedtech Aug 21, 2026
56b10d5
Merge branch 'feat/abort-r1-foundation' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Aug 21, 2026
e57e88b
refactor(api): use shared abort helpers from foundation utils in lm-s…
easonLiangWorldedtech Aug 21, 2026
c235479
fix(api): normalize aborts during qwen-code 401 retry and lm-studio t…
easonLiangWorldedtech Aug 21, 2026
5ac4e51
test(api): cover the non-abort path of the qwen-code 401 retry
easonLiangWorldedtech Aug 21, 2026
7f26495
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Sep 1, 2026
5e3a575
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Sep 2, 2026
37ef142
Merge upstream/main (79cd12f2c) into feat/abort-r2-lmstudio-qwen
easonliang28 Sep 3, 2026
78345cf
fix(ci): declare vitest as a root devDependency so the mutation gate…
easonliang28 Sep 3, 2026
6db3e70
test(api): strengthen focused tests for the changed-code mutation gate
easonliang28 Sep 3, 2026
0df30b9
test(api): harden abort-wiring tests against hanging mutants
easonliang28 Sep 3, 2026
87beca0
test(api): exclude proven-equivalent Stryker mutants from the changed…
easonliang28 Sep 3, 2026
3cd0261
test(api): exclude unobservable inner-abort provider-name literals fr…
easonliang28 Sep 3, 2026
8b154df
fix(api): settle lm-studio and qwen-code wait points against the abor…
easonliang28 Sep 5, 2026
00e369f
Merge remote-tracking branch 'upstream/main' into feat/abort-r2-lmstu…
easonliang28 Sep 5, 2026
2f8aab0
test(api): add abort kill-tests for lm-studio and qwen-code
easonliang28 Sep 5, 2026
279f093
Merge branch main into feat/abort-r2-lmstudio-qwen
easonliang28 Sep 6, 2026
1a0877a
Adapt qwen-code spec to per-scope NativeToolCallParser API
easonliang28 Sep 6, 2026
ab38513
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Sep 28, 2026
a257beb
fix(deps): repair pnpm-lock.yaml broken by merge conflict resolution
easonliang28 Sep 28, 2026
b80175a
fix(deps): align root vitest with the 4.1.11 security bump
easonliang28 Sep 28, 2026
dc2d41e
fix(api): race the Qwen 401 refresh wait against the abort signal and…
Sep 28, 2026
1c277ef
fix(qwen-code): keep in-memory credentials current after a cancelled …
Sep 29, 2026
7d2ba9f
Merge remote-tracking branch 'upstream/main' into feat/abort-r2-lmstu…
Oct 2, 2026
4c44112
chore: trigger label reconcile (CI green + CR approved, cron stalled)
Oct 2, 2026
a2ff86d
Merge commit 'refs/shapes/upstream-main' into feat/abort-r2-lmstudio-…
Oct 2, 2026
3dcee63
Merge upstream main (3859e5dd8) into feat/abort-r2-lmstudio-qwen
Oct 4, 2026
c26a94c
Assert the abort bridge while the request is in flight
Oct 4, 2026
f288d0a
Re-trigger review at the current head
Oct 4, 2026
f3a73e1
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Oct 5, 2026
081b314
Merge upstream main (285f6687a) into feat/abort-r2-lmstudio-qwen
easonliang28 Oct 13, 2026
e5c3ab4
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Oct 13, 2026
9c7faba
Address pre-merge checks: detach settleOnAbort's listener on abort; p…
easonliang28 Oct 13, 2026
3b998a5
Address review: pin listener removal by function reference
easonliang28 Oct 13, 2026
dc09b59
Address pre-merge warnings: guard settleOnAbort's early return; share…
easonliang28 Oct 13, 2026
f621443
Address review: cover LM Studio early consumer termination
easonliang28 Oct 13, 2026
9041eb1
Address review: pin no premature abort before early termination
easonliang28 Oct 14, 2026
411fe4d
Merge upstream/main (58341d882) into feat/abort-r2-lmstudio-qwen
easonliang28 Oct 14, 2026
1c83959
chore(api): remove Stryker suppression comments from touched files
easonliang28 Oct 14, 2026
bef1524
fix(api): reject non-finite and cap overflowing mergeAbortSignalAndTi…
easonliang28 Oct 14, 2026
b7dafe0
fix(api): round fractional timeouts before AbortSignal.timeout
easonliang28 Oct 14, 2026
fc35d1b
test(api): assert the rounded delay reaching AbortSignal.timeout
easonliang28 Oct 14, 2026
4f66ae5
Merge remote-tracking branch 'upstream/main' into feat/abort-r2-lmstu…
easonLiangWorldedtech Oct 22, 2026
f6b0454
fix(api): restore the OpenAiRequestOptions type the abort wiring imports
easonLiangWorldedtech Oct 22, 2026
235257a
fix(api): report an elapsed per-request timeout as TimeoutError
easonLiangWorldedtech Oct 22, 2026
2f014e4
Merge remote-tracking branch 'upstream/main' into feat/abort-r2-lmstu…
easonLiangWorldedtech Oct 26, 2026
efccacd
refactor(providers): share the timeout-vs-abort helpers and dedupe th…
easonLiangWorldedtech Oct 26, 2026
760c42a
fix(abort-signal): classify timeout aborts by the merged signal reason
easonLiangWorldedtech Oct 26, 2026
eac598e
chore(lm-studio): drop the unused caller signal parameter
easonLiangWorldedtech Oct 26, 2026
cf4eb86
Merge branch 'main' into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Oct 29, 2026
cfe27c6
test(lmstudio): wait for the request instead of a fixed sleep
easonLiangWorldedtech Nov 2, 2026
be0b396
fix(api): settle qwen-code streams that end quietly on abort
easonLiangWorldedtech Nov 3, 2026
afd49f6
Merge upstream/main into feat/abort-r2-lmstudio-qwen
easonLiangWorldedtech Nov 3, 2026
356d6d9
test(api): poll instead of assuming await depth, and exercise the mer…
easonLiangWorldedtech Nov 3, 2026
3933b64
test(api): ban setTimeout in provider specs, use waitFor and shared h…
edelauna Nov 4, 2026
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
Prev Previous commit
Next Next commit
fix(api): normalize aborts during qwen-code 401 retry and lm-studio t…
…oken counting

CodeRabbit follow-ups on the abort-signal series: an abort landing while the qwen-code 401 retry request is in flight escaped callApiWithRetry as the raw SDK abort error instead of the normalized 'The Qwen Code request was aborted'; the retried apiCall now goes through the same isRequestAborted normalization. In lm-studio createMessage, an abort landing while input token counting is pending was silently dropped (a listener added to an already-aborted signal never fires), so the aborted state is bridged into the request-local controller and throwIfAborted fast-fails before the request is issued. Regression tests cover both paths.
  • Loading branch information
easonLiangWorldedtech committed Aug 21, 2026
commit c235479b2cabe0d363182e34a011a2082da287e7
37 changes: 37 additions & 0 deletions src/api/providers/__tests__/lmstudio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,43 @@ describe("LmStudioHandler", () => {
"Please check the LM Studio developer logs to debug what went wrong. You may need to load the model with a larger context length to work with Zoo Code's prompts.",
)
})

it("should not issue the request when the caller aborts while input token counting is pending", async () => {
const controller = new AbortController()
let releaseCount!: () => void
const countGate = new Promise<void>((resolve) => {
releaseCount = resolve
})
const countSpy = vi.spyOn(handler, "countTokens").mockImplementation(async () => {
await countGate
return 10
})

const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task-id",
abortSignal: controller.signal,
})
const pending = collectStream(stream).catch((error: unknown) => error)

// Let the generator reach the token count, then abort while it is pending.
const start = Date.now()
while (countSpy.mock.calls.length === 0) {
if (Date.now() - start > 5000) {
throw new Error("timed out waiting for the token count")
}
await new Promise((resolve) => setTimeout(resolve, 5))
}
controller.abort()
releaseCount()

const caught = (await pending) as Error
Comment thread
easonLiangWorldedtech marked this conversation as resolved.
Resolved
countSpy.mockRestore()

expect(caught).toBeInstanceOf(Error)
expect(caught.name).toBe("AbortError")
expect(caught.message).toBe("The LM Studio request was aborted")
expect(mockCreate).not.toHaveBeenCalled()
})
})

describe("completePrompt", () => {
Expand Down
49 changes: 49 additions & 0 deletions src/api/providers/__tests__/qwen-code-native-tools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,31 @@ describe("QwenCodeHandler Native Tools", () => {
expect(mockCreate).toHaveBeenCalledTimes(1) // the retried request was never sent
expect(fetchMock).toHaveBeenCalledTimes(1)
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it("should normalize an abort error from the 401 retry instead of exposing the raw SDK error", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(tokenResponse()))
const external = new AbortController()
mockCreate
.mockRejectedValueOnce(unauthorizedError())
.mockImplementationOnce((_params: unknown, opts?: { signal?: AbortSignal }) => {
external.abort() // Stop pressed while the retried request is in flight
return Promise.reject(sdkAbortError())
})

const stream = handler.createMessage("test prompt", [], { taskId: "t1", abortSignal: external.signal })
let caught: unknown
try {
await collectStream(stream)
} catch (error) {
caught = error
}

expect(caught).toBeInstanceOf(Error)
expect((caught as Error).name).toBe("AbortError")
expect((caught as Error).message).toBe("The Qwen Code request was aborted")
expect((caught as Error).message).not.toBe("Request was aborted.") // not the raw SDK error
expect(mockCreate).toHaveBeenCalledTimes(2) // first attempt 401, then the aborted retry
})
})

describe("completePrompt", () => {
Expand Down Expand Up @@ -790,6 +815,30 @@ describe("QwenCodeHandler Native Tools", () => {
expect((caught as Error).name).toBe("AbortError")
expect((caught as Error).message).toMatch(/aborted$/)
})

it("should normalize an abort error from the 401 retry instead of exposing the raw SDK error", async () => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(tokenResponse()))
const external = new AbortController()
mockCreate
.mockRejectedValueOnce(unauthorizedError())
.mockImplementationOnce((_params: unknown, opts?: { signal?: AbortSignal }) => {
external.abort() // Stop pressed while the retried request is in flight
return Promise.reject(sdkAbortError())
})

let caught: unknown
try {
await handler.completePrompt("hi", { abortSignal: external.signal })
} catch (error) {
caught = error
}

expect(caught).toBeInstanceOf(Error)
expect((caught as Error).name).toBe("AbortError")
expect((caught as Error).message).toBe("The Qwen Code request was aborted")
expect((caught as Error).message).not.toBe("Request was aborted.") // not the raw SDK error
expect(mockCreate).toHaveBeenCalledTimes(2) // first attempt 401, then the aborted retry
})
})
})
})
12 changes: 12 additions & 0 deletions src/api/providers/lm-studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
const externalSignal = metadata?.abortSignal
if (externalSignal) {
externalSignal.addEventListener("abort", onExternalAbort)
// An abort can land while the input token count above is still
// pending: a listener registered after the signal already aborted
// never fires, so bridge the aborted state into the request-local
// controller.
if (externalSignal.aborted) {
requestController.abort()
}
Comment thread
easonLiangWorldedtech marked this conversation as resolved.
Resolved
}

try {
Expand All @@ -131,6 +138,11 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
.setOption("signal", requestController.signal)
.build()

// Fast-fail if the caller aborted while countTokens() above was
// pending — the request must not be issued once the request-local
// signal has aborted.
throwIfAborted(requestController.signal)

let results
try {
results = await this.client.chat.completions.create(params, createOptions)
Expand Down
13 changes: 12 additions & 1 deletion src/api/providers/qwen-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,18 @@ export class QwenCodeHandler extends BaseProvider implements SingleCompletionHan
const client = this.ensureClient()
client.apiKey = this.credentials.access_token
client.baseURL = this.getBaseUrl(this.credentials)
return await apiCall()
// A stop can also land while the retried request itself is in
// flight; that rejection must go through the same abort
// normalization as the first attempt instead of escaping as the
// raw SDK abort error.
try {
return await apiCall()
} catch (retryError) {
if (isRequestAborted(retryError, externalSignal)) {
throw createAbortError("Qwen Code")
}
throw retryError
}
} else {
throw error
}
Expand Down
Loading