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:
clawsweeper[bot]
2026-04-29 21:53:25 -07:00
committed by GitHub
parent a6af23a1de
commit 6689e414bb
2 changed files with 19 additions and 1 deletions

View File

@@ -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")];

View File

@@ -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;
}