mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-18 21:22:28 +03:00
fix(auto): rate-limit empty-pool AUTO warnings (#10344)
Family resolves like auto/zai with no connected models logged a warn on every call (about once a minute per poll). Keep the empty-pool behavior; emit the warn at most once per label per 60s. Co-authored-by: Ravi Tharuma <RaviTharuma@users.noreply.github.com> Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
This commit is contained in:
1
changelog.d/fixes/auto-empty-pool-log-once.md
Normal file
1
changelog.d/fixes/auto-empty-pool-log-once.md
Normal file
@@ -0,0 +1 @@
|
||||
- **fix(auto):** rate-limit `auto/<family> matched no connected models` warnings to once per minute per label (`open-sse/services/autoCombo/virtualFactory.ts`)
|
||||
@@ -44,6 +44,23 @@ export interface AutoComboSpec {
|
||||
family?: ModelFamily;
|
||||
}
|
||||
|
||||
/** Rate-limit empty-pool AUTO warns (same label can be resolved many times/min). */
|
||||
const emptyPoolWarnAt = new Map<string, number>();
|
||||
export const EMPTY_POOL_WARN_INTERVAL_MS = 60_000;
|
||||
|
||||
export function warnEmptyAutoPoolOnce(label: string, message: string, now = Date.now()): boolean {
|
||||
const last = emptyPoolWarnAt.get(label) ?? 0;
|
||||
if (now - last < EMPTY_POOL_WARN_INTERVAL_MS) return false;
|
||||
emptyPoolWarnAt.set(label, now);
|
||||
log.warn("AUTO", message);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Test-only: reset the debounce map. */
|
||||
export function resetEmptyAutoPoolWarnStateForTests(): void {
|
||||
emptyPoolWarnAt.clear();
|
||||
}
|
||||
|
||||
/** Minimal connection shape needed for virtual auto-combo factory */
|
||||
interface VirtualFactoryConn extends ConnectionFields {
|
||||
id: string;
|
||||
@@ -692,8 +709,8 @@ export async function createVirtualAutoComboFromPrepared(
|
||||
// Family combos always degrade to an empty pool when unavailable — a family
|
||||
// is a hard identity constraint, not a soft optimization bias, so there is
|
||||
// no sensible "fall back to the full pool" behavior for it.
|
||||
log.warn(
|
||||
"AUTO",
|
||||
warnEmptyAutoPoolOnce(
|
||||
label,
|
||||
`${label} matched no connected models; returning an empty pool.${spec?.family ? "" : ' Set OMNIROUTE_AUTO_FREE_FALLBACK_TO_FULL_POOL=true to restore the legacy "use full pool" behavior.'}`
|
||||
);
|
||||
effectivePool = [];
|
||||
|
||||
18
tests/unit/auto-empty-pool-warn-once.test.ts
Normal file
18
tests/unit/auto-empty-pool-warn-once.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
import {
|
||||
EMPTY_POOL_WARN_INTERVAL_MS,
|
||||
resetEmptyAutoPoolWarnStateForTests,
|
||||
warnEmptyAutoPoolOnce,
|
||||
} from "../../open-sse/services/autoCombo/virtualFactory.ts";
|
||||
|
||||
test("warnEmptyAutoPoolOnce emits at most once per label per interval", () => {
|
||||
resetEmptyAutoPoolWarnStateForTests();
|
||||
const t0 = 1_000_000;
|
||||
assert.equal(warnEmptyAutoPoolOnce("auto/zai", "empty", t0), true);
|
||||
assert.equal(warnEmptyAutoPoolOnce("auto/zai", "empty", t0 + 1), false);
|
||||
assert.equal(warnEmptyAutoPoolOnce("auto/zai", "empty", t0 + EMPTY_POOL_WARN_INTERVAL_MS - 1), false);
|
||||
assert.equal(warnEmptyAutoPoolOnce("auto/other", "empty", t0 + 1), true);
|
||||
assert.equal(warnEmptyAutoPoolOnce("auto/zai", "empty", t0 + EMPTY_POOL_WARN_INTERVAL_MS), true);
|
||||
});
|
||||
Reference in New Issue
Block a user