Skip to content

After jcode is actually doing something, gets interrupted, and then executes another task, it returns a 400 error #321

Closed

Description

@luosoy

After jcode is actually doing something, gets interrupted, and then executes another task, it returns a 400 error。
No matter what you say, it cannot recover。After exiting, even if you enter /resume again, it still cannot recover.

OpenAI-compatible chat request failed
endpoint: https://api.deepseek.com/chat/completions
model: deepseek-v4-flash
auth: DEEPSEEK_API_KEY
status: 400 Bad Request
response: {"error":{"message":"Invalid assistant message: content or tool_calls must be set","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}
Hint: check network connectivity, DNS/TLS, that the base URL includes the API version (usually /v1), and that the model exists on the provider.

Activity

  1. added
    bug
    priority: high
    triage: reproducible
    on Jun 5, 2026
  2. 1jehuang commented on Jun 5, 2026

    @1jehuang
    Owner

    Reproduced and fixed in b8ba276a.

    Root cause: When a turn is interrupted while only reasoning (thinking) content has streamed, the persisted assistant message contains a single reasoning block but no text or tool calls. The OpenAI-compatible request builder serialized this as a bare {"role":"assistant"} for providers like DeepSeek that don't accept a standalone reasoning_content field. DeepSeek then rejects the entire request with 400 Invalid assistant message: content or tool_calls must be set, which is why no follow-up message recovered and even /resume kept failing (it replayed the same invalid history).

    Fix: The builder now drops the empty interrupted-thinking artifact entirely when there is no text/tool payload and no provider-accepted reasoning_content (and, for providers that do accept reasoning replay, attaches an explicit empty content so strict validators accept it). Added a regression test that asserts no assistant message is sent without content or tool_calls.

    Will close automatically on the next release.

  3. added
    triage: fixed-pending-release
    and removed
    triage: reproducible
    on Jun 5, 2026
  4. 1jehuang commented on Jun 5, 2026

    @1jehuang
    Owner

    Root-caused and fixed in b8ba276a.

    Cause: When a turn is interrupted while only reasoning has streamed, the persisted assistant message carries a single Reasoning block with no text and no tool calls. For direct OpenAI-compatible providers that don't accept a standalone reasoning_content field (e.g. DeepSeek, where allow_reasoning=false), the request builder serialized this as a bare {"role":"assistant"}. DeepSeek rejects that with 400 Invalid assistant message: content or tool_calls must be set, and because the bad message stays in history, every subsequent request (including /resume) replays it and keeps failing, permanently wedging the session.

    Fix: The OpenAI-compatible message builder now only keeps an interrupted-thinking assistant message when it actually carries text/tool_calls, or when a provider-accepted reasoning_content field is present (in which case it adds an explicit empty content so strict validators still accept it). Otherwise the empty artifact is dropped entirely. Added regression tests for both branches.

    This will close automatically on the next release.

  5. 1jehuang commented on Jun 5, 2026

    @1jehuang
    Owner

    Triaged: this was reproduced and fixed in b8ba276a ("fix(openrouter): never send empty assistant message from interrupted reasoning").

    Root cause: when a turn was interrupted while only reasoning had streamed, the persisted assistant message carried a single Reasoning block but no text/tool calls. For direct OpenAI-compatible providers that don't accept a standalone reasoning_content field (e.g. DeepSeek), the request builder serialized this as a bare {"role":"assistant"}, which the provider rejected with 400 "Invalid assistant message: content or tool_calls must be set". Because the invalid message stayed in history, even /resume replayed it and the session could never recover, matching your report exactly.

    Fix: the builder now only keeps an interrupted reasoning-only assistant turn when it has text/tool calls, or when a provider-accepted reasoning_content field is present (with an explicit empty content added for strict validators); otherwise the empty artifact is dropped. Regression tests cover both the drop path (DeepSeek-style) and the keep-with-reasoning path.

    Will close automatically on the next release.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority: hightriage: fixed-pending-release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions