From 419f393d7d223fa11e887f554d6ebe21e258dbf9 Mon Sep 17 00:00:00 2001 From: admin-mf Date: Fri, 6 Mar 2026 09:02:17 -0600 Subject: [PATCH] fix(agent): honor workspace config overrides in model routing selectCandidates uses agent.Model/Candidates baked in at startup, which ignores per-request workspace config overrides (effProvider/effModel). When the workspace overrides the provider, skip routing and fallback candidates entirely to avoid cross-provider credential issues. When only the model is overridden, allow routing but use the effective model. Co-Authored-By: Claude Opus 4.6 --- pkg/agent/loop.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 4d72935cd..034c4ee59 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -972,17 +972,32 @@ func (al *AgentLoop) runLLMIteration( iteration := 0 var finalContent string - // Resolve effective provider — workspace config overrides win + // Resolve effective provider/model — workspace config overrides win effProvider := agent.Provider + effModel := agent.Model if opts.effProvider != nil { effProvider = opts.effProvider } + if opts.effModel != "" { + effModel = opts.effModel + } // Determine effective model tier for this conversation turn. // selectCandidates evaluates routing once and the decision is sticky for // all tool-follow-up iterations within the same turn so that a multi-step // tool chain doesn't switch models mid-way through. - activeCandidates, activeModel := al.selectCandidates(agent, opts.UserMessage, messages) + var activeCandidates []providers.FallbackCandidate + var activeModel string + if opts.effProvider != nil { + // Workspace overrides the provider — skip routing and fallback + // candidates since they may reference different provider credentials. + activeModel = effModel + } else { + activeCandidates, activeModel = al.selectCandidates(agent, opts.UserMessage, messages) + if opts.effModel != "" { + activeModel = effModel + } + } for iteration < agent.MaxIterations { iteration++