Skip to content

fix(api): pass abortSignal to streaming API calls for all providers (#404)#1

Open
easonLiangWorldedtech wants to merge 2 commits into
mainfrom
fix/abort-signal-openai-compatible
Open

fix(api): pass abortSignal to streaming API calls for all providers (#404)#1
easonLiangWorldedtech wants to merge 2 commits into
mainfrom
fix/abort-signal-openai-compatible

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes Zoo-Code-Org#404 — When the user clicks Stop during streaming, the HTTP request to the provider continues running because the abort signal wasn't being passed through. This wastes API tokens/compute on the provider side.

Changes

Added { signal: metadata?.abortSignal } to streaming .chat.completions.create() calls in 13 providers:

  • lm-studio.ts, openai.ts, deepseek.ts
  • base-openai-compatible-provider.ts (merged into requestOptions)
  • lite-llm.ts, mimo.ts, opencode-go.ts, openrouter.ts, qwen-code.ts, requesty.ts, unbound.ts, vercel-ai-gateway.ts, zai.ts

Also added abortSignal?: AbortSignal to ApiHandlerCreateMessageMetadata interface and wired it through Task.ts's AbortController.

Test Coverage

  • task-abort-signal-passing.spec.ts — Comprehensive tests for abort signal flow
  • openai-compatible-abort-signal.spec.ts — Provider-level abort signal verification

p.s All code generated by AI, this is the testing video(I only tested LM Studio)

2026-06-01.230625.mp4

@easonLiangWorldedtech easonLiangWorldedtech force-pushed the fix/abort-signal-openai-compatible branch 4 times, most recently from 277e296 to c674eec Compare June 9, 2026 20:25
@easonLiangWorldedtech easonLiangWorldedtech force-pushed the fix/abort-signal-openai-compatible branch 5 times, most recently from 79dd3fb to c5a6f53 Compare June 13, 2026 13:09
@easonLiangWorldedtech easonLiangWorldedtech force-pushed the fix/abort-signal-openai-compatible branch 3 times, most recently from fab4533 to b1c1c4f Compare June 13, 2026 14:02
@easonLiangWorldedtech easonLiangWorldedtech force-pushed the fix/abort-signal-openai-compatible branch 5 times, most recently from 19d668d to b1a2469 Compare June 13, 2026 16:32
…ode-Org#434)

- Add AbortController support to openai-compatible provider
- Pass abort signal through Task execution chain
- Add comprehensive tests for abort signal behavior across all providers
@easonLiangWorldedtech easonLiangWorldedtech force-pushed the fix/abort-signal-openai-compatible branch 2 times, most recently from cdb9a74 to cdfbc4b Compare June 13, 2026 17:34
Previously, these three providers used their own AbortControllers but did not
listen to the external abort signal from the Task execution chain. This meant
clicking stop would not immediately cancel requests to these providers. Now all
providers consistently respect the user's stop action.

Also add optional metadata parameter with abortSignal to completePrompt methods
across 22 provider implementations:
- Anthropic, Anthropic Vertex, Base OpenAI Compatible
- Gemini/Vertex, LiteLLM, LM Studio, MiniMax, Mistral
- Native Ollama, OpenAI, OpenAI Compatible, OpenRouter
- Qwen Code, Requesty, Unbound, Vercel AI Gateway
- Opencode Go, xAI, Zoo Gateway, VSCode LM, Poe, Bedrock

Add abortSignal tests for all modified providers.

- Add comment explaining Mistral completePrompt does not support non-streaming abort (Mistral SDK limitation)
@easonLiangWorldedtech easonLiangWorldedtech force-pushed the fix/abort-signal-openai-compatible branch from cdfbc4b to 32de395 Compare June 13, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Stop does not work on OpenAI Compatible API Provider

2 participants