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
Problem
After compaction/pruning, the Kiro API returns a 400
Improperly formed requesterror.Root Cause
When
filterCompactedtrims history to only include messages after the summary, assistant messages withtoolUsescan remain while their correspondingtoolResultsin 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