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
address review (agy): strip a model pin the posture swap orphaned, and keep the actions picker populated when the daemon is down
[._.]/ Adam Eivy91c24e95439c
diff --git a/client/src/components/cos/tabs/schedule/PipelineStageConfig.jsx b/client/src/components/cos/tabs/schedule/PipelineStageConfig.jsxindex 9439fd32d4..260659c0ac 100644--- a/client/src/components/cos/tabs/schedule/PipelineStageConfig.jsx+++ b/client/src/components/cos/tabs/schedule/PipelineStageConfig.jsx@@ -170,12 +170,23 @@ export default function PipelineStageConfig({ taskType, config, providers, provi// there let a stage be pinned to a model the daemon no longer serves,// and hid one that had just been pulled. Every other provider uses its// own catalog, so a cloud CLI stage can pick any model it offers.- const stageModels = posture && localBackend- ? localModelIds.map(id => ({- id,- name: id,- capabilities: capabilitiesByBackend?.[localBackend]?.[id],- }))+ //+ // `useLocalModels` reports BOTH "not fetched yet" and "daemon said+ // nothing" as `[]`, so an empty list is not evidence the daemon serves+ // no models. The two stages part ways on what to do about that. The+ // tool-free gate must stay strict: its policy needs a probeable+ // capability report, and a model with none is not selectable at all,+ // so an empty list correctly offers nothing. The actions stage has no+ // such gate, so it falls back to the record's catalog — otherwise a+ // stopped daemon (or the in-flight window) renders an empty picker and+ // drops the stage's own saved pin out of the dropdown.+ const localStageModels = localModelIds.map(id => ({+ id,+ name: id,+ capabilities: capabilitiesByBackend?.[localBackend]?.[id],+ }));+ const stageModels = posture && localBackend && (isNoToolStage || localStageModels.length > 0)+ ? localStageModels: effortAwareModelOptions(stageProvider, stage.model);const selectionPolicy = posture ? selectionPolicies[posture] : undefined;const stageProviderId = stage.providerId || '';diff --git a/client/src/components/cos/tabs/schedule/PipelineStageConfig.test.jsx b/client/src/components/cos/tabs/schedule/PipelineStageConfig.test.jsxindex 14d337aa53..fbadc00fe2 100644--- a/client/src/components/cos/tabs/schedule/PipelineStageConfig.test.jsx+++ b/client/src/components/cos/tabs/schedule/PipelineStageConfig.test.jsx@@ -1,21 +1,30 @@-import { describe, expect, it, vi } from 'vitest';+import { beforeEach, describe, expect, it, vi } from 'vitest';import { fireEvent, render, screen, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router';-vi.mock('../../../../hooks/useLocalModels', () => ({- default: () => ({- ollama: ['safe-model', 'tool-model'],- lmstudio: [],- capabilitiesByBackend: {- ollama: {- 'safe-model': ['chat'],- 'tool-model': ['chat', 'tools'],- },+// The installed-local-model report, mutable so a test can model a daemon that+// is stopped or still loading (both of which `useLocalModels` reports as `[]`).+const INSTALLED_LOCAL_MODELS = {+ ollama: ['safe-model', 'tool-model'],+ lmstudio: [],+ capabilitiesByBackend: {+ ollama: {+ 'safe-model': ['chat'],+ 'tool-model': ['chat', 'tools'],},- loading: false,- }),+ },+ loading: false,+};+let localModels = { ...INSTALLED_LOCAL_MODELS };++vi.mock('../../../../hooks/useLocalModels', () => ({+ default: () => localModels,}));+beforeEach(() => {+ localModels = { ...INSTALLED_LOCAL_MODELS };+});+import PipelineStageConfig from './PipelineStageConfig';const STAGES = [@@ -261,3 +270,51 @@ describe('PipelineStageConfig — posture-driven eligibility', () => {expect([...modelSelects[1].options].map((o) => o.value)).toEqual(['', 'safe-model', 'tool-model']);});});++// `useLocalModels` reports "not fetched yet" and "the daemon listed nothing"+// identically, as `[]` — so an empty list is not evidence the daemon serves no+// models. The actions stage has no capability gate, so it must fall back to the+// record's catalog rather than render an empty picker that also drops the+// stage's own saved pin. The tool-free gate deliberately does NOT: a model with+// no probeable capability report is not selectable there at all.+describe('PipelineStageConfig — local daemon unreachable', () => {+ const LOCAL = {+ id: 'opencode-ollama-tui',+ name: 'OpenCode Ollama TUI',+ type: 'tui',+ command: 'opencode',+ models: ['cached-a', 'cached-b'],+ publicReviewPostures: ['no-tool', 'sandboxed-actions'],+ publicReviewEnforcedPostures: ['no-tool'],+ };++ it('falls back to the record catalog for the actions stage, but not for the gate', () => {+ localModels = { ollama: [], lmstudio: [], capabilitiesByBackend: {}, loading: false };+ render(+ <MemoryRouter>+ <PipelineStageConfig+ taskType="pr-reviewer"+ config={{ taskMetadata: { pipeline: { stages: [+ STAGES[0],+ { ...STAGES[1], executionProfile: 'public-review-gate', providerId: 'opencode-ollama-tui', model: 'cached-a' },+ { ...STAGES[2], executionProfile: 'public-review-actions', providerId: 'opencode-ollama-tui', model: 'cached-a' },+ ] } } }}+ providers={[LOCAL]}+ onUpdate={vi.fn().mockResolvedValue(undefined)}+ updating={false}+ setUpdating={() => {}}+ />+ </MemoryRouter>,+ );+ const modelSelects = screen.getAllByLabelText('Model');+ // The gate offers nothing from the catalog — `cached-a` is present only+ // because ProviderModelSelector keeps a disallowed *selected* value visible+ // rather than blanking the control, and `cached-b` proves the list itself+ // was not consulted.+ expect([...modelSelects[0].options].map((o) => o.value)).toEqual(['', 'cached-a']);+ // The actions stage gets the whole record catalog instead of an empty+ // picker that would also drop its own saved pin (nothing re-adds it there:+ // its policy allows every model, so the disallowed affordance never fires).+ expect([...modelSelects[1].options].map((o) => o.value)).toEqual(['', 'cached-a', 'cached-b']);+ });+});diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.jsindex 573d8ad4ca..61f86d46cd 100644--- a/server/services/agentProviderResolution.js+++ b/server/services/agentProviderResolution.js@@ -78,13 +78,19 @@ async function resolvePublicReviewAgentProvider(task, posture) {// `modelPinIsOffered` owns which provider records may invalidate a pin at all// — an empty catalog and a local daemon's cached snapshot are both// pass-throughs (see its doc comment).- const pinRejected = pinnedForThisProvider && !modelPinIsOffered(provider, pinnedModel);- // Strip the rejected pin BEFORE model selection. `selectModelForTask` returns- // `metadata.model` verbatim as its highest-priority answer, so leaving it in- // place handed the CLI the very id just rejected and the warning below- // promised a default the run never used.+ const honorPin = pinnedForThisProvider && modelPinIsOffered(provider, pinnedModel);+ const pinRejected = pinnedForThisProvider && !honorPin;+ // Strip a pin that will NOT be honored, BEFORE model selection.+ // `selectModelForTask` returns `metadata.model` verbatim as its+ // highest-priority answer, so leaving it on the task defeats both guards+ // above: a REJECTED pin came straight back while the warning below promised a+ // default the run never used, and a pin belonging to a DIFFERENT provider+ // (`pinnedForThisProvider` false, after the posture swap above chose someone+ // else) was handed to the new provider — the exact cross-vendor leak this+ // function's header says it prevents. Both are the same "will not be honored"+ // case, so both strip here.const modelSelection = await selectModelForTask(- pinRejected ? { ...task, metadata: { ...task.metadata, model: null } } : task,+ pinnedModel && !honorPin ? { ...task, metadata: { ...task.metadata, model: null } } : task,provider,);if (pinRejected) {@@ -95,7 +101,7 @@ async function resolvePublicReviewAgentProvider(task, posture) {validModels: provider.models,});}- const selectedModel = pinnedForThisProvider && !pinRejected+ const selectedModel = honorPin? pinnedModel: (modelSelection.model || provider.defaultModel || null);emitLog('info', `Public-review stage (${posture}) resolved to provider ${provider.id}${selectedModel ? ` model ${selectedModel}` : ''}`, {diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.jsindex cdb4b80a33..a2f35fff61 100644--- a/server/services/agentProviderResolution.test.js+++ b/server/services/agentProviderResolution.test.js@@ -375,11 +375,25 @@ describe('resolveAgentProviderAndModel — public-review stages', () => {expect(r).toMatchObject({ ok: true, provider: { id: 'codex-cli' } });});+ // `selectModelForTask`'s real precedence: `task.metadata.model` wins outright+ // over everything else. The suite's flat `m-default` default cannot observe a+ // pin that leaks through it, so the tests below that assert a pin was DROPPED+ // install this instead — otherwise they pass no matter what the code does.+ const useRealisticModelSelection = () => selectModelForTask.mockImplementation(async (task, provider) => (+ task?.metadata?.model+ ? { model: task.metadata.model, tier: 'user-specified', reason: 'user-preference' }+ : { model: provider?.defaultModel || 'm-default', tier: 'medium', reason: 'default' }+ ));+it('keeps a model pin only on the provider it was chosen for', async () => {+ useRealisticModelSelection();getAllProviders.mockResolvedValue({ providers: [CODEX, GROK], activeProvider: null });await expect(resolveAgentProviderAndModel(gateTask({ provider: 'grok-cli', model: 'grok-4' }))).resolves.toMatchObject({ provider: { id: 'grok-cli' }, selectedModel: 'grok-4' });// Pinned for a DIFFERENT provider — falls back to that provider's own model.+ // The posture swap above landed on codex-cli, and grok's model id must not+ // ride along with it; leaving the pin on the task let `selectModelForTask`+ // hand it straight back, so the swap silently kept the foreign model.await expect(resolveAgentProviderAndModel(gateTask({ provider: 'opencode', model: 'grok-4' }))).resolves.toMatchObject({ provider: { id: 'codex-cli' }, selectedModel: 'm-default' });});@@ -408,11 +422,7 @@ describe('resolveAgentProviderAndModel — public-review stages', () => {// it was "using its default instead". The mock is given the real precedence// here on purpose; the flat `m-default` default cannot observe the bug.it('does not let model selection hand the rejected pin back', async () => {- selectModelForTask.mockImplementation(async (task, provider) => (- task?.metadata?.model- ? { model: task.metadata.model, tier: 'user-specified', reason: 'user-preference' }- : { model: provider?.defaultModel || 'm-default', tier: 'medium', reason: 'default' }- ));+ useRealisticModelSelection();const CURATED = { id: 'grok-cli', type: 'cli', command: 'grok', models: ['grok-4'], defaultModel: 'grok-4' };getAllProviders.mockResolvedValue({ providers: [CURATED], activeProvider: null });