Skip to content

400 provider error on session resume with open tool calls #701

Open

Description

@thecannabisapp

Bug Description

When resuming a Kimi Code session where the last turn has open (unresponded) tool calls, the LLM provider fails with a 400 [provider.api_error] stating:

an assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'.

This happens because the new user prompt/steer is appended to the history after the open tool calls, preventing trimTrailingOpenToolExchange from cleaning them since they are no longer "trailing" at the very end of the history. Additionally, the new user prompt gets deferred if pendingToolResultIds is not cleared from the aborted turn.

Solution

We resolved this by:

  1. Clearing pendingToolResultIds at the start and end of turn boundaries (TurnFlow.runOneTurn).
  2. Clearing pendingToolResultIds after replaying session records during resume (Agent.resume).
  3. Reverting the step.end cleanup to correctly preserve system reminder deferral during active tool execution.

The commit with the fix on the fork is:
thecannabisapp@0291e89

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions