fix(agent-core): drop thinking-only assistant messages from projected requests - #30
Merged
Merged
Conversation
… requests Interrupting a response (ESC/stop) mid-thinking seals a partial assistant message holding only an unencrypted thinking fragment. The OpenAI-compatible base moves think parts out of `content` into `reasoning_content`, so the message serializes with neither content nor tool_calls and the provider rejects it with "400 Invalid assistant message: content or tool_calls must be set" on every retry, permanently wedging the session. The projector now treats unencrypted think parts as non-sendable content and drops whole messages that carry nothing else (signed/encrypted thinking and messages with real content are preserved). Applies to both the v1 (agent-core) and v2 (agent-core-v2) engines, with regression tests for the ESC-cancel case and a changeset.
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 MoonshotAI#2691 (upstream: "Pressing ESC mid-stream permanently wedges the session: next request fails with 400 Invalid assistant message: content or tool_calls must be set"). This is a port of upstream PR MoonshotAI#2689 into the fork, based on
fork/main(0.34.0-MB.1.6).Problem
Interrupting a response (ESC/stop) while the model is still thinking seals a partial assistant message that holds only an unencrypted thinking fragment. When the next request is built, the OpenAI-compatible provider base moves
thinkparts out ofcontentintoreasoning_content, so the message serializes with neithercontentnortool_calls, and the provider rejects it with:The error is non-retryable and the history is rebuilt identically on every retry, so the session stays permanently wedged (observed on the webui USR-dashboard session, 2026-08-09, with
deepseek-v4-flash).What changed
The projector now treats unencrypted
thinkparts as non-sendable content and drops a whole message when it carries nothing else:packages/agent-core/src/agent/context/projector.ts(v1 engine) — newwireSendableContenthelper; a message whose only parts are unencrypted thinking is dropped from the projected request.packages/agent-core-v2/src/agent/contextProjector/contextProjectorService.ts(v2 engine) — same change.encrypted) is preserved verbatim, and messages that carry any text, tool calls, or media keep every part intact.Commits in this PR
b2be09027— fix(agent-core): drop thinking-only assistant messages from projected requests (Mark Buckaway, 2026-08-09)Testing