Skip to content

fix(providers): bound non-streaming response body reads - #320

Merged
404-Page-Found merged 1 commit into
mainfrom
fix/304-non-streaming-body-timeout
Sep 22, 2026
Merged

404-Page-Found merged 1 commit into
mainfrom
fix/304-non-streaming-body-timeout

Conversation

@404-Page-Found

@404-Page-Found 404-Page-Found commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep the provider abort controller available after headers arrive
  • add a shared timeout-bounded response text/JSON reader for non-streaming bodies
  • apply the body deadline to OpenAI-compatible, Anthropic, and Cohere completion/model reads
  • add regression coverage for headers arriving before a stalled JSON body

Closes #304.

Note: the local test suite could not be executed in this environment because outbound access to github.com is unavailable; the deterministic regression tests are included for CI verification.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Added timeout handling while reading AI provider response bodies.
    • Requests now cancel stalled response streams instead of waiting indefinitely.
    • Improved timeout errors for incomplete responses across supported providers.
  • Tests

    • Added coverage for stalled response bodies, cancellation, and timeout reporting.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: de29f96e-f5bf-415f-a7d5-2f13e45ac7af

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 1c3f71ad-796b-499b-8046-e39c14c6d898

📥 Commits

Reviewing files that changed from the base of the PR and between 335fda8 and 02a0022.

📒 Files selected for processing (6)
  • src/providers/anthropic.ts
  • src/providers/cohere.ts
  • src/providers/openai-compatible.ts
  • src/providers/request.ts
  • tests/provider-timeout.test.mjs
  • tests/providers/provider-body-timeout.test.mjs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (4)
All LLM providers must implement the `Provider` interface from `src/types.ts`; new providers must be registered in `BUILTIN_PROVIDERS` and wired through `createProvider()`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • src/providers/openai-compatible.ts
  • src/providers/anthropic.ts
  • src/providers/cohere.ts
  • src/providers/request.ts
Use Node.js built-in `node:test` and `node:assert/strict`; do not use Jest or Mocha.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • tests/provider-timeout.test.mjs
  • tests/providers/provider-body-timeout.test.mjs
Library code must throw errors directly; command handlers should catch errors and display them through `outro(pc.red(...))`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • src/providers/openai-compatible.ts
  • src/providers/anthropic.ts
  • src/providers/cohere.ts
  • src/providers/request.ts
Use ESM imports with `.js` extensions for local modules, and use `import type` for type-only imports.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • src/providers/openai-compatible.ts
  • src/providers/anthropic.ts
  • src/providers/cohere.ts
  • src/providers/request.ts
🪛 GitHub Actions: CI / 0_Test (ubuntu-latest).txt
src/providers/openai-compatible.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/anthropic.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/cohere.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

🪛 GitHub Actions: CI / 1_Test (macos-latest).txt
src/providers/openai-compatible.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/anthropic.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/cohere.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

🪛 GitHub Actions: CI / 2_Test (windows-latest).txt
src/providers/openai-compatible.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/anthropic.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/cohere.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

🪛 GitHub Actions: CI / Test (macos-latest)
src/providers/openai-compatible.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/anthropic.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/cohere.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

🪛 GitHub Actions: CI / Test (ubuntu-latest)
src/providers/openai-compatible.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/anthropic.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

src/providers/cohere.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

🪛 GitHub Actions: CI / Test (windows-latest)
src/providers/openai-compatible.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write src/providers/openai-compatible.ts' to fix code style issues.

src/providers/anthropic.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write src/providers/anthropic.ts' to fix code style issues.

src/providers/cohere.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write src/providers/cohere.ts' to fix code style issues.

🔇 Additional comments (6)
src/providers/request.ts (1)

32-90: LGTM!

src/providers/anthropic.ts (1)

2-7: LGTM!

Also applies to: 40-40, 57-58, 62-66, 70-70, 73-73

src/providers/cohere.ts (1)

2-7: LGTM!

Also applies to: 12-12, 49-50, 54-58, 62-62, 65-65, 78-78, 89-90, 97-97, 99-99

src/providers/openai-compatible.ts (1)

2-7: LGTM!

Also applies to: 33-33, 52-53, 57-61, 65-65, 68-68, 150-150, 160-166, 172-174

tests/provider-timeout.test.mjs (1)

4-7: LGTM!

Also applies to: 51-71

tests/providers/provider-body-timeout.test.mjs (1)

1-110: LGTM!


📝 Walkthrough

Walkthrough

Provider completion and model-discovery requests now apply timeouts while reading response bodies. Shared helpers abort stalled reads and cancel streams. Tests cover all affected providers and verify timeout errors and cancellation.

Changes

Provider body timeout handling

Layer / File(s) Summary
Timed response readers
src/providers/request.ts
Adds timeout-aware text and JSON response readers. Stalled reads abort the controller, cancel the stream, release the body lock, and report labeled timeout errors.
Provider request integration
src/providers/anthropic.ts, src/providers/cohere.ts, src/providers/openai-compatible.ts
Completion and model-discovery methods pass abort controllers to fetchWithTimeout and use the timeout-aware response readers.
Response timeout validation
tests/provider-timeout.test.mjs, tests/providers/provider-body-timeout.test.mjs
Tests verify stalled response handling, timeout messages, controller abortion, stream cancellation, and body-lock release.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: mikemikimike

Merge Risk: ⚪ Minimal · up to 02a00

Non-streaming provider responses now have bounded body reads and stream cancellation, preventing indefinite hangs. The supplied coverage spans completion and model-discovery paths, so the change is mergeable with normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: bounding non-streaming provider response body reads with timeouts.
Linked Issues check ✅ Passed Issue #304 requires a timeout after headers arrive and before a non-streaming body completes. The PR adds readResponseTextWithTimeout and readResponseJsonWithTimeout, which abort and cancel stalle…
Out of Scope Changes check ✅ Passed The changed source files implement the #304 body-read timeout. The changed tests verify the shared reader and each required provider path. The diff contains no demonstrated unrelated product behavior …
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

A rabbit reads the stream with care
No stalled JSON lingers there
The timers ring, the streams unwind
Each provider leaves the wait behind
Fresh tests guard the timeout line

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

Comment thread src/providers/anthropic.ts Outdated
Comment thread tests/providers/provider-body-timeout.test.mjs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.
Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/providers/provider-body-timeout.test.mjs Outdated
@404-Page-Found
404-Page-Found force-pushed the fix/304-non-streaming-body-timeout branch from 452bc01 to 9e2f2ac Compare September 22, 2026 21:35
@sonarqubecloud

Copy link
Copy Markdown

@404-Page-Found
404-Page-Found merged commit 2a44b90 into main Sep 22, 2026
7 checks passed
@404-Page-Found
404-Page-Found deleted the fix/304-non-streaming-body-timeout branch September 22, 2026 21:39
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] Non-streaming provider responses can hang indefinitely after headers arrive

1 participant