Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (antigravity): validate the batch probe result as an array, not against null (#4155)

[._.]/ Adam Eivy2137b2077a90
diff --git a/server/lib/aiToolkit/providers.batch.test.js b/server/lib/aiToolkit/providers.batch.test.js
index 4719a666b0..a816ec583e 100644
--- a/server/lib/aiToolkit/providers.batch.test.js
+++ b/server/lib/aiToolkit/providers.batch.test.js
@@ -216,6 +216,27 @@ describe('refreshProviderModelsBatch — one providers.json write per fan-out',
expect(atomicWrite).toHaveBeenCalledTimes(1);
});
+ it('treats a probe that answers with no array as missing, not as an update', async () => {
+ // `fetchProviderModels` promises an array or a throw, so this is a guard
+ // against a future fetcher rather than a reachable path today — but the
+ // failure mode it prevents is the whole batch dying on `[...undefined]`,
+ // taking the healthy groups' write down with it.
+ stubOllama({ [LOCAL]: ['qwen2.5:7b'] });
+ const broken = await providerService.createProvider(ollamaProvider('Broken', { base: REMOTE }));
+ const healthy = await providerService.createProvider(ollamaProvider('Local One'));
+ vi.spyOn(providerService, 'fetchProviderModels').mockImplementation(async (id) => (
+ id === broken.id ? undefined : ['qwen2.5:7b']
+ ));
+ atomicWrite.mockClear();
+
+ const groups = await providerService.refreshProviderModelsBatch([broken.id, healthy.id]);
+
+ expect(groups.map((g) => g.status)).toEqual(['missing', 'updated']);
+ expect(atomicWrite).toHaveBeenCalledTimes(1);
+ expect((await providerService.getProviderById(broken.id)).models).toEqual(['stale-model']);
+ expect((await providerService.getProviderById(healthy.id)).models).toEqual(['qwen2.5:7b']);
+ });
+
it('is a no-op for an empty id list', async () => {
stubOllama({ [LOCAL]: ['qwen2.5:7b'] });
await providerService.createProvider(ollamaProvider('Local One'));
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index f026c60f35..4e06c99283 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -909,8 +909,13 @@ export function createProviderService(config = {}) {
continue;
}
// `null` here means the lead vanished mid-probe — the same `missing`
- // the group already carries, so leave the status alone.
- if (probed.models === null) continue;
+ // the group already carries, so leave the status alone. Validated as an
+ // ARRAY rather than compared to `null`: `fetchProviderModels` promises
+ // an array or a throw, but a future fetcher that leaks `undefined` must
+ // land on `missing` too, not be persisted as an "updated" catalog (and
+ // then crash the whole batch on the spread below). `[]` is an array, so
+ // a legitimately empty catalog still passes.
+ if (!Array.isArray(probed.models)) continue;
group.status = 'updated';
group.models = probed.models;
}