mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-17 20:52:15 +03:00
* fix(providers): raise default provider probe timeout from 5s to 8s The validationRead and modelsProbe presets in safeOutboundFetch.ts used a fixed 5000ms timeout for the periodic credential health check and on-demand connection test. Several real free-tier providers (Cerebras, Cloudflare AI observed in practice) routinely take close to 5s to answer a lightweight /models probe, which is indistinguishable from a real outage under that budget — the connection flaps between "active" and "error" in the dashboard/topology view purely from being near the edge of the timeout, not from any actual failure. Raised the default to 8000ms and made it configurable via OMNIROUTE_PROVIDER_PROBE_TIMEOUT_MS (validated: falls back to 8000ms for non-numeric or sub-1000ms values) so it can be tuned per-deployment without a code change. validationWrite and modelsPagination presets are untouched. Added tests/unit/safe-outbound-fetch-probe-timeout.test.ts covering the default, env override, invalid-value fallback, and that the other two presets are unaffected. * docs(.env.example): document OMNIROUTE_PROVIDER_PROBE_TIMEOUT_MS * Merge branch 'release/v3.8.50' into fix/provider-probe-timeout Resolved merge conflict in .env.example: kept both Provider probe section (PR) and Proxy/relay fetch section (release branch). Added docs/reference/ENVIRONMENT.md entry for OMNIROUTE_PROVIDER_PROBE_TIMEOUT_MS. --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
50 lines
2.2 KiB
TypeScript
50 lines
2.2 KiB
TypeScript
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const ENV_KEY = "OMNIROUTE_PROVIDER_PROBE_TIMEOUT_MS";
|
|
const originalValue = process.env[ENV_KEY];
|
|
|
|
async function freshImport() {
|
|
// Force a fresh module evaluation so the env var read at module scope is re-applied.
|
|
const modUrl = `../../src/shared/network/safeOutboundFetch.ts?t=${Date.now()}-${Math.random()}`;
|
|
return import(modUrl);
|
|
}
|
|
|
|
describe("safeOutboundFetch — provider probe timeout (validationRead / modelsProbe)", () => {
|
|
afterEach(() => {
|
|
if (originalValue === undefined) delete process.env[ENV_KEY];
|
|
else process.env[ENV_KEY] = originalValue;
|
|
});
|
|
|
|
it("defaults validationRead and modelsProbe to 8000ms when no env override is set", async () => {
|
|
delete process.env[ENV_KEY];
|
|
const { SAFE_OUTBOUND_FETCH_PRESETS } = await freshImport();
|
|
assert.equal(SAFE_OUTBOUND_FETCH_PRESETS.validationRead.timeoutMs, 8000);
|
|
assert.equal(SAFE_OUTBOUND_FETCH_PRESETS.modelsProbe.timeoutMs, 8000);
|
|
});
|
|
|
|
it("honors OMNIROUTE_PROVIDER_PROBE_TIMEOUT_MS when set to a valid value", async () => {
|
|
process.env[ENV_KEY] = "12000";
|
|
const { SAFE_OUTBOUND_FETCH_PRESETS } = await freshImport();
|
|
assert.equal(SAFE_OUTBOUND_FETCH_PRESETS.validationRead.timeoutMs, 12000);
|
|
assert.equal(SAFE_OUTBOUND_FETCH_PRESETS.modelsProbe.timeoutMs, 12000);
|
|
});
|
|
|
|
it("falls back to the 8000ms default when the env value is invalid or too low", async () => {
|
|
process.env[ENV_KEY] = "not-a-number";
|
|
const invalid = await freshImport();
|
|
assert.equal(invalid.SAFE_OUTBOUND_FETCH_PRESETS.modelsProbe.timeoutMs, 8000);
|
|
|
|
process.env[ENV_KEY] = "500"; // below the 1000ms floor
|
|
const tooLow = await freshImport();
|
|
assert.equal(tooLow.SAFE_OUTBOUND_FETCH_PRESETS.modelsProbe.timeoutMs, 8000);
|
|
});
|
|
|
|
it("leaves validationWrite and modelsPagination unaffected by the probe timeout override", async () => {
|
|
process.env[ENV_KEY] = "12000";
|
|
const { SAFE_OUTBOUND_FETCH_PRESETS } = await freshImport();
|
|
assert.equal(SAFE_OUTBOUND_FETCH_PRESETS.validationWrite.timeoutMs, 15000);
|
|
assert.equal(SAFE_OUTBOUND_FETCH_PRESETS.modelsPagination.timeoutMs, 15000);
|
|
});
|
|
});
|