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 (claude, round 2): pin the residual clauses, honest status codes

Adam Eivy027e5f1183ae
diff --git a/client/src/components/settings/VoiceTab.jsx b/client/src/components/settings/VoiceTab.jsx
index cdbf7cb2c0..24c02655f2 100644
--- a/client/src/components/settings/VoiceTab.jsx
+++ b/client/src/components/settings/VoiceTab.jsx
@@ -243,8 +243,9 @@ export function VoiceTab() {
if (!providerId || refreshingModels) return;
setRefreshingModels(true);
try {
- // Silent: the route 404s when the provider returns no models, so the
- // catch below owns the error toast (avoids a double toast).
+ // Silent: the route errors when the refresh fails (502 with the probe's
+ // real message, or 400 when that CLI has no fetcher), so the catch below
+ // owns the error toast (avoids a double toast).
const updated = await refreshProviderModels(providerId, { silent: true });
setApiProviders((prev) => prev.map((p) => (p.id === providerId ? { ...p, models: updated.models || [] } : p)));
toast.success(`Refreshed models for ${updated.name || providerId} (${updated.models?.length || 0})`);
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index 8ff690bea0..4e7b4eee45 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -800,6 +800,15 @@ describe('supportsModelRefresh', () => {
expect(supportsModelRefresh({ id: 'x', type: 'tui', command: '/opt/bin/agy', name: 'whatever' })).toBe(true);
});
+ // Pins the COMMAND half of the antigravity CLI test, which the server hoisted
+ // above its name test. Only the NAME half was covered above, so deleting
+ // `isAntigravityCommand(command)` here left the suite green while an
+ // agy-commanded provider under any other name lost a button the server serves.
+ it('offers it for an agy-commanded CLI provider whose name says nothing about it', () => {
+ expect(supportsModelRefresh({ id: 'x', type: 'cli', command: 'agy', name: 'My Coding Agent' })).toBe(true);
+ expect(supportsModelRefresh({ id: 'x', type: 'cli', command: '/opt/homebrew/bin/agy', name: 'My Coding Agent' })).toBe(true);
+ });
+
it('still offers it for the providers the server CAN fetch for', () => {
// Ollama-backed and antigravity are checked BEFORE the TUI gate, so their
// TUI variants must still refresh — the ordering is the load-bearing part.
diff --git a/server/lib/aiToolkit/internal/endpointGuard.js b/server/lib/aiToolkit/internal/endpointGuard.js
index 76f4047686..3288db8d67 100644
--- a/server/lib/aiToolkit/internal/endpointGuard.js
+++ b/server/lib/aiToolkit/internal/endpointGuard.js
@@ -176,6 +176,13 @@ export function assertSecretEndpoint(endpoint, { hasSecret, allowCustomEndpoint
if (!hasSecret) return;
const { allowed, reason } = evaluateSecretEndpoint(endpoint, { allowCustomEndpoint });
if (!allowed) {
- throw new Error(`Blocked outbound API-key request: ${reason}`);
+ // 400, not the caller's 502 default: nothing upstream failed — the endpoint
+ // is misconfigured and the user has to change it (or opt in via
+ // `allowCustomEndpoint`). Reported as BAD_GATEWAY it reads as "the vendor is
+ // down, retry", so the user retries instead of fixing it — and any status
+ // >= 500 also makes errorHandler log a full stack for a plain config error.
+ const blocked = new Error(`Blocked outbound API-key request: ${reason}`);
+ blocked.status = 400;
+ throw blocked;
}
}
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index f972aedd2f..ec21bed3f8 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -780,6 +780,17 @@ export function createProviderService(config = {}) {
// Shaped to match the antigravity arm above; both collapse together
// when the dispatch becomes a table (#3620).
models = await this._fetchCursorModels(provider);
+ } else {
+ // No branch matched — this provider type/shape has no fetcher. Say so,
+ // the same 400 the CLI arm's own fall-through throws. Previously this
+ // fell out as `models === null` and the route rendered it as
+ // `404 Provider not found or not an API type`, which is exactly the
+ // false message the rethrow above set out to stop showing: a plain
+ // `codex-tui`/`grok-tui` provider exists and its type is fine, it just
+ // has no catalog to fetch.
+ const unsupported = new Error(`Model refresh not supported for ${provider.type} provider '${provider.id}'`);
+ unsupported.status = 400;
+ throw unsupported;
}
} catch (error) {
console.error(`Failed to refresh models for ${provider.name}:`, error.message);
@@ -800,8 +811,16 @@ export function createProviderService(config = {}) {
throw error;
}
+ // Belt-and-braces: every branch above returns an array or throws, so this
+ // is unreachable today — but a future fetcher that returns null must not
+ // persist `models: null` over the user's list. Throws rather than
+ // returning null so `null` keeps exactly ONE meaning out of this function:
+ // the provider does not exist. That is what lets the route's 404 say
+ // plainly "Provider not found" instead of guessing at a reason.
if (models === null) {
- return null;
+ const unsupported = new Error(`Model refresh returned nothing for provider '${provider.id}'`);
+ unsupported.status = 400;
+ throw unsupported;
}
const updatedProvider = {
@@ -964,8 +983,10 @@ export function createProviderService(config = {}) {
* from a real fetch — `refreshProviderModels` would persist it and the UI
* would toast "Models refreshed", so a user whose PATH can't see the binary
* would pick a model their plan doesn't have and only find out when the run
- * dies. Throwing makes `refreshProviderModels` return null → an explicit
- * error toast, with the stored list left untouched. Same posture as
+ * dies. `refreshProviderModels` propagates the throw (as a 502) rather than
+ * flattening it to null, so the toast names the actual cause instead of the
+ * route's generic not-found text — and the stored list is left untouched
+ * either way, since nothing is persisted. Same posture as
* `_fetchOllamaToolCapableModels`, and the root CLAUDE.md rule that a
* reachable-but-list-failed backend must surface an explicit error rather
* than a plausible-looking empty/default result.
@@ -1078,7 +1099,11 @@ export function createProviderService(config = {}) {
const apiKey = provider.apiKey || process.env.GOOGLE_API_KEY;
if (!apiKey) {
- throw new Error('Google API key required for model refresh');
+ // 400 for the same reason as the endpoint guard: a missing key is the
+ // user's to fix, not an upstream outage.
+ const missingKey = new Error('Google API key required for model refresh');
+ missingKey.status = 400;
+ throw missingKey;
}
const response = await fetch(
diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.js
index 319adc016c..3a0805c7d9 100644
--- a/server/lib/aiToolkit/providers.test.js
+++ b/server/lib/aiToolkit/providers.test.js
@@ -806,9 +806,10 @@ describe('Provider Service', () => {
expect(updated.models).toEqual(['qwen2.5:7b']);
});
- it('does not refresh a non-ollama-backed TUI provider (returns null)', async () => {
- // A plain claude TUI provider has no Ollama backing — refresh is a no-op
- // for tui type, so it returns null (models left as configured).
+ it('reports a non-ollama-backed TUI provider as unsupported, not as missing', async () => {
+ // A plain claude TUI provider has no Ollama backing and no catalog to
+ // fetch. It must say THAT — not fall out as null and get rendered as
+ // "Provider not found", which is false: it exists and its type is fine.
const p = await providerService.createProvider({
name: 'Claude Code TUI',
type: 'tui',
@@ -816,8 +817,49 @@ describe('Provider Service', () => {
models: ['claude-opus-4-8'],
});
- const updated = await providerService.refreshProviderModels(p.id);
- expect(updated).toBeNull();
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const err = await providerService.refreshProviderModels(p.id).catch(e => e);
+ errSpy.mockRestore();
+
+ expect(err).toBeInstanceOf(Error);
+ expect(err.message).toMatch(/not supported for tui provider/i);
+ expect(err.status).toBe(400);
+ // The configured list is untouched.
+ const after = await providerService.getProviderById(p.id);
+ expect(after.models).toEqual(['claude-opus-4-8']);
+ });
+
+ it('returns null only for a provider that does not exist', async () => {
+ // The one remaining meaning of null — what lets the route's 404 say
+ // plainly "Provider not found" rather than guessing at a reason.
+ expect(await providerService.refreshProviderModels('no-such-provider')).toBeNull();
+ });
+
+ // Pins the `provider.id === ANTIGRAVITY_TUI_ID` half of that arm's OR — the
+ // same gap that was open on CURSOR_TUI_ID. Every other antigravity-TUI test
+ // matches on the `agy` command, so deleting the id clause left the suite
+ // green while a shipped antigravity-tui repointed at a wrapper lost refresh.
+ it('reaches the agy fetcher for a shipped antigravity-tui repointed at a wrapper', async () => {
+ await writeFile(join(TEST_DATA_DIR, 'providers.json'), JSON.stringify({
+ activeProvider: 'antigravity-tui',
+ providers: {
+ 'antigravity-tui': {
+ id: 'antigravity-tui', name: 'Antigravity TUI', type: 'tui',
+ command: '/nonexistent/path/to/agy-wrap', contextWindow: 1048576,
+ models: ['antigravity-configured-default'],
+ defaultModel: 'antigravity-configured-default',
+ },
+ },
+ }, null, 2));
+
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const err = await providerService.refreshProviderModels('antigravity-tui').catch(e => e);
+ errSpy.mockRestore();
+
+ // Reached the agy fetcher (which then failed on the bogus path). Without
+ // the id clause it would fall to the `else` and report "not supported".
+ expect(err.message).toMatch(/agy-wrap models' failed/);
+ expect(err.message).not.toMatch(/not supported/i);
});
});
@@ -956,6 +998,24 @@ describe('Provider Service', () => {
expect(updated.models).not.toContain('antigravity-configured-default');
});
+ // …and the residual NAME half of that same split is pinned too. Left
+ // unpinned, a future cleanup deletes it as apparently-redundant while the
+ // client's mirrored `name.includes('antigravity')` keeps offering the
+ // button — every click then 400s. That is precisely the client/server drift
+ // the parity apparatus exists to prevent.
+ it('still routes an antigravity-NAMED provider with an unrelated command to the agy fetcher', async () => {
+ const p = await providerService.createProvider({
+ name: 'Antigravity Nightly', type: 'cli', command: '/nonexistent/path/to/weird-wrapper', models: ['x'],
+ });
+
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const err = await providerService.refreshProviderModels(p.id).catch(e => e);
+ errSpy.mockRestore();
+
+ expect(err.message).toMatch(/weird-wrapper models' failed/);
+ expect(err.message).not.toMatch(/not supported/i);
+ });
+
// A failed `cursor-agent models` probe must be distinguishable from a real
// fetch. Returning the shipped 27-id seed here would persist it and toast
// "Models refreshed", so a user whose service PATH can't resolve the binary
diff --git a/server/lib/aiToolkit/routes/errorEnvelope.test.js b/server/lib/aiToolkit/routes/errorEnvelope.test.js
index b8ddc69944..11bb30a327 100644
--- a/server/lib/aiToolkit/routes/errorEnvelope.test.js
+++ b/server/lib/aiToolkit/routes/errorEnvelope.test.js
@@ -73,6 +73,48 @@ describe('issue-1084: toolkit routes emit the PortOS error envelope', () => {
expect(providers.createProvider).not.toHaveBeenCalled();
});
+ // issue-3615 — a refresh that fails must tell the user WHY. This is the seam
+ // the fix lives on: the service throws with a real message and a status, and
+ // the route must pass both through instead of flattening every failure into
+ // its own 404. Asserted here at the HTTP boundary, not just at the service.
+ it('providers refresh-models 502 (probe failed) → BAD_GATEWAY carrying the real reason', async () => {
+ const probeFailed = new Error("'cursor-agent models' failed: spawn cursor-agent ENOENT");
+ probeFailed.status = 502;
+ const providers = { refreshProviderModels: vi.fn().mockRejectedValue(probeFailed) };
+ const app = portosApp('/api/providers', (opts) => createProvidersRoutes(providers, opts));
+
+ const res = await request(app).post('/api/providers/cursor-cli/refresh-models');
+ expect(res.status).toBe(502);
+ expect(res.body.code).toBe('BAD_GATEWAY');
+ // The actual cause, not "Provider not found or not an API type".
+ expect(res.body.error).toMatch(/cursor-agent models' failed/);
+ expect(res.body.error).not.toMatch(/not found/i);
+ // No stack in the response body, even at a 5xx.
+ expect(res.body.stack).toBeUndefined();
+ });
+
+ it('providers refresh-models 400 (no fetcher for this CLI) → BAD_REQUEST, not 502', async () => {
+ const unsupported = new Error('Model refresh not supported for this CLI provider');
+ unsupported.status = 400;
+ const providers = { refreshProviderModels: vi.fn().mockRejectedValue(unsupported) };
+ const app = portosApp('/api/providers', (opts) => createProvidersRoutes(providers, opts));
+
+ const res = await request(app).post('/api/providers/codex/refresh-models');
+ expect(res.status).toBe(400);
+ expect(res.body).toMatchObject({ error: 'Model refresh not supported for this CLI provider', code: 'BAD_REQUEST' });
+ });
+
+ it('providers refresh-models 404 → the bare "Provider not found", null having one meaning now', async () => {
+ const providers = { refreshProviderModels: vi.fn().mockResolvedValue(null) };
+ const app = portosApp('/api/providers', (opts) => createProvidersRoutes(providers, opts));
+
+ const res = await request(app).post('/api/providers/ghost/refresh-models');
+ expect(res.status).toBe(404);
+ expect(res.body).toMatchObject({ error: 'Provider not found', code: 'NOT_FOUND' });
+ // The old message guessed at a cause it could not know.
+ expect(res.body.error).not.toMatch(/API type/);
+ });
+
it('prompts 404 (GET /stages/:name missing) → NOT_FOUND envelope', async () => {
const prompts = { getStage: vi.fn().mockReturnValue(null) };
const app = portosApp('/api/prompts', (opts) => createPromptsRoutes(prompts, opts));
diff --git a/server/lib/aiToolkit/routes/providers.js b/server/lib/aiToolkit/routes/providers.js
index 25d893f30c..1a695737c9 100644
--- a/server/lib/aiToolkit/routes/providers.js
+++ b/server/lib/aiToolkit/routes/providers.js
@@ -96,8 +96,14 @@ export function createProvidersRoutes(providerService, options = {}) {
router.post('/:id/refresh-models', asyncHandler(async (req, res) => {
const provider = await providerService.refreshProviderModels(req.params.id);
+ // `null` now means exactly one thing — no such provider. Every other failure
+ // (probe failed, no fetcher for this type/CLI, missing key, blocked
+ // endpoint) throws from the service with its own status and real message,
+ // which asyncHandler routes straight to the error middleware. The old
+ // "or not an API type" suffix was a guess that covered for those cases and
+ // was wrong for all of them.
if (!provider) {
- throw new ServerError('Provider not found or not an API type', { status: 404 });
+ throw new ServerError('Provider not found', { status: 404 });
}
res.json(provider);