Skip to content

fix(kimi): omit empty assistant history on native Responses and keep Chat call/result pairs intact (supersedes #6931) - #6947

Merged
lidge-jun merged 1 commit into
devfrom
codex/lane-r3-l1-261011
Oct 11, 2026
Merged

lidge-jun merged 1 commit into
devfrom
codex/lane-r3-l1-261011

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

Supersedes #6931 (carried; the original author is credited in the trailers below). Lane L1 of the 2026-10-11 compatibility round also reviewed #6930 and #6675; both are left out because each needs an owner decision (see the end of this section).

Kimi Code native Responses no longer sends content-empty assistant history. https://api.kimi.com/coding/v1/responses rejects a request containing an assistant message with empty content (Invalid request: the message at position 585 with role 'assistant' must not be empty). For that exact host and path only, the outgoing input now omits assistant messages whose content is "", [], or only empty text parts. Whitespace, refusals, nonempty annotations, unknown parts or fields, reasoning items, tool calls and results are kept. An empty message referenced by a same-input item_reference is kept so no reference dangles. Client history is not rewritten, and every other destination is unchanged.

On the translated Chat wire, an empty assistant turn no longer splits a tool call from its result. Before, function_call → assistant("") → function_call_output closed the pending call with a synthetic "no tool result was recorded" tool message, then turned the real result into an orphan with a second synthesized call. An empty turn (no text, tools or serialized reasoning) that arrives while calls await results is now dropped, so the real result stays attached. Outside that window, a standalone answer made of explicit blank text parts still serializes as content: "", so chat templates that require strict user/assistant alternation (for example Mistral's) keep accepting the history. This is narrower than #6931's original Chat change, which dropped every empty answer on all openai-chat providers; independent review found that it would have produced consecutive user turns on strict templates.

Left out, as owner decisions:

Verification

  • Local tests were intentionally not run for this round; hosted CI on the exact head is the test evidence. The new regression file is tests/adapters/openai/openai-empty-assistant-history.test.ts, registered in scripts/test-layout/layout.json and tests/fixtures/test-layout-expected.json.
  • Static checks on the final head: bun run typecheck, bun run structure:check, bun run privacy:scan, and git diff --check origin/dev all pass.
  • Independent read-only review (gpt-6.1-sol): the first round found one P2 (the global Chat drop breaking strict alternation), which is fixed above. The second round and a fresh pre-push reviewer both passed with no P0, P1 or P2 findings. The remaining P3, which said the structure doc overstated the standalone guarantee, is fixed in the final head.
  • Security: no credential, auth, dependency, workflow, logging or release change; fixtures are synthetic.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Co-authored-by: panyuanyuan panyuanyuan@hetao101.com
Co-authored-by: yuanyuanlove yuanyuanlove@users.noreply.github.com

Summary by CodeRabbit

  • Bug Fixes
    • Kimi Code Responses requests now omit empty assistant history messages that could be rejected, while preserving messages referenced elsewhere in the same request and all messages with meaningful content.
    • Chat history now preserves explicitly blank assistant messages when they are standalone answers, while continuing to retain reasoning and tool-call sequences.
  • Documentation
    • Updated provider guidance and adapter documentation to explain empty assistant-message handling.

…(carry #6931)

Kimi Code's native Responses endpoint rejects a content-empty assistant
message ("the message at position N with role 'assistant' must not be
empty"). For the exact api.kimi.com/coding/v1/responses destination, the
outgoing input now drops assistant messages whose content is "" or only
empty text parts, keeping any message referenced by a same-input
item_reference and any message with unknown fields.

On the translated Chat wire, an empty assistant turn between a tool call
and its result no longer splits the pair: it used to close the pending
call with a synthetic "no tool result was recorded" message and turn the
real result into an orphan. A standalone empty answer keeps its slot so
chat templates with strict role alternation still accept the history.

Co-authored-by: panyuanyuan <panyuanyuan@hetao101.com>
Co-authored-by: yuanyuanlove <yuanyuanlove@users.noreply.github.com>
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 11, 2026 13:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T13:36:20.117798Z 2b299c7 PR opened
ℹ️ 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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 11, 2026
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6c3148c1-f927-46bb-9df9-0e92d01f9158

📥 Commits

Reviewing files that changed from the base of the PR and between 9b6f4b2 and 2b299c7.


📒 Files selected for processing (9)
  • docs-site/src/content/docs/guides/providers.md
  • docs-site/src/content/docs/zh-cn/guides/providers.md
  • scripts/test-layout/layout.json
  • src/adapters/openai-chat/messages.ts
  • src/adapters/openai-responses/empty-assistant.ts
  • src/adapters/openai-responses/passthrough.ts
  • structure/adapters/registry.md
  • tests/adapters/openai/openai-empty-assistant-history.test.ts
  • tests/fixtures/test-layout-expected.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

The Chat adapter now retains explicit empty assistant messages in specified cases. The native Responses adapter filters eligible empty assistant messages only for Kimi Code’s matching endpoint. Documentation and tests describe these rules and their exceptions.

Changes

Empty assistant history

Layer / File(s) Summary
Chat projection and coverage
src/adapters/openai-chat/messages.ts, structure/adapters/registry.md, tests/adapters/openai/openai-empty-assistant-history.test.ts
Chat distinguishes explicit empty content from undefined content. Tests cover empty messages, serialized reasoning, and tool-call/result ordering.
Kimi Responses filtering and coverage
src/adapters/openai-responses/empty-assistant.ts, src/adapters/openai-responses/passthrough.ts, tests/adapters/openai/openai-empty-assistant-history.test.ts, docs-site/src/content/docs/guides/providers.md, docs-site/src/content/docs/zh-cn/guides/providers.md, structure/adapters/registry.md, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
The passthrough adapter filters eligible empty assistant messages for the matching Kimi endpoint and preserves referenced messages. Tests cover preserved content and other destinations. Provider documentation describes the behavior and unchanged client history. Test-layout mappings are updated.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to 2b299

No identified issue currently prevents merging; complete the normal test checks before merge.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (5 skipped: 5… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes both main changes: omitting empty assistant history for Kimi native Responses and preserving Chat call/result pairing. The wording is specific and related to the changeset…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (5 skipped: 5 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lidge-jun
lidge-jun merged commit c3a4cdf into dev Oct 11, 2026
38 checks passed
@lidge-jun
lidge-jun deleted the codex/lane-r3-l1-261011 branch October 11, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant