Skip to content

Empty reasoning step (no delta) in replayed history causes 400 on later Kimi K3 requests #37651

Description

@mihneaptu

Description

Multi-turn sessions with opencode-go/kimi-k3 (max variant) start failing with Error from provider (Console Go): Upstream request failed (HTTP 400) once the history contains an assistant step where the provider opened and closed a reasoning stream without emitting any delta. Every later request in that session fails; a fresh session works until it hits the same history shape.

This is the second, independent failure path originally documented in #37552. That issue was closed when models.dev#3331 fixed the temperature path (thanks for the fast fix) — but this replay path does not involve temperature at all and still reproduces after the catalog fix.

Root cause

MessageV2.toModelMessages replays a reasoning part with empty text and no metadata (between duplicate step-start boundaries) as an assistant message with no usable content, which the upstream endpoint rejects.

Evidence

  • Reproduced with a minimal config ("model": "opencode-go/kimi-k3" only — no agent files, no temperature anywhere).
  • A/B: the exact affected session replayed through a build patched to skip empty metadata-free reasoning parts continued for 26 steps and finished normally; the same session on stock source fails immediately. Identical catalog and provider conditions in both runs.

Fix with regression test: #37624.

Environment

  • opencode 1.18.3
  • Windows 11 Pro (10.0.26200)
  • Plugins: none active in the reproduction

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions