[PR #11233] fix: ensure Codex OAuth sessions use agent prompt correctly #13706

Closed
opened 2026-02-16 18:18:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11233

State: closed
Merged: No


Summary

Fixes #11163: OpenAI OAuth 5.2 Codex was not applying the agent persona as a system-level instruction.

Changes

Modified packages/opencode/src/session/llm.ts to ensure Codex OAuth sessions mirror other providers:

  • Exclude agent prompt from message stream: For Codex OAuth sessions, agent.prompt is excluded from the message stream since it's sent via options.instructions
  • Construct proper instructions: When isCodex is true, options.instructions now includes:
    • agent.prompt (if present) or base SystemPrompt.instructions()
    • Environment + instruction context from input.system (SystemPrompt.environment() + InstructionPrompt.system())
    • Joined with double newlines and filtered for truthiness
  • Maintain user.system: input.user.system is still kept in the message stream for per-request context

Rationale

The OpenAI Codex OAuth provider sends prompts differently than other providers via the options.instructions field. Previously only the base SystemPrompt.instructions() was sent there; agent/environment instructions were relegated to user content. This caused:

  • Agent persona to not be injected (issue #11163)
  • Agent/env instructions to be sent as user content instead of system-level instructions

This fix ensures parity with other providers by:

  1. Sending agent.prompt through options.instructions (excluded from message stream)
  2. Appending input.system to options.instructions

Testing

Verified that:

  • Agent persona is now correctly injected for Codex OAuth sessions

Fixes #11163

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11233 **State:** closed **Merged:** No --- ## Summary Fixes #11163: OpenAI OAuth 5.2 Codex was not applying the agent persona as a system-level instruction. ## Changes Modified `packages/opencode/src/session/llm.ts` to ensure Codex OAuth sessions mirror other providers: - **Exclude agent prompt from message stream**: For Codex OAuth sessions, `agent.prompt` is excluded from the message stream since it's sent via `options.instructions` - **Construct proper instructions**: When `isCodex` is true, `options.instructions` now includes: - `agent.prompt` (if present) or base `SystemPrompt.instructions()` - Environment + instruction context from `input.system` (`SystemPrompt.environment()` + `InstructionPrompt.system()`) - Joined with double newlines and filtered for truthiness - **Maintain user.system**: `input.user.system` is still kept in the message stream for per-request context ## Rationale The OpenAI Codex OAuth provider sends prompts differently than other providers via the `options.instructions` field. Previously only the base `SystemPrompt.instructions()` was sent there; agent/environment instructions were relegated to user content. This caused: - Agent persona to not be injected (issue #11163) - Agent/env instructions to be sent as user content instead of system-level instructions This fix ensures parity with other providers by: 1. Sending `agent.prompt` through `options.instructions` (excluded from message stream) 2. Appending `input.system` to `options.instructions` ## Testing Verified that: - Agent persona is now correctly injected for Codex OAuth sessions Fixes #11163
yindo added the pull-request label 2026-02-16 18:18:32 -05:00
yindo closed this issue 2026-02-16 18:18:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13706