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

fix: drop a task's model pin when provider fallback swaps to another provider

[._.]/ Adam Eivy0441d913d8c1
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 33be8d42de..f08b41aa04 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -13,3 +13,8 @@
- **Foundation repair distinguishes a deeper critique from a stalled rewrite.** When a harsh re-judge holds a dimension at the same coarse score but identifies a genuinely different underlying gap, that new layer receives its own bounded repair window. Fuzzy-matched paraphrases of the same problem still accrue toward the divergence guard, so the loop remains finite instead of pausing simply because one successful fix exposed the next weakness.
- **Continuing a video carries its prompt forward.** Continuing or extending a clip we generated now prefills the Video Gen prompt (and negative prompt) with the one that produced the source, instead of dropping you into an empty box. This covers both entry points: the **Continue** action on a video card/lightbox, and picking a prior render in Extend mode. Text you typed yourself is never overwritten — only a blank box or a value an earlier pick filled — and a clip we didn't generate (an import, or a legacy render with no stored prompt) leaves the field alone rather than clearing it. The style preset is dropped along with the prefill, since history stores the already-composed prompt and re-applying a preset would prefix it twice.
- **Subscription Usage cards now lay out in four quadrants.** The provider quota grid orders Claude, Antigravity, Codex, Grok — and because Codex and Grok typically report only a single weekly meter, they now share one grid cell stacked vertically instead of each stretching to a full-height card. Cards render at their natural height, so the Image Gen card floats into the fourth quadrant and the whole section fits above the fold on desktop.
+
+## Fixed
+
+- **A provider outage no longer hands a CoS task's model pin to a provider that can't run it.** A task pinned to Antigravity with `gemini-3.6-flash` hit an auth outage on that provider; the fallback chain correctly swapped it onto the Claude CLI but carried the Antigravity model id along, so every retry spawned `claude --model gemini-3.6-flash` and died in ~1.5s ("There's an issue with the selected model") until the task exhausted its retries and blocked. The pass-through exemption that let it through is deliberate — it exists so an explicit pin isn't silently downgraded to the provider's heaviest default just because the provider's `models` list spells an alias differently — but it only makes sense on the provider the pin was chosen *for*. A `metadata.model` pin is provider-scoped (the task form picks a provider, then a model from that provider's catalog), so a fallback swap now drops it back to the new provider's own default unless that provider actually lists it, logging the substitution rather than doing it silently. A swap between siblings that both serve the pinned id (claude-code ↔ claude-code-tui) still keeps it, and a run with no swap at all is untouched. The check also covers a fallback provider that enumerates no models, which the existing model-list validation could not inspect at all.
+- **The Claude CLI's own model rejection is now a recognized, actionable failure.** "There's an issue with the selected model (…)" is printed by the CLI at startup, before any API call, so it carries no `API Error: 4NN` token and matched none of the model-error patterns. It landed in the `unknown` bucket with "Error did not match known patterns" — which autoFixer maps to Tier 4 (escalate), so a task with a bad model id burned all three retries against an id that could never work and then spent an agent run on an investigation task. It now classifies as `model-not-found` with the rejected id extracted from the message, putting it in Tier 1 (config/env) where a model correction belongs. Promoted to a structured `provider`-origin signal, since the full banner with the parenthesised id and the `--model` hint is CLI text rather than something a task's own output prints in passing.
diff --git a/server/services/agentErrorAnalysis.js b/server/services/agentErrorAnalysis.js
index 1627808d61..32581689f9 100644
--- a/server/services/agentErrorAnalysis.js
+++ b/server/services/agentErrorAnalysis.js
@@ -132,6 +132,30 @@ export const ERROR_PATTERNS = [
configuredModel: model
})
},
+ {
+ // The Claude Code CLI's own startup rejection of `--model <id>`, printed
+ // before any API call is made — so it never carries an `API Error: 4NN`
+ // token and matched none of the model patterns above. Untriaged it landed in
+ // the `unknown` bucket ("Error did not match known patterns"), which is Tier
+ // 4 (escalate) in autoFixer's map: the task burned all three retries against
+ // an id that can never work and then spawned an investigation task, instead
+ // of getting the Tier 1 config/env correction a model rejection deserves.
+ // Structured enough to promote to `origin: 'provider'` — the full sentence
+ // with the parenthesised id and the `--model` hint is CLI banner text, not
+ // something a task's own output prints in passing.
+ pattern: /There's an issue with the selected model \(([^)]+)\)/i,
+ category: 'model-not-found',
+ actionable: true,
+ origin: 'provider',
+ structuredMarker: /There's an issue with the selected model \([^)]+\)[\s\S]{0,120}?(?:may not exist|--model)/i,
+ escalation: 'Set a model id this provider actually serves for the task (or clear its model override so the CLI uses its own default), then approve the retry.',
+ extract: (match, output, task, model) => ({
+ message: `Model "${match[1]}" rejected by the CLI - it may not exist or the account lacks access`,
+ suggestedFix: `The CLI does not accept "${match[1]}". Check that the task's model override matches the provider it is running on, or clear the override so the CLI falls back to its own default.`,
+ affectedModel: match[1],
+ configuredModel: model
+ })
+ },
{
pattern: /API Error: 401|authentication|unauthorized/i,
category: 'auth-error',
diff --git a/server/services/agentErrorAnalysis.test.js b/server/services/agentErrorAnalysis.test.js
index 150dd9e567..57d6dfb2bc 100644
--- a/server/services/agentErrorAnalysis.test.js
+++ b/server/services/agentErrorAnalysis.test.js
@@ -121,6 +121,24 @@ describe('analyzeAgentFailure — ERROR_PATTERNS classification', () => {
expect(analysis.actionable).toBe(true);
});
+ it("classifies the Claude CLI's own \"issue with the selected model\" rejection as model-not-found", () => {
+ // Regression: this is the CLI's startup rejection of `--model <id>`, printed
+ // before any API call — so no `API Error: 4NN` token, and it matched none of
+ // the model patterns. It fell into `unknown` ("did not match known
+ // patterns"), which autoFixer maps to Tier 4 (escalate): the task burned all
+ // three retries and spawned an investigation instead of getting the Tier 1
+ // config/env model correction it deserved.
+ const output = withLead("There's an issue with the selected model (gemini-3.6-flash). It may not exist or you may not have access to it. Run --model to pick a different model.");
+ const analysis = analyzeAgentFailure(output, { id: 't' }, 'gemini-3.6-flash');
+ expect(analysis.category).toBe('model-not-found');
+ expect(analysis.actionable).toBe(true);
+ // Distinctive CLI banner text, not something a task's own output prints.
+ expect(analysis.origin).toBe('provider');
+ // The rejected id is extracted from the message, not just echoed from config.
+ expect(analysis.affectedModel).toBe('gemini-3.6-flash');
+ expect(analysis.message).toContain('gemini-3.6-flash');
+ });
+
it('classifies a 401/authentication error as actionable auth-error', () => {
const analysis = analyzeAgentFailure(withLead('API Error: 401 Unauthorized — authentication failed'), { id: 't' }, 'x');
expect(analysis.category).toBe('auth-error');
diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.js
index 403d1ac31b..7145c472c9 100644
--- a/server/services/agentProviderResolution.js
+++ b/server/services/agentProviderResolution.js
@@ -61,6 +61,10 @@ export async function resolveAgentProviderAndModel(task) {
// and stays retryable; but an api primary whose fallback is also api (directType
// 'api') can never gain a harness, so it stays permanent (no infinite retry).
const directProviderType = provider.type;
+ // Id of that same DIRECTLY-resolved provider — the one a `task.metadata.model`
+ // pin was chosen FOR. Compared against `provider.id` after the fallback block
+ // to detect a provider swap, which invalidates the pin (see below).
+ const directProviderId = provider.id;
// Check provider availability (usage limits, rate limits, etc.)
// Set when we fall back below to a provider with a configured "Fallback
// Model" pin — it overrides the usual per-task model selection so the
@@ -153,7 +157,33 @@ export async function resolveAgentProviderAndModel(task) {
// the provider reject a genuine typo at runtime. Auto-selected models (and a
// fallback-model pin, which the comment above deliberately guards) still fall
// back to the provider's tier default.
- const isUserPinnedModel = modelSelection.tier === 'user-specified' && !fallbackModelPin;
+ //
+ // …but ONLY on the provider the pin was chosen for. A `task.metadata.model`
+ // pin is provider-scoped (the task form picks a provider and then a model from
+ // THAT provider's catalog) — it is not a provider-agnostic preference. When
+ // the pinned/active provider is down and the fallback block above swapped us
+ // onto a different provider, the pin no longer describes anything the new
+ // provider can run, and the pass-through exemption — which deliberately skips
+ // the model list — is exactly what stops us from noticing. That combination
+ // shipped `claude --model gemini-3.6-flash` after an `antigravity-tui` auth
+ // outage: the CLI rejected it in ~1.5s ("There's an issue with the selected
+ // model"), on every retry, until the task hit max retries and blocked. So a
+ // provider swap drops the pin back to the new provider's own default unless
+ // that provider actually lists it.
+ const providerSwapped = provider.id !== directProviderId;
+ const isUserPin = modelSelection.tier === 'user-specified' && !fallbackModelPin;
+ const isUserPinnedModel = isUserPin && !providerSwapped;
+ if (isUserPin && providerSwapped && !(provider.models || []).includes(selectedModel)) {
+ // Handled here rather than left to the list check below, which can't fire at
+ // all for a fallback provider that enumerates no `models`.
+ emitLog('warn', `Dropping model "${selectedModel}" pinned for unavailable provider "${directProviderId}" — running on fallback "${provider.id}" with its default model`, {
+ taskId: task.id,
+ requestedModel: selectedModel,
+ pinnedProviderId: directProviderId,
+ providerId: provider.id
+ });
+ selectedModel = provider.defaultModel || null;
+ }
if (selectedModel && provider.models && provider.models.length > 0) {
const modelIsValid = provider.models.includes(selectedModel);
if (!modelIsValid && isUserPinnedModel) {
diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.js
index a7de3eceb3..8a20511576 100644
--- a/server/services/agentProviderResolution.test.js
+++ b/server/services/agentProviderResolution.test.js
@@ -237,6 +237,79 @@ describe('resolveAgentProviderAndModel', () => {
expect(r.permanent).toBe(true);
});
+ it('drops a user model pin when a fallback swap moved the task onto a DIFFERENT provider', async () => {
+ // Regression: a task pinned provider `antigravity-tui` + model
+ // `gemini-3.6-flash`. That provider hit an auth outage, the fallback chain
+ // swapped to `claude-code`, and the CLI-pass-through exemption honored the
+ // now-meaningless pin — shipping `claude --model gemini-3.6-flash`, which the
+ // CLI rejects instantly on every retry until the task blocks.
+ const pinned = { id: 'antigravity-tui', type: 'tui', models: ['gemini-3.6-flash-high'] };
+ const fallback = { id: 'claude-code', type: 'cli', models: ['claude-opus-5', 'claude-sonnet-5'], defaultModel: 'claude-sonnet-5' };
+ getProviderById.mockResolvedValue(pinned);
+ getActiveProvider.mockResolvedValue(pinned);
+ isProviderAvailable.mockReturnValue(false);
+ getProviderStatus.mockReturnValue({ message: 'auth-error', reason: 'auth-error' });
+ getAllProviders.mockResolvedValue({ providers: [pinned, fallback] });
+ // No configured fallback MODEL pin — the case that let the stale pin through.
+ getFallbackProvider.mockResolvedValue({ provider: fallback, model: null, source: 'system' });
+ selectModelForTask.mockResolvedValue({ model: 'gemini-3.6-flash', tier: 'user-specified', reason: 'user-preference' });
+
+ const r = await resolveAgentProviderAndModel({
+ id: 't', metadata: { provider: 'antigravity-tui', model: 'gemini-3.6-flash' }
+ });
+ expect(r.ok).toBe(true);
+ expect(r.provider).toBe(fallback);
+ expect(r.selectedModel).toBe('claude-sonnet-5'); // NOT the antigravity pin
+ });
+
+ it('drops a swap-invalidated pin even when the fallback provider enumerates no models', async () => {
+ // The model-list check can't fire at all here, so the swap guard must own it.
+ const pinned = { id: 'antigravity-tui', type: 'tui', models: ['gemini-3.6-flash-high'] };
+ const fallback = { id: 'opencode', type: 'cli', defaultModel: 'oc-default' }; // no `models`
+ getActiveProvider.mockResolvedValue(pinned);
+ getProviderById.mockResolvedValue(pinned);
+ isProviderAvailable.mockReturnValue(false);
+ getProviderStatus.mockReturnValue({ message: 'down', reason: 'x' });
+ getAllProviders.mockResolvedValue({ providers: [pinned, fallback] });
+ getFallbackProvider.mockResolvedValue({ provider: fallback, model: null, source: 'system' });
+ selectModelForTask.mockResolvedValue({ model: 'gemini-3.6-flash', tier: 'user-specified', reason: 'user-preference' });
+
+ const r = await resolveAgentProviderAndModel({
+ id: 't', metadata: { provider: 'antigravity-tui', model: 'gemini-3.6-flash' }
+ });
+ expect(r.ok).toBe(true);
+ expect(r.selectedModel).toBe('oc-default');
+ });
+
+ it('keeps a user model pin across a swap when the fallback provider DOES list it', async () => {
+ // Sibling providers share ids (claude-code / claude-code-tui) — a swap between
+ // them must not throw away a pin the new provider can honor.
+ const pinned = { id: 'claude-code', type: 'cli', models: ['claude-opus-5'] };
+ const fallback = { id: 'claude-code-tui', type: 'tui', models: ['claude-opus-5'], defaultModel: 'claude-sonnet-5' };
+ getActiveProvider.mockResolvedValue(pinned);
+ isProviderAvailable.mockReturnValue(false);
+ getProviderStatus.mockReturnValue({ message: 'down', reason: 'x' });
+ getAllProviders.mockResolvedValue({ providers: [pinned, fallback] });
+ getFallbackProvider.mockResolvedValue({ provider: fallback, model: null, source: 'system' });
+ selectModelForTask.mockResolvedValue({ model: 'claude-opus-5', tier: 'user-specified', reason: 'user-preference' });
+
+ const r = await resolveAgentProviderAndModel({ id: 't', metadata: { model: 'claude-opus-5' } });
+ expect(r.ok).toBe(true);
+ expect(r.selectedModel).toBe('claude-opus-5');
+ });
+
+ it('still honors an out-of-list user pin when NO provider swap happened', async () => {
+ // Guards the swap fix against over-reach: the CLI pass-through exemption must
+ // survive for the unavailable-provider-recovered / no-fallback path.
+ const provider = { id: 'claude-code', type: 'cli', models: ['claude-opus-5'], defaultModel: 'claude-opus-5' };
+ getActiveProvider.mockResolvedValue(provider);
+ isProviderAvailable.mockReturnValue(true);
+ selectModelForTask.mockResolvedValue({ model: 'claude-haiku-4-5', tier: 'user-specified', reason: 'user-preference' });
+
+ const r = await resolveAgentProviderAndModel({ id: 't', metadata: { model: 'claude-haiku-4-5' } });
+ expect(r.selectedModel).toBe('claude-haiku-4-5');
+ });
+
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: 'cli', models: ['only-this'], heavyModel: 'heavy-x' };
getActiveProvider.mockResolvedValue(provider);