Skip to content

fix(agent-core-v2): drop interrupted thinking-only assistant messages at step settle - #2819

Open
7Sageer wants to merge 1 commit into
mainfrom
fix/openai-legacy-think-only-assistant
Open

fix(agent-core-v2): drop interrupted thinking-only assistant messages at step settle#2819
7Sageer wants to merge 1 commit into
mainfrom
fix/openai-legacy-think-only-assistant

Conversation

@7Sageer

@7Sageer 7Sageer commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Resolve #1404

Related prior work on the v1 engine / shared adapter: #1882 (resume-time drop of fully-empty assistant tails), #2172 (broader v1 resume/projection-layer repair), #1738 (adapter emits an explicit empty content string). This PR fixes the same bug class in the v2 engine only, leaving v1 and the shared kosong adapters untouched.

Problem

On the v2 engine, a turn interrupted while the model is still streaming thinking (user cancel, process kill) leaves the open assistant message holding only a thinking fragment whose provider signature never arrived. The fold's settle step sealed that message into history because a non-empty thinking block is not "vacuous". On the next request the OpenAI-compatible serialization moves the thinking into reasoning_content, producing an assistant message with neither content nor tool_calls; strict gateways reject that shape (400 Invalid assistant message: content or tool_calls must be set), so every follow-up request fails and the session is effectively bricked.

Reproduced from a real session export (0.34.0): cancel during thinking → content.part with an unsigned think fragment → next turn's request carries the think-only assistant message → 400, non-retryable.

What changed

  • contextMemory fold: at settle time, an open assistant with no tool calls whose content parts are all vacuous or unsigned thinking is dropped instead of sealed. Signed thinking (encrypted) still counts as sendable output and is preserved verbatim, as reasoning providers require.
  • The drop runs inside the fold, so it applies deterministically at live dispatch and on WireService.restore replay — sessions already bricked by this shape are repaired the next time their records are folded, with the wire records themselves untouched.
  • Tests: loopEventFold.test.ts flips the "thinking block has real content but no signature" case from seal to drop (the signed-thinking seal case stays), and loop.test.ts gains an end-to-end regression: cancel during thinking → next prompt's LLM input contains no thinking-only assistant message.

Deliberately not changed:

Validation

  • New fold + loop regressions pass; full @moonshot-ai/agent-core-v2 suite 4900 passed.
  • Typecheck, lint:imports, and oxlint clean on the changed files.
  • Verified live against a strict OpenAI-compatible reasoning endpoint: the pre-fix shape (assistant message with only reasoning_content) returns the exact 400 from Empty assistant message after terminal crash causes 400 on session resume (DeepSeek) #1404; the post-fix request (message absent) returns 200.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b01e499

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@b01e499
npx https://pkg.pr.new/@moonshot-ai/kimi-code@b01e499

commit: b01e499

… at settle

A turn interrupted while the model is still streaming thinking leaves the
open assistant holding only an unsigned thinking fragment. The fold used
to seal it into history because a non-empty thinking block is not vacuous;
on OpenAI-compatible providers the serialized message then carries neither
content nor tool_calls, and strict gateways reject every later request
with a 400 (#1404). Treat unsigned-thinking-only content as unsendable at
settle so the fold drops the message instead — replaying the records of
an already bricked session repairs it.
@7Sageer
7Sageer force-pushed the fix/openai-legacy-think-only-assistant branch from e653d4d to b01e499 Compare August 11, 2026 12:41
@7Sageer 7Sageer changed the title fix(kosong): drop thinking-only assistant messages from OpenAI-compatible requests fix(agent-core-v2): drop interrupted thinking-only assistant messages at step settle Aug 11, 2026
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.

Empty assistant message after terminal crash causes 400 on session resume (DeepSeek)

1 participant