Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Nov 15, 2025

Summary

Adds abort controller support to the OpenAI Native provider to enable proper stream cancellation when tasks are cancelled.

Changes

  • Add instance-level abort controller property for external cancellation
  • Pass abort signal to SDK and fetch requests
  • Check abort signal in streaming loops to stop yielding immediately
  • Update tests to expect abort signal parameter

Testing

  • All tests pass (32/32 for openai-native.spec.ts)
  • Follows same pattern as Bedrock provider but with instance-level controller for external cancellation support

Fixes issue where OpenAI Native provider continues yielding after task cancellation.

- Add instance-level abort controller for external cancellation support
- Pass abort signal to SDK and fetch requests
- Check abort signal in streaming loops to stop yielding immediately
- Update tests to expect abort signal parameter
- All tests pass (32/32)
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Enhancement New feature or request labels Nov 15, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 15, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. Found 1 issue that should be addressed:

  • Instance-level abort controller creates concurrency hazard - multiple concurrent requests could interfere with each other's cancellation

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

// Last top-level response id from Responses API (for troubleshooting)
private lastResponseId: string | undefined
// Abort controller for cancelling ongoing requests
private abortController?: AbortController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an instance-level abort controller creates a concurrency hazard. If multiple requests are made concurrently (which can happen in tests or when the handler is reused), they would all share the same abortController instance. This means:

  1. Starting a new request would overwrite the abort controller from a previous in-flight request
  2. Aborting one request could unintentionally abort another concurrent request
  3. The finally block of one request could clear the abort controller while another request is still using it

The Bedrock provider uses method-scoped abort controllers (see bedrock.ts:403-413) which avoids this issue. Consider either:

  • Making the abort controller method-scoped like Bedrock
  • Or if instance-level cancellation is truly needed, implement proper concurrency control (e.g., tracking multiple in-flight requests)

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 15, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 15, 2025
@mrubens mrubens merged commit 44b96f9 into main Nov 15, 2025
24 checks passed
@mrubens mrubens deleted the fix/openai-native-abort-controller branch November 15, 2025 00:38
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 15, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 15, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 17, 2025