Skip to content

Fix Cursor chat-completions compatibility#833

Open
Iweisc wants to merge 20 commits into
Soju06:mainfrom
Iweisc:fix/cursor-chat-compat
Open

Fix Cursor chat-completions compatibility#833
Iweisc wants to merge 20 commits into
Soju06:mainfrom
Iweisc:fix/cursor-chat-compat

Conversation

@Iweisc
Copy link
Copy Markdown

@Iweisc Iweisc commented May 27, 2026

Summary

Fixes compatibility issues seen when Cursor sends OpenAI-compatible requests to /v1/chat/completions while using its GPT-5.5 Extra model option. The failing requests were accepted by the chat-completions surface but rejected later by the ChatGPT/Codex upstream because of model/field mismatches.

Changes:

  • Accept Responses-shaped payloads (input + optional instructions) on the chat-completions endpoint instead of requiring messages in that path.
  • Accept Responses-style text content parts (input_text / output_text) when chat messages are being coerced.
  • Strip OpenAI compatibility fields metadata and user from upstream payload serialization, matching existing unsupported-field handling for fields like temperature and top_p.
  • Normalize Cursor's synthetic gpt-5.5-extra model slug to upstream gpt-5.5, and apply high reasoning for that alias.
  • Allow API keys that permit the canonical model (gpt-5.5) to also pass access checks for the alias (gpt-5.5-extra).

Validation

  • uv run pytest tests/unit/test_chat_request_mapping.py tests/unit/test_openai_requests.py tests/unit/test_request_policy.py
  • uv run ruff check app/core/openai/chat_requests.py app/core/openai/message_coercion.py app/core/openai/requests.py app/modules/proxy/request_policy.py tests/unit/test_chat_request_mapping.py tests/unit/test_openai_requests.py tests/unit/test_request_policy.py

Notes

This keeps compatibility normalization in the existing request mapping / serialization / request-policy layers rather than adding client-specific special cases in the proxy endpoint. The model alias is intentionally narrow because it corresponds to a Cursor UI model name that is not accepted by the upstream Codex backend as a literal model slug.

Copy link
Copy Markdown

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

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: d0f9586077

ℹ️ 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 thread app/core/openai/chat_requests.py Outdated
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 27, 2026
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

Follow-up pushed in e1e0fe3:

  • Replaced the one-off gpt-5.5-extra alias with a guarded GPT-5-family alias parser.
  • Covers gpt-5, gpt-5.1, gpt-5.2, gpt-5.3, gpt-5.4, and gpt-5.5.
  • Recognizes Cursor-style suffix tokens: extra, xhigh, high, medium, low, minimal, fast, priority, reasoning, thinking.
  • Maps extra/xhigh to upstream-safe high reasoning and fast to priority service tier.
  • Leaves unknown suffixes untouched instead of guessing.

Validation after this follow-up:

uv run pytest tests/unit/test_request_policy.py tests/unit/test_chat_request_mapping.py tests/unit/test_openai_requests.py
# 141 passed

uv run ruff check app/modules/proxy/request_policy.py tests/unit/test_request_policy.py
# All checks passed

@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

Addressed the empty messages regression in dfb17bc:

  • Treat messages: [] with present input as Responses-shaped input.
  • Preserve input and instructions instead of dropping input and forwarding an empty array.
  • Added regression coverage for messages: [] + non-empty input.

Validation:

uv run pytest tests/unit/test_chat_request_mapping.py
# 52 passed

uv run ruff check app/core/openai/chat_requests.py tests/unit/test_chat_request_mapping.py
# All checks passed

@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label May 27, 2026
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

Follow-up: fixed the Cursor context-window failure path. Cursor's bundled client has a dedicated ERROR_CONVERSATION_TOO_LONG UI branch, but the OpenAI-compatible provider path was receiving an immediate Responses response.failed event inside a 200 OK chat stream. /v1/chat/completions now treats first-frame response.failed/error as a startup failure and returns the parsed OpenAI error JSON with the correct HTTP status, so context_length_exceeded surfaces as a 400 instead of an empty successful stream. Mid-stream failures after partial output still stay in-stream. Added an integration test for startup context_length_exceeded.

@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

Follow-up after live Cursor validation: Cursor still does not render the provider HTTP error in its chat UI. Added a targeted compatibility fallback for API keys named cursor: immediate context_length_exceeded startup failures are converted into a normal chat-completions assistant message, preserving visible feedback in Cursor. Other API keys and other errors still use the standard error response path. Added unit coverage for cursor vs non-cursor detection.

@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

Still working to get the compaction working.

@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented May 27, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

@codex review

@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

Compaction is working now.

Copy link
Copy Markdown

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

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: e0e57a434e

ℹ️ 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 thread app/core/openai/chat_requests.py Outdated
Co-authored-by: Cursor <cursoragent@cursor.com>
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 27, 2026
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

@codex review

Copy link
Copy Markdown

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

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: b449e7f094

ℹ️ 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 thread app/core/openai/chat_requests.py Outdated
Comment thread app/modules/proxy/api.py Outdated
Co-authored-by: Cursor <cursoragent@cursor.com>
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label May 27, 2026
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 27, 2026

@codex review

Copy link
Copy Markdown

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

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: cd8d905f46

ℹ️ 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 thread app/modules/proxy/api.py
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 27, 2026
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

Copy link
Copy Markdown

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

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: 9358529183

ℹ️ 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 thread app/modules/proxy/api.py
Co-authored-by: Cursor <cursoragent@cursor.com>
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 28, 2026
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

Copy link
Copy Markdown

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

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: 7d50632aef

ℹ️ 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 thread app/core/openai/chat_requests.py
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

Copy link
Copy Markdown

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

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: 7d69bad48c

ℹ️ 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 thread app/modules/proxy/request_policy.py Outdated
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ 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".

@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

Copy link
Copy Markdown

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

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: 27baea6d62

ℹ️ 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 thread app/modules/proxy/request_policy.py
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

Copy link
Copy Markdown

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

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: 48c89e6b1b

ℹ️ 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 thread app/modules/proxy/request_policy.py Outdated
@Iweisc
Copy link
Copy Markdown
Author

Iweisc commented May 28, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ 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".

@Komzpa Komzpa added 🤖 codex: ok [@codex review] says no issues found. and removed 🤖 codex: needs work [@codex review] raised an issue labels May 31, 2026
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Jun 1, 2026

Hermes owner-review blocker:

This PR changes observable behavior/contracts but does not include an OpenSpec change folder. The repo merge gate requires openspec/changes/<slug>/ for non-exempt behavior changes.

Evidence:

  • AGENTS.md:24-28: behavior / requirement / contract / schema changes must create an OpenSpec change first, then keep code + specs in sync.
  • .github/CONTRIBUTING.md:235-239: pure refactors/docs/dev-tool/test-stabilization are exempt; everything else needs an openspec/changes/<slug>/ entry.
  • This PR has 0 changed files under openspec/changes/, while directly changing stable specs under:
    • openspec/specs/api-keys/spec.md
    • openspec/specs/chat-completions-compat/spec.md
    • openspec/specs/responses-api-compat/spec.md
  • The implementation is not just docs/spec cleanup: it changes /v1/chat/completions request-shape compatibility, Responses-tool passthrough, GPT-5/Cursor alias normalization, API-key model allowlist/catalog canonicalization, and Cursor context-limit fallback behavior.

Requested fix: add a normal OpenSpec change folder (proposal.md, tasks.md, and delta specs) covering these behavior changes, then validate it with uv run openspec validate <change> --strict plus uv run openspec validate --specs. If maintainers intentionally want to waive the OpenSpec-first gate for this PR, please state that explicitly in-thread before merge.

I also noticed one non-blocking follow-up worth considering while touching the policy surface: the Cursor context-limit synthetic-success path is enabled by any User-Agent containing cursor, not only by a Cursor-named API key; that broadens who can opt into the 200/synthetic-usage error semantics.

@Soju06 Soju06 added the hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation label Jun 1, 2026
@Komzpa Komzpa removed 🤖 codex: ok [@codex review] says no issues found. hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation labels Jun 1, 2026
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Jun 1, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

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

ℹ️ 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".

@Soju06 Soju06 added the 🤖 codex: ok [@codex review] says no issues found. label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 codex: ok [@codex review] says no issues found.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants