Skip to content

Kiro API 400 error after compaction due to mismatched toolUses/toolResults #14367

Closed as not planned

Description

@ricoshin

Problem

After compaction/pruning, the Kiro API returns a 400 Improperly formed request error.

Root Cause

When filterCompacted trims history to only include messages after the summary, assistant messages with toolUses can remain while their corresponding toolResults in the next user message get cut. The existing validation only checked the last history item, missing mismatches in intermediate history.

Expected Behavior

The converter should validate toolUses/toolResults pairs across the entire history, not just the last item.

Affected Code

packages/opencode/src/provider/kiro/converters.ts

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 20, 2026
  2. ke7in-zz commented on Mar 11, 2026

    @ke7in-zz

    Additional investigation from #17065 (closing as duplicate):

    Proxy is not the cause. I reproduced this error using hai-proxy as a local passthrough and confirmed it forwards Anthropic's 400 verbatim — it does not mangle or truncate message history itself. The errorCode: PROXY_LLM_ERROR wrapper is just hai-proxy's envelope around the raw Anthropic error.

    Isolation method: wrote a repro script testing four scenarios directly against the proxy:

    1. Well-formed tool_use → tool_result pair → 200 OK
    2. Orphaned tool_use with no tool_result → 400 (proxy passes through verbatim)
    3. Long history with orphaned tool_use at end (compaction-style) → 400
    4. Multiple tool_use, only one tool_result → 400

    All 400s originated from Anthropic. The proxy is a transparent passthrough, confirming the bug is entirely in OpenCode's filterCompacted history reconstruction as identified here.

    Environment: OpenCode 1.2.22, claude-sonnet-4-6, macOS 26.2, triggered at ~300 messages.

  3. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

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