Skip to content

Fixed OpenAI-compatible models with strict chat templates failing with "System message must be at the beginning" - #201

Merged
oleg68 merged 5 commits into
nbplugins:mainfrom
oleg68:bugfix/openai-proxy-system-message-position
Oct 21, 2026
Merged

oleg68 merged 5 commits into
nbplugins:mainfrom
oleg68:bugfix/openai-proxy-system-message-position

Conversation

@oleg68

@oleg68 oleg68 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Claude Code >= 2.1.288 sends mid-conversation role:"system" messages; the Chat Completions translator forwarded them in place (system, user, system), which vLLM chat templates reject with HTTP 400. They are now merged into the leading system message, or become <system-reminder> text in a user message later in the conversation. The Codex translator is unchanged.

🤖 Generated with Claude Code

…h "System message must be at the beginning"

Mid-conversation system messages (Claude Code >= 2.1.288) were forwarded in place as role:system. They are now merged into the leading system message, or turned into <system-reminder> user text later in the conversation.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T20:17:40.950865Z c1f199d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1230718e64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Mid-conversation system text after a multipart (image) user turn is now added as a text part of that turn instead of a second consecutive user message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a814a3bcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

A mid-conversation system message that precedes the first user turn (explicit cache breakpoint case) is now folded into that user turn instead of producing two consecutive user messages.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44a8818440

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

A reminder created between an assistant tool_use and its tool_result turn is now placed after the tool messages so the call/result pair stays adjacent.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oleg68

oleg68 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +373 to +375
if (last != null && "user".equals(last.path("role").asText()) && last.path("content").isTextual()) {
((ObjectNode) last).put("content", last.path("content").asText() + "\n\n" + reminder);
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Coalesce the next user after appending a reminder

When an in-band system message separates two textual user entries (user A, system S, user B), this branch appends S to A but leaves pendingReminder unset; processing B then adds another user message. The translator consequently emits user,user, which strict chat templates that require user/assistant alternation reject even though the non-leading system role has been removed; coalesce B into the same turn as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in c1f199d: a user turn following a user message that received a reminder (user A, system S, user B) is now coalesced into that message (text+text concatenated, or merged into a multipart content array), so no two user messages are adjacent. Added tests for both the text and the image case.

🤖 Generated with Claude Code

A user turn that follows a user message which received a mid-conversation system text is now coalesced into it, so no two user messages are adjacent.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oleg68

oleg68 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: c1f199d3d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oleg68
oleg68 merged commit d93cdef into nbplugins:main Oct 21, 2026
3 checks passed
@oleg68
oleg68 deleted the bugfix/openai-proxy-system-message-position branch October 21, 2026 05:19
@oleg68 oleg68 mentioned this pull request Oct 22, 2026
oleg68 added a commit that referenced this pull request Oct 22, 2026
Adds the `# 1.3` release heading to line 1 of CHANGELOG.md for the
unreleased fix of OpenAI-compatible models with strict chat templates
(#201).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Oleg Samarin <osamarin@openintegration.inc>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant