Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

### 🐛 Fixed

- **fix(executor): stop leaking `stream_options` onto non-streaming requests (NVIDIA NIM 400)** — clients that send `stream_options: { include_usage: true }` regardless of `stream` (e.g. the OpenAI Python SDK) had it passed through untouched on non-streaming calls, and NVIDIA NIM rejected it with `400 "Stream options can only be defined when stream=True"`. `DefaultExecutor.transformRequest` only injected/cleared `stream_options` on the streaming branch and had no branch to strip a client-sent value when the outbound request is non-streaming. It now strips `stream_options` whenever `stream` is false (the streaming injection path is unchanged). Affects all OpenAI-compatible providers; NIM is just the one that strictly rejects the violation. ([#3884](https://github.com/diegosouzapw/OmniRoute/issues/3884) — thanks @andrea-kingautomation / @daniij)
- **fix(claude): forward the client-negotiated `anthropic-beta: tool-search-tool-2025-10-19` on the Claude OAuth path** — with `ENABLE_TOOL_SEARCH` active, Claude Code sends deferred tools + a `tool_search_tool_*` and negotiates the `tool-search-tool-2025-10-19` beta, but OmniRoute dropped that beta on **both** Claude code paths (the `default` executor rebuilt the header from the static `ANTHROPIC_BETA_CLAUDE_OAUTH` set, and `selectBetaFlags` only read the client beta to gate thinking/effort), so the claude.ai backend rejected every deferred-tool request with `400 Tool reference '<name>' not found in available tools`. A new allowlist-merge (`mergeClientAnthropicBeta`) now unions the client's negotiated beta into the outbound set on both paths — appending only allowlisted client betas (currently just `tool-search-tool-2025-10-19`) so it never forces betas the client didn't request (preserving the #3415 fix) nor leaks betas the backend rejects. ([#3974](https://github.com/diegosouzapw/OmniRoute/issues/3974) — thanks @huohua-dev)
- **fix(combo): strict-random spreads fallbacks across healthy peers instead of retrying a failing model** — with the `strict-random` strategy, a model that kept failing was retried on essentially every request and traffic concentrated on a few models. The strategy shuffled only the deck-selected slot 0 and left the fallback remainder in **fixed priority order**, so after any failing deck pick the dispatch chain always fell through to the same top-priority model next. The fallback remainder is now shuffled (like the `random` strategy), so the fallback load — and recovery from a persistently-failing target — spreads evenly across the healthy peers. (Note: when the client always sends `tools` (e.g. OpenCode), the combo still correctly routes only to the tool-capable models in the combo — that capability filtering is by design.) ([#3959](https://github.com/diegosouzapw/OmniRoute/issues/3959) — thanks @KeNJiKunG)
- **fix(dashboard): Logs auto-refresh now works even when the tab loads in the background** — the Logs page never auto-refreshed (only the manual Refresh button worked). The auto-refresh interval gated each tick on a visibility ref seeded once at mount and updated only by a `visibilitychange` event; when the tab mounted while the document reported `hidden` (background load, bfcache restore, embedded/Docker-proxied webviews) and no `visibilitychange` ever fired, the ref stayed `false` forever, so the interval ticked but never fetched. The tick now reads the live `document.visibilityState`, so polling self-heals as soon as the tab is visible — while still pausing when genuinely hidden. ([#3972](https://github.com/diegosouzapw/OmniRoute/issues/3972) — thanks @tjengbudi)
Expand Down
8 changes: 8 additions & 0 deletions open-sse/executors/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ export class DefaultExecutor extends BaseExecutor {
delete withoutStreamOptions.stream_options;
withDefaults = withoutStreamOptions;
}
} else if (!stream && Object.prototype.hasOwnProperty.call(withDefaults, "stream_options")) {
// #3884: stream_options is only valid on streaming requests. NVIDIA NIM
// (and the OpenAI spec) reject "Stream options can only be defined when
// stream=True" on non-streaming calls. Strip any client-sent
// stream_options when the outbound request is not streaming.
const withoutStreamOptions = { ...withDefaults } as Record<string, unknown>;
delete withoutStreamOptions.stream_options;
withDefaults = withoutStreamOptions;
Comment on lines +577 to +579

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.

medium

Using object destructuring with a rest parameter is a more modern, idiomatic, and declarative way to omit properties in TypeScript/JavaScript compared to using the delete operator on a shallow copy. It also avoids the need for an explicit delete statement.

Additionally, this property-omission pattern is duplicated in multiple places within this file. Consider refactoring this into a reusable helper function (e.g., omitStreamOptions) to improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle.

Suggested change
const withoutStreamOptions = { ...withDefaults } as Record<string, unknown>;
delete withoutStreamOptions.stream_options;
withDefaults = withoutStreamOptions;
const { stream_options: _, ...withoutStreamOptions } = withDefaults as Record<string, unknown>;
withDefaults = withoutStreamOptions;

} else if (
(targetFormat === "openai-responses" || requestFormat === "openai-responses") &&
Object.prototype.hasOwnProperty.call(withDefaults, "stream_options")
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/stream-options-nonstreaming-3884.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* TDD regression for #3884: OmniRoute leaked `stream_options` onto NON-streaming
* requests. NVIDIA NIM (and the OpenAI spec) reject it with
* `400 "Stream options can only be defined when stream=True"`.
*
* Root cause: DefaultExecutor.transformRequest injected `stream_options` only on
* streaming openai requests (correctly gated on `stream`), but had no branch to
* STRIP a client-sent `stream_options` when the outbound request is non-streaming
* — so the OpenAI Python SDK and similar clients (which send
* `stream_options:{include_usage:true}` regardless of `stream`) passed it through
* untouched to the provider on `stream:false` calls. Affects all openai-compat
* providers; NIM is just the one that strictly rejects the violation.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { DefaultExecutor } from "../../open-sse/executors/default.ts";

test("#3884 non-streaming request strips a client-sent stream_options", () => {
const executor = new DefaultExecutor("openai");
const body = {
model: "gpt-4.1",
messages: [{ role: "user", content: "hi" }],
stream_options: { include_usage: true },
};
const result = executor.transformRequest("gpt-4.1", body, false, {}) as Record<string, unknown>;
assert.equal(
result.stream_options,
undefined,
"stream_options must be stripped when the outbound request is not streaming"
);
});

test("#3884 streaming request still injects stream_options.include_usage", () => {
const executor = new DefaultExecutor("openai");
const body = { model: "gpt-4.1", messages: [{ role: "user", content: "hi" }] };
const result = executor.transformRequest("gpt-4.1", body, true, {}) as Record<string, unknown>;
assert.deepEqual(result.stream_options, { include_usage: true });
});

test("#3884 non-streaming request without stream_options stays clean", () => {
const executor = new DefaultExecutor("openai");
const body = { model: "gpt-4.1", messages: [{ role: "user", content: "hi" }] };
const result = executor.transformRequest("gpt-4.1", body, false, {}) as Record<string, unknown>;
assert.equal(result.stream_options, undefined);
});