Skip to content

feat(api): add throwIfAborted helper and completePrompt options regression tests - #1288

Open
easonLiangWorldedtech wants to merge 2 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:feat/abort-r1-foundation
Open

feat(api): add throwIfAborted helper and completePrompt options regression tests#1288
easonLiangWorldedtech wants to merge 2 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:feat/abort-r1-foundation

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Add the missing throwIfAborted fast-fail guard and the shared abort-detection / abort-error helpers to the abort-signal utilities (#1008 merged the merge helpers but not this guard), plus regression tests for the CompletePromptOptions interface added by #901.

  • src/api/providers/utils/abort-signal.ts:
    • new throwIfAborted(signal?) — throws Error with name = "AbortError" when the signal is already aborted
    • new shared isRequestAborted(error, signal?) — true when the caller signal fired, a native AbortError / OpenAI SDK APIUserAbortError was raised, or the message is exactly "Request was aborted."
    • new shared createAbortError(providerName) — fresh AbortError with a provider-specific message ending in "aborted", satisfying the Task.ts abort contract
    • new exported OpenAiRequestOptions type
  • src/api/providers/utils/__tests__/abort-signal.spec.ts: 3 throwIfAborted tests (undefined / not aborted / aborted) + 7 new tests for the shared helpers
  • src/api/providers/__tests__/complete-prompt-options.spec.ts: new regression spec (4 tests) for the interface surface

Part of the abort-signal series (round 1). Builds on #674, #901, #1008. Addresses #404.

Summary by CodeRabbit

  • New Features

    • Added support for detecting already-cancelled requests and returning clear, provider-specific abort errors.
    • Improved recognition of cancellation across different request and error formats.
    • Added support for combining request timeouts with cancellation signals.
  • Bug Fixes

    • Improved handling of optional request cancellation signals and consistent cancellation reporting.
  • Tests

    • Expanded coverage for cancellation scenarios, timeout options, combined settings, empty configurations, error messages, and error naming.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e06b6201-6fa7-4a3a-ace9-82c638f07e1c

📥 Commits

Reviewing files that changed from the base of the PR and between f3e807a and a0117fb.

📒 Files selected for processing (2)
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The provider API now includes abort-signal guards, detection, and error creation utilities. Tests cover abort behavior, abort error variants, and valid CompletePromptOptions combinations.

Changes

Provider API updates

Layer / File(s) Summary
Abort-signal utilities
src/api/providers/utils/abort-signal.ts
Added throwIfAborted, OpenAiRequestOptions, isRequestAborted, and createAbortError.
Abort-signal behavior coverage
src/api/providers/utils/__tests__/abort-signal.spec.ts
Added tests for signal states, native and SDK abort errors, exact abort messages, unrelated errors, and normalized error instances.
Completion option coverage
src/api/providers/__tests__/complete-prompt-options.spec.ts
Added tests for abortSignal, timeoutMs, both properties, and an empty options object.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to a0117

This PR adds abort-handling helpers and regression coverage without any identified current-head correctness or production-impact risk; it is merge-ready after normal checks and review.

Suggested reviewers: edelauna

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation and tests, but it omits the required template sections and an explicit linked issue entry. Use the repository template and add an explicit issue link, test procedure, checklist status, and documentation notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main helper addition and the related CompletePromptOptions regression tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…ssion tests

Add a fast-fail throwIfAborted guard to the shared abort-signal utilities and regression tests for the CompletePromptOptions interface (added by Zoo-Code-Org#901).
@easonLiangWorldedtech

Copy link
Copy Markdown
Contributor Author

Series follow-up flag: adopt RequestConfigBuilder for abort/timeout option construction

This PR currently builds its abort/timeout request options directly with mergeAbortSignalAndTimeout(...) from src/api/providers/utils/abort-signal.ts. That is behaviorally identical to the RequestConfigBuilder path (src/api/providers/config-builder/request-config-builder.ts, introduced in #1008) - the builder wraps the same utility. The series plan is to make the builder the canonical call site for SDK request-option construction (typed TOptions variants per SDK), so this PR is flagged for that update.

Status: series foundation - nothing to migrate here. This PR ships the abort-signal utilities (including throwIfAborted and the timeout guard) that the builder delegates to; provider-side adoption is tracked on the individual provider PRs.

@easonLiangWorldedtech

Copy link
Copy Markdown
Contributor Author

Round 1 — final status: all checks green, changed-line coverage verified

Part of the abort-signal series addressing #404 (builds on #674, #901, #1008). Foundation PR — canonical abort-signal utilities + CompletePromptOptions.

Final verified 2026-08-20: all CI checks green on this head (0 pending / 0 failed), CodeRabbit review clean, and zero new bot findings after this commit.

…o abort-signal utils

The OpenAI-family provider PRs (Zoo-Code-Org#1309, Zoo-Code-Org#1311) carry per-provider copies of the same abort-detection helper (isRequestAborted) and the same abort-error constructor (createAbortError); only the provider name in the message differs. Per the CodeRabbit maintainability finding on Zoo-Code-Org#1309 (extract the shared abort helpers into utils/abort-signal.ts), these are now shared in the foundation utility:
- isRequestAborted(error, signal?) - true when the caller signal fired, a native AbortError / OpenAI SDK APIUserAbortError was raised, or the message is exactly "Request was aborted." (exact match; a substring match would misclassify unrelated errors that merely mention aborting)
- createAbortError(providerName) - fresh error with name === "AbortError" and message "The <providerName> request was aborted", satisfying the Task.ts abort contract
- exported OpenAiRequestOptions type
7 new tests (isRequestAborted 4, createAbortError 3).
easonLiangWorldedtech added a commit to easonLiangWorldedtech/Zoo-Code that referenced this pull request Aug 21, 2026
…tudio and qwen-code

The per-provider copies of isRequestAborted / createAbortError /
OpenAiRequestOptions were extracted into src/api/providers/utils/abort-signal.ts by foundation PR Zoo-Code-Org#1288 (commit a0117fb) following the CodeRabbit maintainability finding on this PR; the providers now import the shared helpers. createAbortError takes the provider name as a parameter; provider behavior and abort messages are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants