Skip to content

fix: harden kimi structured output and replay#21943

Closed
themauveavenger wants to merge 3 commits intoanomalyco:devfrom
themauveavenger:fix/kimi-replay-structured-output
Closed

fix: harden kimi structured output and replay#21943
themauveavenger wants to merge 3 commits intoanomalyco:devfrom
themauveavenger:fix/kimi-replay-structured-output

Conversation

@themauveavenger
Copy link
Copy Markdown

Issue for this PR

Closes #15197
Closes #15226

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This fixes two Kimi-specific protocol mismatches in opencode's current dev branch.

First, it preserves reasoning_content / reasoning_details when prior assistant turns are replayed through the OpenAI-compatible chat path. That addresses the replay failure reported in #15197 and also helps with the broader replay-stripping problem discussed in #19081.

Second, it stops forcing tool_choice: "required" for Kimi structured-output requests. Kimi thinking mode rejects that combination, so structured output now uses auto for Kimi-family models instead. That addresses #15226.

The fix is intentionally narrow:

  • it adds the replay serialization on the OpenAI-compatible chat transport
  • it moves the structured-output tool-choice decision into ProviderTransform
  • it keeps the Kimi exception keyed off model.family
  • it adds regression coverage for both behaviors

Related upstream work:

In practice, this should make Kimi sessions more stable in two places that currently fail immediately: multi-turn replay after tool use, and JSON-schema/structured-output requests.

How did you verify your code works?

I tested the touched paths locally with:

  • bun test test/provider/copilot/convert-to-copilot-messages.test.ts
  • bun test test/session/prompt.test.ts
  • bun test test/provider/transform.test.ts
  • bun test test/session/structured-output.test.ts

I also ran diagnostics on the changed files before committing.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@themauveavenger themauveavenger force-pushed the fix/kimi-replay-structured-output branch from bc08904 to 874446c Compare April 10, 2026 20:41
@smashah
Copy link
Copy Markdown

smashah commented Apr 11, 2026

why is this closed?

@themauveavenger
Copy link
Copy Markdown
Author

why is this closed?

I modified the copilot sdk when it wasn't necessary.

The kimi issue of not sending "auto" might still be a problem. But I'm testing that more myself before I try again.

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

Labels

None yet

Projects

None yet

2 participants