Skip to content

fix(codex-proxy): merge multiple system messages into one leading message - #2688

Merged
EKKOLearnAI merged 2 commits into
EKKOLearnAI:mainfrom
WenhuaXia:pr/codex-merged-system-messages
Aug 23, 2026
Merged

fix(codex-proxy): merge multiple system messages into one leading message#2688
EKKOLearnAI merged 2 commits into
EKKOLearnAI:mainfrom
WenhuaXia:pr/codex-merged-system-messages

Conversation

@WenhuaXia

Copy link
Copy Markdown
Contributor

问题 / Problem

Codex 0.149 发起请求时会同时携带两处 system 级指令:

  1. 顶层 instructions 字段(核心系统提示,实测 ~20KB)
  2. input 数组中的 role: "developer" 消息(web-ui 写入的 developer_instructions

responsesToOpenAiChat 适配器把两者各转成一条 system 消息,第二条落在对话中间。vLLM 等严格校验的消息顺序,直接拒绝:

400 BadRequestError: "System message must be at the beginning."

影响:web-ui 编程工具(Codex / Claude Code)在 scoped 模式 + OpenAI-compatible vLLM provider(如 Qwen via vLLM)下 每次 请求都会失败。

修复 / Fix

新增 consolidateChatSystemMessages():转换完成后将所有 system 消息按原始顺序合并为一条置顶消息;仅一条 system 时保持原样(含图片 content 不被 stringify),只在其位于对话中间时移到开头。

验证 / Verification

  • 41 个适配器单测全过(含 3 个新增回归测试:单条 system 置顶保持、多条 system 合并、顺序保留)
  • 端到端:mock 服务器捕获 Codex 0.149 真实 payload(顶层 instructions + input 内 developer 消息)→ 修复后转换 → roles: [system, user, user] → 直接请求 vLLM /v1/chat/completionsHTTP 200,模型正常回复
  • 回程转换(openAiChatToResponses)含 tool_calls 场景验证通过

…sage

Codex 0.149 sends both a top-level `instructions` string and `developer`
messages inside `input`. The responses->chat_completions adapter converted
each into its own system message, leaving the second one mid-conversation.
Providers such as vLLM reject this with:
  400 BadRequestError: "System message must be at the beginning."

consolidateChatSystemMessages() now keeps exactly one leading system
message, merging any additional system messages into it in original order.

Fixes web-ui coding-agent (codex + custom:qwen) run failures with vLLM-backed
OpenAI-compatible providers.

Refs: repro via mock capture of codex 0.149 responses payload
…system position

The adapter now relocates in-input developer messages to the front as a
single leading system message, so the expected message order changes from
[user, system] to [system, user].
@WenhuaXia
WenhuaXia force-pushed the pr/codex-merged-system-messages branch from 83a0669 to 1d11107 Compare August 23, 2026 04:21
@EKKOLearnAI
EKKOLearnAI merged commit c2205ef into EKKOLearnAI:main Aug 23, 2026
2 checks passed
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.

2 participants