Browse Source

fix(session): skip duplicate system prompt for Codex OAuth sessions (#8357)

Co-authored-by: Claude <[email protected]>
zerone0x 1 month ago
parent
commit
f9fcdead55
1 changed files with 10 additions and 7 deletions
  1. 10 7
      packages/opencode/src/session/llm.ts

+ 10 - 7
packages/opencode/src/session/llm.ts

@@ -55,13 +55,20 @@ export namespace LLM {
       modelID: input.model.id,
       modelID: input.model.id,
       providerID: input.model.providerID,
       providerID: input.model.providerID,
     })
     })
-    const [language, cfg] = await Promise.all([Provider.getLanguage(input.model), Config.get()])
+    const [language, cfg, provider, auth] = await Promise.all([
+      Provider.getLanguage(input.model),
+      Config.get(),
+      Provider.getProvider(input.model.providerID),
+      Auth.get(input.model.providerID),
+    ])
+    const isCodex = provider.id === "openai" && auth?.type === "oauth"
 
 
     const system = SystemPrompt.header(input.model.providerID)
     const system = SystemPrompt.header(input.model.providerID)
     system.push(
     system.push(
       [
       [
         // use agent prompt otherwise provider prompt
         // use agent prompt otherwise provider prompt
-        ...(input.agent.prompt ? [input.agent.prompt] : SystemPrompt.provider(input.model)),
+        // For Codex sessions, skip SystemPrompt.provider() since it's sent via options.instructions
+        ...(input.agent.prompt ? [input.agent.prompt] : isCodex ? [] : SystemPrompt.provider(input.model)),
         // any custom prompt passed into this call
         // any custom prompt passed into this call
         ...input.system,
         ...input.system,
         // any custom prompt from last user message
         // any custom prompt from last user message
@@ -84,10 +91,6 @@ export namespace LLM {
       system.push(header, rest.join("\n"))
       system.push(header, rest.join("\n"))
     }
     }
 
 
-    const provider = await Provider.getProvider(input.model.providerID)
-    const auth = await Auth.get(input.model.providerID)
-    const isCodex = provider.id === "openai" && auth?.type === "oauth"
-
     const variant =
     const variant =
       !input.small && input.model.variants && input.user.variant ? input.model.variants[input.user.variant] : {}
       !input.small && input.model.variants && input.user.variant ? input.model.variants[input.user.variant] : {}
     const base = input.small
     const base = input.small
@@ -110,7 +113,7 @@ export namespace LLM {
         sessionID: input.sessionID,
         sessionID: input.sessionID,
         agent: input.agent,
         agent: input.agent,
         model: input.model,
         model: input.model,
-        provider: Provider.getProvider(input.model.providerID),
+        provider,
         message: input.user,
         message: input.user,
       },
       },
       {
       {