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.d/fixes/15432-lkgp-intra-request-ttl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **fix(combo):** skip the redundant second LKGP write when a combo success already pins the combo-level key ([#15432](https://github.com/diegosouzapw/OmniRoute/pull/15432)) — thanks @maxmad64bis
7 changes: 6 additions & 1 deletion open-sse/services/combo/recordLkgpPin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ async function writePins(
setLKGPFn: SetLkgp | undefined
): Promise<void> {
const set = setLKGPFn ?? (await import("@/lib/db/settings")).setLKGP;
const comboKey = comboId || comboName;
if (comboKey === comboName) {
await set(comboName, comboKey, provider, connectionId);
return;
}
await Promise.all([
set(comboName, executionKey, provider, connectionId),
set(comboName, comboId || comboName, provider, connectionId),
set(comboName, comboKey, provider, connectionId),
]);
}

Expand Down
49 changes: 49 additions & 0 deletions tests/unit/combo/record-lkgp-pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,52 @@ test("writer calls carry the connection id through (absent stays absent)", async
});
assert.deepEqual(seen, [undefined, undefined]);
});

test("records a single combo-level pin when the combo id matches the combo name", async () => {
// Pin store standing in for the persisted LKGP namespace; the read below is
// the `getLKGP(comboName, comboId || comboName)` equivalent the routing
// readers use.
const store = new Map<string, { provider: string; connectionId?: string }>();
const calls: Array<[string, string, string, string | undefined]> = [];
const { warnings, log } = captureWarn();
await recordLkgpPin({
comboName: "combo-a",
executionKey: "ek-7",
comboId: "combo-a",
provider: "openai",
connectionId: "conn-1",
log,
tag: "COMBO",
setLKGP: async (comboName, modelKey, provider, connectionId) => {
calls.push([comboName, modelKey, provider, connectionId]);
store.set(`${comboName}:${modelKey}`, { provider, connectionId });
},
});
assert.deepEqual(warnings, []);
assert.equal(calls.length, 1);
assert.deepEqual(calls, [["combo-a", "combo-a", "openai", "conn-1"]]);
assert.equal(store.get("combo-a:combo-a")?.provider, "openai");
});

test("records a single combo-level pin when the combo id is missing", async () => {
const store = new Map<string, { provider: string; connectionId?: string }>();
const calls: Array<[string, string, string, string | undefined]> = [];
const { warnings, log } = captureWarn();
await recordLkgpPin({
comboName: "combo-a",
executionKey: "ek-7",
comboId: null,
provider: "openai",
connectionId: "conn-1",
log,
tag: "COMBO",
setLKGP: async (comboName, modelKey, provider, connectionId) => {
calls.push([comboName, modelKey, provider, connectionId]);
store.set(`${comboName}:${modelKey}`, { provider, connectionId });
},
});
assert.deepEqual(warnings, []);
assert.equal(calls.length, 1);
assert.deepEqual(calls, [["combo-a", "combo-a", "openai", "conn-1"]]);
assert.equal(store.get("combo-a:combo-a")?.provider, "openai");
});
Loading