Browse Source

fix: preserve user /model selection across plugin re-inits

When a user selects a model via /model in OpenCode, that selection was
being overwritten after spawning a subagent (which triggers
client.config.update() → Instance.dispose() → plugin re-init).

The model array resolution block in the config() hook unconditionally
overwrote entry.model with the first model from the config array,
ignoring any runtime /model selection preserved in opencodeConfig.

Fix: skip model array resolution when entry.model is already set
(user's /model selection survived the merge). Only apply when
entry.model is undefined (first init or array config with no
prior selection).

This preserves runtime model selections and avoids breaking
provider cache on subagent spawns.
dragon-Elec 1 month ago
parent
commit
84074a02e2
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/index.ts

+ 9 - 3
src/index.ts

@@ -514,9 +514,15 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
             | Record<string, unknown>
             | Record<string, unknown>
             | undefined;
             | undefined;
           if (entry) {
           if (entry) {
-            entry.model = chosen.id;
-            if (chosen.variant) {
-              entry.variant = chosen.variant;
+            // Only apply model array resolution if no user-selected model
+            // exists. A user-selected model (via /model command) takes
+            // precedence over the config's fallback chain to preserve
+            // runtime selections and avoid breaking provider cache.
+            if (entry.model === undefined) {
+              entry.model = chosen.id;
+              if (chosen.variant) {
+                entry.variant = chosen.variant;
+              }
             }
             }
           } else {
           } else {
             // Agent exists in slim but not in opencodeConfig.agent —
             // Agent exists in slim but not in opencodeConfig.agent —