fix(agent-core-v2): drop interrupted thinking-only assistant messages at step settle - #2819
Open
7Sageer wants to merge 1 commit into
Open
fix(agent-core-v2): drop interrupted thinking-only assistant messages at step settle#28197Sageer wants to merge 1 commit into
7Sageer wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: b01e499 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
… 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
force-pushed
the
fix/openai-legacy-think-only-assistant
branch
from
August 11, 2026 12:41
e653d4d to
b01e499
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 neithercontentnortool_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.partwith an unsignedthinkfragment → next turn's request carries the think-only assistant message → 400, non-retryable.What changed
contextMemoryfold: 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.WireService.restorereplay — sessions already bricked by this shape are repaired the next time their records are folded, with the wire records themselves untouched.loopEventFold.test.tsflips the "thinking block has real content but no signature" case from seal to drop (the signed-thinking seal case stays), andloop.test.tsgains an end-to-end regression: cancel during thinking → next prompt's LLM input contains no thinking-only assistant message.Deliberately not changed:
appendInterruptedStreamContentstill persists the interrupted fragment at cancel time, so the live transcript and thewire.jsonlrecord keep it; only the settled history that feeds provider projections drops it.packages/agent-core) and the kosong adapters: v1 never lands partial stream parts in history, and the adapter-layer fixes are being discussed in fix(agent-core): recover sessions interrupted during thinking #2172 / fix(kosong): serialize reasoning-only assistant content #1738.Validation
@moonshot-ai/agent-core-v2suite 4900 passed.lint:imports, and oxlint clean on the changed files.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
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.