Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(cloud): stop ends the walk, and the proxy stops opening what it just cancelled

David3fd86727b4d7
diff --git a/src/api/__tests__/provider-think-off.test.ts b/src/api/__tests__/provider-think-off.test.ts
index 98074291..c3838884 100644
--- a/src/api/__tests__/provider-think-off.test.ts
+++ b/src/api/__tests__/provider-think-off.test.ts
@@ -257,3 +257,39 @@ describe('a 400 for an unrelated reason teaches nothing', () => {
expect(spy).toHaveBeenCalledTimes(1)
})
})
+
+describe('stop ends the walk', () => {
+ // P6 from the review. The claim as filed does not hold for the real fetch:
+ // an aborted signal makes it reject, so no rung reaches the network. It does
+ // hold for localFetchStream, whose proxy path used to call cancel on a stream
+ // id it had not opened yet and then start the request anyway. The mock here
+ // stands in for exactly that kind of fetcher, one that ignores the signal.
+ it('a rung is not posted once the user has pressed stop', async () => {
+ const ac = new AbortController()
+ const spy = vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
+ // Deaf to the signal on purpose, like the proxy path was.
+ ac.abort()
+ return refuse()
+ })
+ await expect(
+ new OpenAIProvider(makeConfig()).chatWithTools(
+ 'm-stopped', [{ role: 'user', content: 'hi' }], [], { thinking: false, signal: ac.signal },
+ ),
+ ).rejects.toBeTruthy()
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
+
+ it('and nothing is learned from a walk the user cut short', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ const ac = new AbortController()
+ vi.spyOn(globalThis, 'fetch').mockImplementation(async () => { ac.abort(); return refuse() })
+ await expect(
+ provider.chatWithTools('m-cut', [{ role: 'user', content: 'hi' }], [], { thinking: false, signal: ac.signal }),
+ ).rejects.toBeTruthy()
+ vi.restoreAllMocks()
+
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-cut', [{ role: 'user', content: 'hi' }], [], { thinking: false })
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('none')
+ })
+})
diff --git a/src/api/backend.ts b/src/api/backend.ts
index 564973b0..98a74979 100644
--- a/src/api/backend.ts
+++ b/src/api/backend.ts
@@ -304,14 +304,16 @@ async function proxyStreamChunked(url: string, method: string, body?: string, he
const streamId =
(globalThis.crypto as Crypto | undefined)?.randomUUID?.() ??
`s_${Date.now()}_${Math.random().toString(36).slice(2)}`;
+ // Already aborted before we start: cancelling a stream id that has never
+ // been opened cancels nothing, and the old code then opened it anyway. On the
+ // Tauri loopback path that is a real upstream request fired after the user
+ // pressed Stop (review 2026-08-14). Refuse first, cancel nothing.
+ if (signal?.aborted) throw new DOMException('Aborted', 'AbortError');
const cancelUpstream = () => { void invoke("cancel_proxy_stream", { streamId }).catch(() => { /* best-effort */ }); };
let onAbort: (() => void) | null = null;
if (signal) {
- if (signal.aborted) cancelUpstream();
- else {
- onAbort = () => cancelUpstream();
- signal.addEventListener("abort", onAbort, { once: true });
- }
+ onAbort = () => cancelUpstream();
+ signal.addEventListener("abort", onAbort, { once: true });
}
const detachAbort = () => { if (signal && onAbort) { signal.removeEventListener("abort", onAbort); onAbort = null; } };
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.ts
index 33c0c318..a1362cbf 100644
--- a/src/api/providers/openai-provider.ts
+++ b/src/api/providers/openai-provider.ts
@@ -294,19 +294,24 @@ export class OpenAIProvider implements ProviderClient {
const lane: 'on' | 'off' | undefined =
asked === undefined ? undefined : asked === 'high' ? 'on' : 'off'
+ // Stop ends the walk. The real fetch rejects on an aborted signal on its
+ // own, but localFetchStream's proxy path used to fire the request anyway,
+ // so the ladder could keep spending steps after the user was done.
+ const stopped = () => signal?.aborted === true
+
let res = await this.sendOrExplain(post)
- if (refused(res) && body.reasoning_effort === 'none') {
+ if (!stopped() && refused(res) && body.reasoning_effort === 'none') {
body.reasoning_effort = 'minimal'
res = await post()
}
- if (refused(res) && 'stream_options' in body) {
+ if (!stopped() && refused(res) && 'stream_options' in body) {
delete body.stream_options
res = await post()
}
- if (refused(res) && 'reasoning_effort' in body) {
+ if (!stopped() && refused(res) && 'reasoning_effort' in body) {
delete body.reasoning_effort
res = await post()
}