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: only flag a genuinely weaker learning-tier pick as a downgrade, and cover the public-review path
[._.]/ Adam Eivyf899f7364148
diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.jsindex 216e9f6157..1c66b80ff3 100644--- a/server/services/agentProviderResolution.js+++ b/server/services/agentProviderResolution.js@@ -92,6 +92,38 @@ export async function resolveAgentProviderAndModel(task) {return resolveOrdinaryProviderAndModel(task);}+/**+ * Flags `modelSelection` when the learning system substituted a weaker tier+ * than the provider's configured default for a task that never pinned one —+ * shared by the ordinary and public-review resolution paths (#8148).+ *+ * Only a literal `medium`/`light` `tierToModel` pick counts as "weaker":+ * `selectModelForTask`'s learning branches can also land on `heavy`/`high`/+ * `xhigh` (a stronger tier proven out by history), which must NOT be flagged+ * merely because its model id differs from `provider.defaultModel` — that+ * would mislabel a legitimate upgrade as a downgrade.+ *+ * `selectedModel === modelSelection.model` guards against a DOWNSTREAM+ * override (a fallback-provider model pin, or the invalid-model-list+ * fallback in the ordinary path) silently inheriting this flag: those+ * substitutions happen for reasons unrelated to learning, after+ * `modelSelection` was already decided, and must not be reported as if the+ * learning system chose them.+ */+function flagLearningDowngrade(modelSelection, selectedModel, provider) {+ const isWeakerLearningTier = modelSelection.tier === 'medium' || modelSelection.tier === 'light';+ const downgradedFromDefault = !!modelSelection.isLearningTierOverride+ && isWeakerLearningTier+ && !!provider.defaultModel+ && selectedModel === modelSelection.model+ && selectedModel !== provider.defaultModel;+ if (downgradedFromDefault) {+ modelSelection.downgradedFromDefault = true;+ modelSelection.configuredDefault = provider.defaultModel;+ }+ return downgradedFromDefault;+}+/*** Provider + model for a public-review stage. A stage's own provider/model/* effort pins (`metadata.provider` / `metadata.model`, set by the pipeline@@ -140,10 +172,15 @@ async function resolvePublicReviewAgentProvider(task, posture) {const selectedModel = honorPin? pinnedModel: (modelSelection.model || provider.defaultModel || null);- emitLog('info', `Public-review stage (${posture}) resolved to provider ${provider.id}${selectedModel ? ` model ${selectedModel}` : ''}`, {+ const downgradedFromDefault = flagLearningDowngrade(modelSelection, selectedModel, provider);+ const logMessage = `Public-review stage (${posture}) resolved to provider ${provider.id}${selectedModel ? ` model ${selectedModel}` : ''}`;+ emitLog(downgradedFromDefault ? 'warn' : 'info', downgradedFromDefault+ ? `${logMessage} — differs from provider's configured default "${provider.defaultModel}" (learning system substituted this model)`+ : logMessage, {taskId: task.id,providerId: provider.id,model: selectedModel,+ ...(downgradedFromDefault && { downgradedFromDefault: true, configuredDefault: provider.defaultModel })});return { ok: true, provider, selectedModel, modelSelection };}@@ -374,18 +411,12 @@ async function resolveOrdinaryProviderAndModel(task) {// The learning-based tiers can pick a weaker model than the provider's// configured default without the task ever asking for that — surface it// loudly rather than let "ran on the configured default" and "the learning- // system downgraded it" collapse into the same quiet info log (#8148).- // `isLearningTierOverride` is a fact `selectModelForTask` states at the- // moment it makes the substitution, not re-derived here from `reason`- // string-matching (a proxy a future learning-tier reason could bypass);- // this only re-checks the FINAL model against the default because the- // fallback-model-pin and invalid-model-list branches above can still- // change `selectedModel` after that decision was made.- const downgradedFromDefault = !!modelSelection.isLearningTierOverride && !!provider.defaultModel && selectedModel !== provider.defaultModel;- if (downgradedFromDefault) {- modelSelection.downgradedFromDefault = true;- modelSelection.configuredDefault = provider.defaultModel;- }+ // system downgraded it" collapse into the same quiet info log (#8148). The+ // fallback-model-pin and invalid-model-list branches above can still change+ // `selectedModel` after `modelSelection` was decided, which is exactly what+ // `flagLearningDowngrade`'s `selectedModel === modelSelection.model` guard+ // excludes.+ const downgradedFromDefault = flagLearningDowngrade(modelSelection, selectedModel, provider);const logMessage = modelSelection.learningReason? `Model selection: ${selectedModel} (${modelSelection.reason} - ${modelSelection.learningReason})`diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.jsindex ff7379a496..ce52da6040 100644--- a/server/services/agentProviderResolution.test.js+++ b/server/services/agentProviderResolution.test.js@@ -113,6 +113,40 @@ describe('resolveAgentProviderAndModel', () => {expect(emitLog).toHaveBeenCalledWith('info', expect.any(String), expect.not.objectContaining({ downgradedFromDefault: true }));});+ it('never flags a learning-tier override that picked a STRONGER model than the default (codex #8148 review)', async () => {+ // provider.defaultModel is a light/medium tier here; the learning system+ // proved out the heavy tier for this task type — a legitimate upgrade,+ // not a downgrade, even though the model id obviously differs from+ // provider.defaultModel.+ const provider = { id: 'p1', type: 'cli', defaultModel: 'claude-sonnet-5', heavyModel: 'claude-opus-5-5', models: ['claude-sonnet-5', 'claude-opus-5-5'] };+ getActiveProvider.mockResolvedValue(provider);+ selectModelForTask.mockResolvedValue({ model: 'claude-opus-5-5', tier: 'heavy', reason: 'learning-suggested', isLearningTierOverride: true, learningReason: 'proven high success at heavy' });++ const r = await resolveAgentProviderAndModel(TASK);+ expect(r.selectedModel).toBe('claude-opus-5-5');+ expect(r.modelSelection.downgradedFromDefault).toBeUndefined();+ expect(emitLog).toHaveBeenCalledWith('info', expect.any(String), expect.not.objectContaining({ downgradedFromDefault: true }));+ });++ it('never flags a downgrade when a downstream fallback-model pin replaced the learning selection (codex #8148 review)', async () => {+ // selectModelForTask picks a weaker learning tier, but the provider is+ // unavailable and its configured "Fallback Model" pin (a user choice on+ // the FALLBACK provider) overrides selectedModel afterward — that+ // substitution is unrelated to learning and must not inherit the flag.+ const provider = { id: 'fallback-p', type: 'cli', defaultModel: 'claude-opus-5-5', models: ['claude-opus-5-5', 'claude-sonnet-5', 'pinned-fallback-model'] };+ getActiveProvider.mockResolvedValue({ id: 'primary-p', type: 'cli' });+ isProviderAvailable.mockReturnValue(false);+ getProviderStatus.mockReturnValue({ message: 'down', reason: 'down' });+ getAllProviders.mockResolvedValue({ providers: [{ id: 'primary-p', type: 'cli' }, provider] });+ getFallbackProvider.mockResolvedValue({ provider, source: 'provider-fallback', model: 'pinned-fallback-model' });+ selectModelForTask.mockResolvedValue({ model: 'claude-sonnet-5', tier: 'medium', reason: 'learning-suggested', isLearningTierOverride: true });++ const r = await resolveAgentProviderAndModel(TASK);+ expect(r.selectedModel).toBe('pinned-fallback-model');+ expect(r.modelSelection.downgradedFromDefault).toBeUndefined();+ expect(emitLog).toHaveBeenCalledWith('info', expect.stringContaining('pinned-fallback-model'), expect.not.objectContaining({ downgradedFromDefault: true }));+ });+it('fails with providerId + status when unavailable and no fallback exists', async () => {const provider = { id: 'p1', type: 'cli' };getActiveProvider.mockResolvedValue(provider);@@ -579,6 +613,25 @@ describe('resolveAgentProviderAndModel — public-review stages', () => {expect(r.error).toMatch(/no-tool/);});+ it('also flags a learning-tier downgrade on the public-review stage path (codex #8148 review)', async () => {+ // resolvePublicReviewAgentProvider is a separate resolution function from+ // the ordinary ("ARCHITECT role") path — it must share the same downgrade+ // detection rather than silently omitting it for unpinned review runs.+ const REVIEW_PROVIDER = { id: 'grok-cli', type: 'cli', command: 'grok', defaultModel: 'grok-heavy', models: ['grok-heavy', 'grok-light'] };+ getAllProviders.mockResolvedValue({ providers: [REVIEW_PROVIDER], activeProvider: null });+ selectModelForTask.mockResolvedValue({ model: 'grok-light', tier: 'medium', reason: 'learning-suggested', isLearningTierOverride: true });++ const r = await resolveAgentProviderAndModel(gateTask());+ expect(r.ok).toBe(true);+ expect(r.selectedModel).toBe('grok-light');+ expect(r.modelSelection.downgradedFromDefault).toBe(true);+ expect(r.modelSelection.configuredDefault).toBe('grok-heavy');+ expect(emitLog).toHaveBeenCalledWith('warn', expect.stringContaining('differs from provider\'s configured default'), expect.objectContaining({+ downgradedFromDefault: true,+ configuredDefault: 'grok-heavy',+ }));+ });+it('requires a maintained actions recipe for binary providers and rejects API spawns', async () => {const OPENCODE = { id: 'opencode', type: 'cli', command: 'opencode' };getAllProviders.mockResolvedValue({ providers: [OPENCODE], activeProvider: { id: 'opencode' } });