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 (codex): honor pinned provider before active-provider availability gate

[._.]/ Adam Eivy7d2b17b9234a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1d3f1b8c21..6f8b5c055d 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,7 +6,7 @@
## Changed
-- **CoS system jobs can now pin their own AI provider + model** — Each autonomous "System Task" (Chief of Staff → Jobs) gains an optional **AI Provider & Model** picker in its create and edit forms, so a heavy refactor job can run on Opus while a lightweight triage job runs on a cheaper/local model — independently, per job, instead of every job inheriting the single active provider. The override is forwarded into the generated task's metadata on both the scheduled and manual-trigger paths, where the agent runner already honors `metadata.provider`/`metadata.model`. Leaving the picker on its defaults preserves the prior behavior (active provider, per-task model selection). Only AI-agent jobs show the picker; shell/script jobs never reach the AI runner. (`client/src/components/cos/tabs/JobsTab.jsx`, `server/services/autonomousJobs/crud.js`, `server/services/autonomousJobs/skillTemplates.js`, `server/routes/cosJobRoutes.js`, `server/lib/validation.js`)
+- **CoS system jobs can now pin their own AI provider + model** — Each autonomous "System Task" (Chief of Staff → Jobs) gains an optional **AI Provider & Model** picker in its create and edit forms, so a heavy refactor job can run on Opus while a lightweight triage job runs on a cheaper/local model — independently, per job, instead of every job inheriting the single active provider. The override is forwarded into the generated task's metadata on both the scheduled and manual-trigger paths, where the agent runner already honors `metadata.provider`/`metadata.model`. Leaving the picker on its defaults preserves the prior behavior (active provider, per-task model selection). Only AI-agent jobs show the picker; shell/script jobs never reach the AI runner. A pinned provider is now resolved *before* the active-provider availability gate, so a job pinned to a healthy provider runs even when the globally active provider is down or unset. (`client/src/components/cos/tabs/JobsTab.jsx`, `server/services/autonomousJobs/crud.js`, `server/services/autonomousJobs/skillTemplates.js`, `server/services/agentProviderResolution.js`, `server/routes/cosJobRoutes.js`, `server/lib/validation.js`)
- **LoRA captioning now guarantees a vision model, lets you pick it, and can pull from your gallery** — Auto-captioning a training dataset used to silently send images to whatever model the local backend defaulted to; a text-only model would fail every image with a cryptic `Model does not support images` 400. The captioner now resolves (and validates) a **vision-capable** model up front: it auto-picks the first installed vision model across Ollama + LM Studio, and fails the whole run with one actionable message if none is installed — instead of N per-image errors. A new **caption-model picker** on the dataset workbench lists your installed vision models (each tagged with its backend) and persists the choice to `settings.loraTraining`, so "Caption all" and per-image re-caption both use it; "Auto" defers to the auto-pick. Vision capability is detected from explicit backend metadata when available (LM Studio's `type: 'vlm'`, Ollama's `vision` capability) and an id heuristic otherwise (`isVisionModel`, mirrored client-side). And a new **"From gallery"** button imports images you've already generated/saved straight into the dataset (multi-select, copied independently so deleting the gallery original won't strand the dataset). (`server/lib/localModelHeuristics.js`, `server/services/loraDatasetCaption.js`, `server/services/loraDatasets.js`, `server/services/localLlm.js`, `client/src/components/loraTraining/CaptionModelPicker.jsx`, `client/src/components/loraTraining/ImportGalleryDialog.jsx`)
diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.js
index 1d71b7789e..dbe8ba6f32 100644
--- a/server/services/agentProviderResolution.js
+++ b/server/services/agentProviderResolution.js
@@ -28,7 +28,24 @@ import { selectModelForTask } from './agentModelSelection.js';
* >}
*/
export async function resolveAgentProviderAndModel(task) {
- let provider = await getActiveProvider();
+ // A task can pin a specific provider via metadata.provider (e.g. a CoS job's
+ // per-job AI override). Resolve it BEFORE the active-provider availability
+ // gate so a pinned-but-healthy provider isn't blocked when the *active*
+ // provider is down or unset — independence from the active provider is the
+ // whole point of pinning. The pinned provider then runs through the same
+ // availability/fallback logic below as any other resolved provider.
+ let provider = null;
+ const userProviderId = task.metadata?.provider;
+ if (userProviderId) {
+ const userProvider = await getProviderById(userProviderId);
+ if (userProvider) {
+ emitLog('info', `Using user-specified provider: ${userProviderId}`, { taskId: task.id });
+ provider = userProvider;
+ } else {
+ emitLog('warn', `User-specified provider "${userProviderId}" not found, using active provider`, { taskId: task.id });
+ }
+ }
+ if (!provider) provider = await getActiveProvider();
if (!provider) {
return { ok: false, error: 'No active AI provider configured' };
@@ -72,22 +89,6 @@ export async function resolveAgentProviderAndModel(task) {
}
}
- // Check if user specified a different provider in task metadata
- const userProviderId = task.metadata?.provider;
- if (userProviderId && userProviderId !== provider.id) {
- const userProvider = await getProviderById(userProviderId);
- if (userProvider) {
- emitLog('info', `Using user-specified provider: ${userProviderId}`, { taskId: task.id });
- provider = userProvider;
- // The fallback pin belonged to the fallback provider we just replaced —
- // it must not carry onto the user's explicitly chosen provider, which
- // gets its own normal model selection.
- fallbackModelPin = null;
- } else {
- emitLog('warn', `User-specified provider "${userProviderId}" not found, using active provider`, { taskId: task.id });
- }
- }
-
// Select optimal model for this task (async to allow learning-based suggestions)
const modelSelection = await selectModelForTask(task, provider);
let selectedModel = modelSelection.model;
diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.js
index 1a6aa0a4cd..384f948b31 100644
--- a/server/services/agentProviderResolution.test.js
+++ b/server/services/agentProviderResolution.test.js
@@ -99,6 +99,35 @@ describe('resolveAgentProviderAndModel', () => {
expect(r.selectedModel).toBe('m-default');
});
+ it('honors a pinned provider before the active-provider availability gate', async () => {
+ // The active provider is down, but the task pins a different, healthy
+ // provider. The pin must win without the active provider's unavailability
+ // ever blocking the task (regression: the override used to run after the
+ // active-provider availability check, so a pinned-but-healthy provider
+ // still failed when the active one was down).
+ const active = { id: 'p-active', type: 'api' };
+ const chosen = { id: 'p-user', type: 'api', models: ['m-default'] };
+ getActiveProvider.mockResolvedValue(active);
+ getProviderById.mockResolvedValue(chosen);
+ isProviderAvailable.mockImplementation((id) => id === 'p-user'); // active down, pinned up
+
+ const r = await resolveAgentProviderAndModel({ id: 't', metadata: { provider: 'p-user' } });
+ expect(r.ok).toBe(true);
+ expect(r.provider).toBe(chosen);
+ expect(r.selectedModel).toBe('m-default');
+ expect(getFallbackProvider).not.toHaveBeenCalled();
+ });
+
+ it('honors a pinned provider even when no active provider is configured', async () => {
+ const chosen = { id: 'p-user', type: 'api', models: ['m-default'] };
+ getActiveProvider.mockResolvedValue(null); // no active provider at all
+ getProviderById.mockResolvedValue(chosen);
+
+ const r = await resolveAgentProviderAndModel({ id: 't', metadata: { provider: 'p-user' } });
+ expect(r.ok).toBe(true);
+ expect(r.provider).toBe(chosen);
+ });
+
it('falls back to the provider tier default when the selected model is not in the provider model list', async () => {
const provider = { id: 'p1', type: 'api', models: ['only-this'], heavyModel: 'heavy-x' };
getActiveProvider.mockResolvedValue(provider);