Skip to content

Commit 367dc64

Browse files
ndemiancclaude
andcommitted
fix(ai): fall back to the cached roster unless data.models is a real array (PR #43 review)
The retry returned `data || cached()`, so any truthy JSON that lacked a valid `models` array — a 200 with an error object, a partial response, a schema drift — was returned as-is. pickCloudModel then sees "no models" and collapses to the 2-model fallback even though cloudRoster still holds a good list, defeating the whole point of the cache. Now a payload only counts as a roster when data.models is an array; otherwise it returns cached(). Also fixes the mirror case where a 200 arrives but json() failed (data null) — same fall-through to the cache. Full gate: 24 suites, 0 failures. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ef99a8f commit 367dc64

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

extensions/levelcode-ai/extension.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,17 @@ async function fetchCloudRoster() {
255255
}
256256
if (!res.ok) { dbg('cloud.roster', { ok: false, status: res.status }); return cached(); }
257257
const data = await res.json().catch(() => null);
258+
// Only a payload with a real models array IS a roster. A 200 carrying an error object, a partial
259+
// response, or a schema drift is not — returning it would make pickCloudModel see "no models" and
260+
// collapse to the 2-model fallback despite a valid last-known-good list. Prefer the cache then.
258261
if (data && Array.isArray(data.models)) {
259262
cloudRoster = data.models;
260263
// The roster carries each model's short label — refresh the footer chip so it shows
261264
// "Opus 4.8" instead of the raw id it fell back to before the roster finished loading.
262265
sendConfigToWebview();
266+
return data;
263267
}
264-
return data || cached();
268+
return cached();
265269
} catch (e) { dbg('cloud.roster', { error: String((e && e.message) || e) }); return cached(); }
266270
}
267271

0 commit comments

Comments
 (0)