mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:10:44 +00:00
fix(gateway): avoid caching empty model catalogs
Co-authored-by: openclaw-clawsweeper[bot] <280122609+openclaw-clawsweeper[bot]@users.noreply.github.com>
This commit is contained in:
@@ -47,6 +47,24 @@ describe("loadGatewayModelCatalog", () => {
|
||||
expect(loadModelCatalog).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("does not cache an empty catalog so the next request retries", async () => {
|
||||
const emptyCatalog: GatewayModelChoice[] = [];
|
||||
const freshCatalog = [model("gpt-5.5")];
|
||||
const loadModelCatalog = vi
|
||||
.fn<LoadModelCatalogForTest>()
|
||||
.mockResolvedValueOnce(emptyCatalog)
|
||||
.mockResolvedValueOnce(freshCatalog);
|
||||
|
||||
await expect(loadGatewayModelCatalog({ getConfig, loadModelCatalog })).resolves.toBe(
|
||||
emptyCatalog,
|
||||
);
|
||||
await expect(loadGatewayModelCatalog({ getConfig, loadModelCatalog })).resolves.toBe(
|
||||
freshCatalog,
|
||||
);
|
||||
|
||||
expect(loadModelCatalog).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("returns the last catalog while a stale reload refresh is still pending", async () => {
|
||||
const staleCatalog = [model("gpt-5.4")];
|
||||
const freshCatalog = [model("gpt-5.5")];
|
||||
|
||||
@@ -45,7 +45,7 @@ function startGatewayModelCatalogRefresh(
|
||||
const refresh = resolveLoadModelCatalog(params)
|
||||
.then((loadModelCatalog) => loadModelCatalog({ config }))
|
||||
.then((catalog) => {
|
||||
if (refreshGeneration === staleGeneration) {
|
||||
if (catalog.length > 0 && refreshGeneration === staleGeneration) {
|
||||
lastSuccessfulCatalog = catalog;
|
||||
appliedGeneration = staleGeneration;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user