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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: replace stale preset model subsets on explicit refresh
[._.]/ Adam Eivy546a22bbee6e
diff --git a/server/lib/aiToolkit/internal/modelFetchers.js b/server/lib/aiToolkit/internal/modelFetchers.jsindex 045bb44b9f..f48cea61e4 100644--- a/server/lib/aiToolkit/internal/modelFetchers.js+++ b/server/lib/aiToolkit/internal/modelFetchers.js@@ -150,6 +150,7 @@ export const MODEL_FETCHERS = [// `claude` owns `~/.claude` — widening this is a separate call from// widening the vendors that probe their own CLI.cliMatch: (p) => p?.command === 'claude' && !usesThirdPartyBackend(p),+ tuiMatch: (p) => p?.command === 'claude' && !usesThirdPartyBackend(p),cliNameMatch: (p) => displayName(p).includes('claude') && !usesThirdPartyBackend(p),fetch: '_fetchAnthropicModels',},diff --git a/server/lib/aiToolkit/internal/modelFetchers.test.js b/server/lib/aiToolkit/internal/modelFetchers.test.jsindex a7656d55b6..1d9114f935 100644--- a/server/lib/aiToolkit/internal/modelFetchers.test.js+++ b/server/lib/aiToolkit/internal/modelFetchers.test.js@@ -15,6 +15,7 @@ const SHIPPED = JSON.parse(readFileSync(resolve(__dirname, '../../../../data.ref// failure mode is silent in both directions (a button that 404s, or a feature// that vanishes with no error at all).const SHIPPED_REFRESHABLE = [+ 'claude-code-tui','pi-cli', 'pi-tui','antigravity-cli', 'antigravity-tui', 'cerebras', 'claude-code','claude-ollama', 'claude-ollama-tui', 'cursor-cli',@@ -52,7 +53,7 @@ const SHIPPED_REFRESHABLE = ['claude-sglang', 'claude-sglang-tui',];const SHIPPED_NOT_REFRESHABLE = [- 'claude-code-tui', 'claude-code-tui-bedrock',+ 'claude-code-tui-bedrock',// #8034 moved this one OUT of the refreshable set on purpose. It is// `command: 'claude'` like the subscription record, so it matched the// anthropic row and a refresh overwrote its `global.anthropic.*` /@@ -264,7 +265,7 @@ describe('resolveModelFetcher — the TUI arm never consults the display name',it('ignores a vendor name on a TUI — the asymmetry with the CLI arm is deliberate', () => {expect(resolveModelFetcher({ id: 'x', type: 'tui', command: '/usr/bin/weird', name: 'Antigravity Nightly' })).toBeNull();- expect(resolveModelFetcher({ id: 'x', type: 'tui', command: 'claude', name: 'Claude Code TUI' })).toBeNull();+ expect(resolveModelFetcher({ id: 'x', type: 'tui', command: 'example-tui', name: 'Claude Code TUI' })).toBeNull();});});@@ -376,10 +377,10 @@ describe('claude records pointed at a third-party backend', () => {// record, so it matched the anthropic row and a Refresh overwrote its// `global.anthropic.*` / `us.anthropic.*` ids with first-party ones its// endpoint rejects — stranding its own `defaultModel` outside its model list.- it('resolves to NO fetcher so the card offers no Refresh button', () => {+ it.each(['cli', 'tui'])('resolves a third-party %s to NO fetcher', (type) => {const bedrock = {id: 'claude-code-bedrock',- type: 'cli',+ type,command: 'claude',name: 'Claude Code CLI: Bedrock',envVars: { CLAUDE_CODE_USE_BEDROCK: '1' },diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.jsindex 1b315b77aa..14623d2bfb 100644--- a/server/lib/aiToolkit/providers.test.js+++ b/server/lib/aiToolkit/providers.test.js@@ -1340,14 +1340,14 @@ describe('Provider Service', () => {});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+ // An unknown TUI provider has 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',+ name: 'Example TUI',type: 'tui',- command: 'claude',- models: ['claude-opus-4-8'],+ command: 'example-tui',+ models: ['example-model'],});const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});@@ -1359,7 +1359,7 @@ describe('Provider Service', () => {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']);+ expect(after.models).toEqual(['example-model']);});it('returns null only for a provider that does not exist', async () => {@@ -1622,7 +1622,7 @@ describe('Provider Service', () => {PATH: `${binDir}${delimiter}${process.env.PATH || ''}`,});- it.skipIf(process.platform === 'win32')('refreshes a claude-commanded provider from the cached catalog, not the antigravity sentinel', async () => {+ it.skipIf(process.platform === 'win32').each(['cli', 'tui'])('refreshes a claude %s provider from the cached catalog', async (type) => {const configDir = await writeClaudeCatalog([{ id: 'fixture-alpha', name: 'fixture-alpha', section: 'main' },{ id: 'fixture-beta', name: 'fixture-beta', section: 'main' },@@ -1630,7 +1630,7 @@ describe('Provider Service', () => {const binDir = await writeFakeClaude('2.1.280 (Claude Code)');const p = await providerService.createProvider({name: 'Claude via Antigravity',- type: 'cli',+ type,command: 'claude',models: ['x'],envVars: claudeEnv(configDir, binDir),diff --git a/server/routes/providers.js b/server/routes/providers.jsindex a60a944fd9..ff4dba8307 100644--- a/server/routes/providers.js+++ b/server/routes/providers.js@@ -1212,7 +1212,7 @@ export function createPortOSProviderRoutes(aiToolkit) {// probe onto the record alone leaves that catalog stale, so the next// derivation discards what was found — refresh the service instead, which// re-derives every preset on it.- const { service } = await refreshServiceCatalog(stored.serviceId);+ const { service } = await refreshServiceCatalog(stored.serviceId, { resetPresetId: stored.id });if (service.catalog?.state === 'failed') {throw new ServerError(service.catalog.error || 'The service could not list its models; its catalog was preserved.', { status: 502 });}diff --git a/server/routes/providers.services.test.js b/server/routes/providers.services.test.jsindex 34ff6214d2..5abe015dcb 100644--- a/server/routes/providers.services.test.js+++ b/server/routes/providers.services.test.js@@ -339,6 +339,32 @@ describe('POST /api/providers/services/:slug/refresh-catalog', () => {expect(failed.body.error).toContain('not installed');});+ it('replaces only the refreshed preset narrowing, preserving it on failure and on service refresh', async () => {+ const preset = { id: 'example-claude-cli', name: 'Example Claude', type: 'cli', command: 'claude', models: ['claude-example'], catalogNarrowing: ['claude-example'], harnessId: 'claude', method: 'cli', serviceId: 'claude-subscription' };+ const sibling = { ...preset, id: 'example-claude-sibling' };+ providerService.getAllProviders.mockResolvedValue({ providers: [preset, sibling] });+ providerService.getProviderById.mockResolvedValue(preset);+ harnessModels.mockResolvedValue({ ok: false, reason: 'Catalog unavailable' });+ expect((await request(app()).post(`/api/providers/${preset.id}/refresh-models`)).status).toBe(502);+ for (const [patches] of providerService.applyProviderPatches.mock.calls) {+ expect(patches[preset.id]?.catalogNarrowing).not.toBeNull();+ }++ harnessModels.mockResolvedValue({ ok: true, models: ['claude-new', 'claude-example'] });+ providerService.applyProviderPatches.mockClear();+ expect((await request(app()).post('/api/providers/services/claude-subscription/refresh-catalog')).status).toBe(200);+ for (const [patches] of providerService.applyProviderPatches.mock.calls) {+ expect(patches[preset.id]?.catalogNarrowing).not.toBeNull();+ }++ providerService.applyProviderPatches.mockClear();+ expect((await request(app()).post(`/api/providers/${preset.id}/refresh-models`)).status).toBe(200);+ const patches = Object.assign({}, ...providerService.applyProviderPatches.mock.calls.map(([value]) => value));+ expect(patches[preset.id]).toMatchObject({ models: ['claude-new', 'claude-example'], catalogNarrowing: null });+ expect(patches[sibling.id]?.catalogNarrowing).not.toBeNull();+ expect(patches[sibling.id]?.models ?? sibling.models).toEqual(['claude-example']);+ });+it('refuses a row with no definition to list through, and 404s an unknown slug', async () => {const res = await request(app()).post(`/api/providers/services/${LEGACY}/refresh-catalog`);expect(res.status).toBe(409);diff --git a/server/services/providerGraph.js b/server/services/providerGraph.jsindex 606db34bc1..d299ce0f86 100644--- a/server/services/providerGraph.js+++ b/server/services/providerGraph.js@@ -313,9 +313,10 @@ async function backfillPresets(graph, providers) {* @param {object} connection - the row as saved* @param {{providerIds?: string[]|null}} [options] - the derived presets to re-derive* ONTO this row (a binding that just moved here), instead of the ones already naming it+ * @param {string|null} [options.resetPresetId] preset whose explicit refresh clears its model narrowing* @returns {Promise<string[]>} the preset ids rewritten*/-export async function rematerializeDerivedPresets(connection, { providerIds = null } = {}) {+export async function rematerializeDerivedPresets(connection, { providerIds = null, resetPresetId = null } = {}) {const instance = instanceForConnection(connection);if (!instance) return [];const [{ providers }, bootstraps] = await Promise.all([providerService().getAllProviders(), bootstrapApps()]);@@ -323,7 +324,10 @@ export async function rematerializeDerivedPresets(connection, { providerIds = nuconst patches = {};for (const record of providers) {if (!isDerivedPreset(record) || !onRow(record)) continue;- const patch = rederivePreset(record, { instance, catalog: connection.catalog, bootstraps })?.patch;+ // A preset refresh explicitly replaces its model list. Service refreshes+ // and sibling presets retain their declared narrowing.+ const candidate = record.id === resetPresetId ? { ...record, catalogNarrowing: null } : record;+ const patch = rederivePreset(candidate, { instance, catalog: connection.catalog, bootstraps, stored: record })?.patch;if (patch && Object.keys(patch).length > 0) patches[record.id] = patch;}if (Object.keys(patches).length === 0) return [];diff --git a/server/services/providerServices.js b/server/services/providerServices.jsindex 6bd711ffe3..61ddc16e3e 100644--- a/server/services/providerServices.js+++ b/server/services/providerServices.js@@ -251,10 +251,11 @@ export async function updateService(ref, input) {* (OpenCode Zen `free` keeps only `*-free`). Then `nextConnectionCatalog`'s* contract holds unchanged: a failure keeps what was known with a sanitized* reason, a successful empty answer is `known` and empty. No pin, default or- * route model list is touched.+ * default is changed. Derived model lists follow the refreshed catalog; only+ * an explicit preset refresh (`resetPresetId`) clears that preset's narrowing.*/export function refreshServiceCatalog(ref, deps = {}) {- const { env, probe, harnessModels, routeModels, now } = { ...defaultDeps(), ...deps };+ const { env, probe, harnessModels, routeModels, now, resetPresetId = null } = { ...defaultDeps(), ...deps };return serializeProviderGraph(async () => {requireProviderGraph();const [graph, envFile] = await Promise.all([readGraph(), loadInstallEnvFile()]);@@ -275,7 +276,9 @@ export function refreshServiceCatalog(ref, deps = {}) {const revision = await saveConnectionSettings({ ...connection, catalog });// A derived preset's `models` is this catalog narrowed (#7565): a listing// that changed reaches every preset on the instance in the same request.- await rematerializeDerivedPresets({ ...connection, catalog, revision: revision ?? connection.revision });+ await rematerializeDerivedPresets({ ...connection, catalog, revision: revision ?? connection.revision }, {+ resetPresetId: outcome.refreshed ? resetPresetId : null,+ });console.log(`🔗 Refreshed service ${connection.slug ?? connection.id} catalog via ${definition.catalog.strategy}: `+ `${catalog.state}, ${catalog.models.length} models`);