Skip to content

fix(providers): stop OpenRouter/HF stream timeout on reasoning models - #25

Merged
Ocean82 merged 1 commit into
mainfrom
fix-openrouter-reasoning-timeout
Sep 5, 2026
Merged

fix(providers): stop OpenRouter/HF stream timeout on reasoning models#25
Ocean82 merged 1 commit into
mainfrom
fix-openrouter-reasoning-timeout

Conversation

@Ocean82

@Ocean82 Ocean82 commented Sep 5, 2026

Copy link
Copy Markdown
Owner

One of the three provider bugs blocking launch. qwen/qwen3.6-27b streams reasoning tokens (delta.reasoning) before any content. The openaiCompatible stream parser only forwarded delta.content, so the caller's 30s first-byte timeout (providers.ts) fired during the reasoning phase — every OpenRouter/HuggingFace fallback timed out even though data was flowing.

Fix: emit one empty liveness ping on the first delta.reasoning chunk (bypassing the thinking-tag filter, which swallows empty strings) so the first-byte timeout disarms. No reasoning text is leaked; content streams normally.

Tests: +2 (reasoning-before-content pings exactly once; content-first path does not ping). Server suite 325/325.

Related: the other two provider bugs — Groq reasoning_format (fixed by #24's deploy, verified live 200 + clean output) and Ollama NUM_CTX=2048 overriding the Modelfile (fixed on the box, set to 8192) — are resolved. Groq is primary and healthy. Option 2 (actually suppress reasoning on these fallback providers, vs just not-timing-out) is logged in PRODUCTION-TODO as low-priority polish.

Summary by Sourcery

Keep OpenRouter and Hugging Face reasoning-model streams alive until content arrives without exposing reasoning output.

Bug Fixes:

  • Prevent OpenRouter and Hugging Face streaming fallbacks from timing out while reasoning models emit reasoning before content.
  • Keep reasoning tokens out of user-visible output while allowing normal content streaming.

Documentation:

  • Document the remaining low-priority work to suppress reasoning generation on OpenRouter and Hugging Face fallbacks.

Tests:

  • Add coverage for a single liveness ping during reasoning-before-content streams and no ping for content-first streams.

qwen/qwen3.6-27b streams delta.reasoning before any delta.content. The openaiCompatible stream parser only forwarded delta.content, so the caller's 30s first-byte timeout (providers.ts) tripped during the reasoning phase even though data was flowing — every OpenRouter/HF fallback timed out. Emit one empty liveness ping on the first reasoning chunk (bypassing the thinking-tag filter, which swallows empty strings) so the timeout disarms without leaking reasoning text. Content still streams normally.

Adds 2 tests (reasoning-before-content pings once; content-first does not ping); server suite 325/325. Logs Option 2 (actually suppress reasoning on these providers) as a low-priority follow-up in PRODUCTION-TODO.
Copilot AI lite review requested due to automatic review settings September 5, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sourcery-ai

sourcery-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR updates the OpenAI-compatible SSE parser to treat the first reasoning-only delta as a one-time empty liveness signal, preventing first-byte timeouts while continuing to suppress reasoning content; tests cover both reasoning-first and content-first streams, and the remaining provider-specific reasoning suppression work is documented.

Sequence diagram for reasoning-stream liveness ping

sequenceDiagram
    participant Provider as OpenAI-compatible provider
    participant Parser as chatWithOpenAiCompatibleStream
    participant Caller as Stream caller

    Provider->>Parser: SSE delta.reasoning
    Parser->>Caller: onChunk('')
    Note over Parser,Caller: One-time ping disarms first-byte timeout
    Provider->>Parser: SSE delta.reasoning
    Note over Parser: Reasoning text is suppressed
    Provider->>Parser: SSE delta.content
    Parser->>Caller: onChunk(content)
    Parser-->>Caller: Return accumulated content
Loading

File-Level Changes

Change Details Files
Keep fallback streams alive during reasoning-only phases without exposing reasoning text.
  • Track whether a reasoning liveness ping has been sent.
  • Detect delta.reasoning chunks when no content is present and invoke the callback once with an empty string, bypassing the thinking-tag filter.
  • Continue accumulating and filtering only delta.content, preserving normal output behavior.
server/src/openaiCompatible.ts
Add coverage for reasoning-first and content-first streaming behavior.
  • Mock SSE streams with reasoning before content and verify exactly one empty ping, clean accumulated output, and correct callback chunks.
  • Verify content-first streams produce no empty ping and preserve the complete response.
server/src/openaiCompatible.test.ts
Document remaining reasoning suppression as a separate fallback-provider polish task.
  • Record that timeout handling is fixed while reasoning generation remains unsuppressed on OpenRouter/HuggingFace.
  • Note provider-specific request parameters and defer implementation pending live API verification.
docs/PRODUCTION-TODO.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 4bf8cecc-91d0-4419-b542-a3f2838abebe


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

@Ocean82
Ocean82 merged commit 9777027 into main Sep 5, 2026
5 checks passed
@Ocean82
Ocean82 deleted the fix-openrouter-reasoning-timeout branch September 5, 2026 15:59

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Ocean82 added a commit that referenced this pull request Sep 6, 2026
…ect ecosystem note (#27)

The 2026-09-06 launch deploy failed at the nginx -t gate and rolled back:
nginx.conf:12 includes /etc/letsencrypt/le_http_01_cert_challenge.conf (a
Certbot HTTP-01 renewal include) which had gone missing, so nginx -t failed
for the whole config even though our site config was identical to the repo.
Fixed by recreating the include empty + root-owned (the correct idle state;
removing the include line would break Certbot renewal). nginx -t then passed,
reloaded, and the server half of the deploy was completed manually (tsc build,
pm2 restart on Node 22, pm2 save). Strict health green; public / 200, /app 301,
/health 200; live Groq probe returned clean 200 (no <think> dump).

Also corrects the stale "deploy the committed ecosystem.config.cjs" pending
item: that file is .gitignored (contains secrets), so it is never checked out
on the box and there is nothing to migrate to. The manual pm2 start + pm2 save
dump is the intended steady state and deploy.sh's pm2 restart reuses it. Marked
not-applicable rather than pending.
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.

2 participants