From fb8617cfa973023696b4ec144a226ada32f37bdc Mon Sep 17 00:00:00 2001 From: Vishnuvardhan Reddy Date: Thu, 26 Feb 2026 12:14:20 +0000 Subject: [PATCH] fix(agent,gateway): don't overwrite ModelName with protocol-stripped modelID Previously, after CreateProvider returned, the code would overwrite cfg.Agents.Defaults.ModelName with modelID (the second return value). The modelID is the protocol-stripped model identifier returned by ExtractProtocol. For example, if model_list has: - model_name: "openrouter-free" - model: "openrouter/free" Then CreateProvider would return modelID="free" (after stripping the "openrouter/" protocol), and the code would set ModelName="free". This broke the fallback mechanism because: 1. The agent's Model field became "free" instead of "openrouter-free" 2. ParseModelRef("free", "openrouter") would create a candidate with Provider="openrouter", Model="free" 3. When Chat() failed, the error would show provider=openrouter model=free 4. The actual model name "openrouter-free" was lost, breaking fallback The fix is to NOT overwrite ModelName with modelID. The ModelName should remain as the model_list entry name (like "openrouter-free") for proper fallback resolution. The modelID is only used internally by the provider implementation. This fixes the issue where changing config and restarting gateway wouldn't pick up the new model because the model name was being overwritten with just the model ID part. Fixes config changes not being applied after gateway restart. --- cmd/picoclaw/internal/agent/helpers.go | 7 +++---- cmd/picoclaw/internal/gateway/helpers.go | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/picoclaw/internal/agent/helpers.go b/cmd/picoclaw/internal/agent/helpers.go index 746e9755e..8d4422b9f 100644 --- a/cmd/picoclaw/internal/agent/helpers.go +++ b/cmd/picoclaw/internal/agent/helpers.go @@ -42,10 +42,9 @@ func agentCmd(message, sessionKey, model string, debug bool) error { return fmt.Errorf("error creating provider: %w", err) } - // Use the resolved model ID from provider creation - if modelID != "" { - cfg.Agents.Defaults.ModelName = modelID - } + // Don't overwrite ModelName with modelID - modelID is just the protocol-stripped + // model identifier, but ModelName should remain as the model_list entry name + // for proper fallback resolution. msgBus := bus.NewMessageBus() agentLoop := agent.NewAgentLoop(cfg, msgBus, provider) diff --git a/cmd/picoclaw/internal/gateway/helpers.go b/cmd/picoclaw/internal/gateway/helpers.go index a06625dc9..be191d13c 100644 --- a/cmd/picoclaw/internal/gateway/helpers.go +++ b/cmd/picoclaw/internal/gateway/helpers.go @@ -43,10 +43,9 @@ func gatewayCmd(debug bool) error { return fmt.Errorf("error creating provider: %w", err) } - // Use the resolved model ID from provider creation - if modelID != "" { - cfg.Agents.Defaults.ModelName = modelID - } + // Don't overwrite ModelName with modelID - modelID is just the protocol-stripped + // model identifier, but ModelName should remain as the model_list entry name + // for proper fallback resolution. msgBus := bus.NewMessageBus() agentLoop := agent.NewAgentLoop(cfg, msgBus, provider)