Skip to content

Conversation

@kumanday
Copy link

Summary

This PR fixes OpenHands Codex subscription model support by making the Responses API payload Codex-compatible. Codex subscription endpoints can reject complex/long top-level instructions (often returning 400 / “Instructions are not valid”), which breaks agent flows that rely on a large system prompt.

What changed

  • Codex-specific message adapter for Responses formatting
    • For models whose id contains "codex":
      • We do not send any system messages as top-level instructions.
      • Instead, we merge system prompt content and prepend it to the first user input message (or inject a synthetic user message if none exists).
    • Non-Codex models keep the current behavior: system messages are concatenated into instructions.
  • Ensure Codex models go through the Responses API path
    • Expanded Responses-model detection from only codex-mini-latest to any model containing codex (e.g. gpt-5.1-codex, gpt-5-codex, provider-prefixed variants).

Why this is needed

Codex subscription endpoints require server-validated instructions and can reject the complex, tool-heavy system prompts typically used by agent frameworks. Moving that content into user input avoids the strict validation while preserving the same guidance/context for the model.

Tests

  • Added a unit test that verifies for a Codex model:
    • instructions is None
    • system prompt content appears at the start of the first user input message.

Copy link
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found several issues that need attention: overly broad model matching, potential data loss bug, and missing test coverage. Details in inline comments.

@kumanday kumanday marked this pull request as draft January 10, 2026 07:03
input_items = normalized

# For subscription Codex transport, use a small, stable instructions string
# (required by the endpoint) and move the full system prompt into user content.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually the right idea, though I’m not sure about the details of the messages.

It seems codex wants its own system prompt basically, more or less

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants