Kaynağa Gözat

fix: disable fallback when user picks any model via /model

No chain[0] comparison, no state tracking. Just: user has a model set
in opencodeConfig before plugin merge → chain disabled for that agent.
Michael Henke 1 ay önce
ebeveyn
işleme
a3b1779995
1 değiştirilmiş dosya ile 8 ekleme ve 22 silme
  1. 8 22
      src/index.ts

+ 8 - 22
src/index.ts

@@ -561,6 +561,14 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
           const existing = (opencodeConfig.agent as Record<string, unknown>)[
             name
           ] as Record<string, unknown> | undefined;
+          // User picked a model via /model → disable fallback for that agent.
+          if (existing && typeof existing.model === 'string') {
+            foregroundFallback.disableChain(name);
+            log('[plugin] disabled fallback chain for model-switched agent', {
+              agent: name,
+              model: existing.model,
+            });
+          }
           if (existing) {
             // Shallow merge: plugin defaults first, user overrides win
             (opencodeConfig.agent as Record<string, unknown>)[name] = {
@@ -740,28 +748,6 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
         }
       }
 
-      // Disable fallback for agents whose model was switched via /model.
-      // Empty chain → rate-limit errors surface instead of falling back.
-      for (const agentName of Object.keys(runtimeChains)) {
-        const chain = runtimeChains[agentName];
-        if (!chain || chain.length === 0) continue;
-        const entry = configAgent[agentName] as
-          | Record<string, unknown>
-          | undefined;
-        if (
-          entry &&
-          typeof entry.model === 'string' &&
-          entry.model !== chain[0]
-        ) {
-          foregroundFallback.disableChain(agentName);
-          log('[plugin] disabled fallback chain for model-switched agent', {
-            agent: agentName,
-            model: entry.model,
-            chainPrimary: chain[0],
-          });
-        }
-      }
-
       // Capture the resolved model state before optionally removing the
       // orchestrator model from the SDK config, so the TUI keeps showing the
       // configured model rather than a fallback or "default".