GeezerVison is showing github.com — Kiro API 400 error after compaction due to mismatched toolUses/toolResults · Issue #14367 · anomalyco/opencode
Kiro API 400 error after compaction due to mismatched toolUses/toolResults #14367
Description
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
added
coreAnything pertaining to core functionality of the application (opencode server stuff) on Feb 20, 2026ke7in-zz commented on Mar 11, 2026
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:
- Well-formed
tool_use → tool_result pair → 200 OK
- Orphaned
tool_use with no tool_result → 400 (proxy passes through verbatim)
- Long history with orphaned
tool_use at end (compaction-style) → 400
- 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.
removed
coreAnything pertaining to core functionality of the application (opencode server stuff) on May 3, 2026github-actions commented on Jul 4, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
Metadata
Metadata
Development
No branches or pull requestsIssue actions