Skip to content

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

Open
easonLiangWorldedtech wants to merge 3 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 3 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.

@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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: c4b62b0e-30c9-453d-87ae-e71b1e1f2951

📥 Commits

Reviewing files that changed from the base of the PR and between 5e8fcc8 and 74ecee0.

📒 Files selected for processing (3)
  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • 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.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: platform-unit-test (windows-latest)
  • GitHub Check: platform-unit-test (ubuntu-latest)
  • GitHub Check: e2e-mock
🧰 Additional context used
📓 Path-based instructions (8)
Treat model, provider, MCP, path, command, and tool data as untrusted.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts
Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts
Verify extension/webview contracts, cancellation and error propagation, VS Code lifecycle correctness, and behavior under retries and partial failure.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts
Act as an adversarial second-opinion reviewer.

⚙️ CodeRabbit configuration file

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts
Add focused tests for UI binding and save behavior, persistence or normalization, and the value returned by `getStateToPostToWebview()`, including true and false/unset cases when defaults could hide omissions.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
Fix lint violations in new TypeScript code instead of suppressing them.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts
After editing a file, run ESLint with pruning and zero warnings for that relative file, and confirm its suppression count did not increase.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/utils/__tests__/abort-signal.spec.ts
  • src/api/providers/utils/abort-signal.ts
🔇 Additional comments (3)
src/api/providers/utils/abort-signal.ts (1)

38-54: LGTM!

Also applies to: 56-65, 67-82, 84-95

src/api/providers/utils/__tests__/abort-signal.spec.ts (1)

1-7: LGTM!

Also applies to: 108-134, 136-169, 171-187

src/api/providers/__tests__/complete-prompt-options.spec.ts (1)

8-8: 📐 Maintainability & Code Quality

No type-checking gap exists. src/package.json runs tsc --noEmit, and src/tsconfig.json includes the entire src directory. This spec is covered by the package type-check.


📝 Summary

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 request cancellation signals alongside timeout options.
  • Bug Fixes

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

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

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 74ece

This PR adds localized cancellation helpers and regression coverage without changing external integrations, permissions, persistent state, or deployment behavior. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Regression Evidence ⚠️ Warning The new exported OpenAiRequestOptions type lacks focused coverage. The PR adds OpenAiRequestOptions { signal?: AbortSignal } in src/api/providers/utils/abort-signal.ts (lines 63-65), but reposit… Add a compile-time focused test for OpenAiRequestOptions. Import the type in the abort-signal utility spec, assign both { signal: controller.signal } and {}, and assert the signal and unset value. Keep the existing helper and `Complet…
✅ Passed checks (6 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 3 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.
Trust And Persistence Invariants ✅ Passed PASS. The PR changes only abort-signal helpers and tests. throwIfAborted creates and throws an error, isRequestAborted reads abort metadata, createAbortError formats an error message, and `OpenA…
Title check ✅ Passed The title clearly identifies the main changes: adding the throwIfAborted helper and adding CompletePromptOptions regression tests.
Description check ✅ Passed The description clearly explains the implementation, linked issue context, scope, and added tests. It does not reproduce the template sections, provide detailed test execution steps, or include the pr…
Full details: Regression Evidence

Explanation

The new exported OpenAiRequestOptions type lacks focused coverage. The PR adds OpenAiRequestOptions { signal?: AbortSignal } in src/api/providers/utils/abort-signal.ts (lines 63-65), but repository-wide search finds no test or consumer that uses this named type. The added utility tests cover throwIfAborted, isRequestAborted, and createAbortError, and the separate spec covers CompletePromptOptions.

Resolution

Add a compile-time focused test for OpenAiRequestOptions. Import the type in the abort-signal utility spec, assign both { signal: controller.signal } and {}, and assert the signal and unset value. Keep the existing helper and CompletePromptOptions coverage.

Full details: Trust And Persistence Invariants

Explanation

PASS. The PR changes only abort-signal helpers and tests. throwIfAborted creates and throws an error, isRequestAborted reads abort metadata, createAbortError formats an error message, and OpenAiRequestOptions is type-only. The changed paths contain no secret or PII handling, input execution, approval or allowlist logic, persistence writes, missing awaits, or new resource allocation. The PR delta versus the main parent is limited to the three summarized files.

Full details: Description check

Explanation

The description clearly explains the implementation, linked issue context, scope, and added tests. It does not reproduce the template sections, provide detailed test execution steps, or include the pre-submission checklist, but the core required information is present.

  • Fix all pre-merge checks with AI
✨ 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.
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review process

Thanks for contributing. This comment tracks the review sequence and the next action.

  1. Required CI checks pass.
  2. The workflow starts CodeRabbit automatically.
  3. For eligible human-authored PRs, CodeRabbit reviews and approves the latest commit.
  4. A human maintainer reviews and approves after CodeRabbit.

Current step: Ready for human maintainer review and approval.

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Aug 29, 2026
@easonLiangWorldedtech

Copy link
Copy Markdown
Contributor Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved. Approval is disabled; enable reviews.request_changes_workflow to allow explicit top-level @coderabbitai resolve or @coderabbitai approve commands.

@github-actions github-actions Bot removed the coderabbit-review-active Required CI passed; CodeRabbit review is active label Sep 2, 2026
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions github-actions Bot removed the awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit label Sep 2, 2026
@github-actions github-actions Bot added the awaiting-maintainer CodeRabbit approved; waiting for a human maintainer label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-maintainer CodeRabbit approved; waiting for a human maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants