[PR #23] [MERGED] fix(converters): skip thinking tag injection when toolResults present #60

Closed
opened 2026-02-27 07:17:47 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jwadow/kiro-gateway/pull/23
Author: @kilhyeonjun
Created: 1/8/2026
Status: Merged
Merged: 1/8/2026
Merged by: @jwadow

Base: mainHead: fix/skip-thinking-tags-with-tool-results


📝 Commits (1)

  • caebe7a fix(converters): skip thinking tag injection when toolResults present

📊 Changes

2 files changed (+83 additions, -5 deletions)

View changed files

📝 kiro_gateway/converters.py (+11 -4)
📝 tests/unit/test_converters.py (+72 -1)

📄 Description

Summary

Fixes #20 - OpenCode compaction returns 400 "Improperly formed request" error.

Root Cause

When the last message contains tool results:

  1. merge_adjacent_messages converts tool messages to user message with toolResults
  2. inject_thinking_tags adds <thinking_mode>... tags to content
  3. Kiro API rejects requests with both toolResults in userInputMessageContext AND thinking tags in content
  4. Results in 400 "Improperly formed request" error

Solution

Check for toolResults before injecting thinking tags. Skip injection when toolResults are present in the current message.

Changes

  • Reorder build_kiro_payload to build user_input_context before thinking tag injection
  • Add check to skip thinking tags when toolResults present
  • Add debug log for skipped injection

Tests

  • test_skips_thinking_tags_when_tool_results_present - verifies thinking tags are NOT injected when toolResults present
  • test_injects_thinking_tags_when_no_tool_results - verifies normal messages still get thinking tags

Verification

✅ 213 passed (test_converters.py, test_auth_manager.py, test_thinking_parser.py)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/jwadow/kiro-gateway/pull/23 **Author:** [@kilhyeonjun](https://github.com/kilhyeonjun) **Created:** 1/8/2026 **Status:** ✅ Merged **Merged:** 1/8/2026 **Merged by:** [@jwadow](https://github.com/jwadow) **Base:** `main` ← **Head:** `fix/skip-thinking-tags-with-tool-results` --- ### 📝 Commits (1) - [`caebe7a`](https://github.com/jwadow/kiro-gateway/commit/caebe7a3940363ea4024d81689a6680b49a002ab) fix(converters): skip thinking tag injection when toolResults present ### 📊 Changes **2 files changed** (+83 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `kiro_gateway/converters.py` (+11 -4) 📝 `tests/unit/test_converters.py` (+72 -1) </details> ### 📄 Description ## Summary Fixes #20 - OpenCode compaction returns 400 "Improperly formed request" error. ## Root Cause When the last message contains tool results: 1. `merge_adjacent_messages` converts tool messages to user message with `toolResults` 2. `inject_thinking_tags` adds `<thinking_mode>...` tags to content 3. Kiro API rejects requests with **both** `toolResults` in `userInputMessageContext` AND thinking tags in content 4. Results in 400 "Improperly formed request" error ## Solution Check for `toolResults` before injecting thinking tags. Skip injection when `toolResults` are present in the current message. ## Changes - Reorder `build_kiro_payload` to build `user_input_context` before thinking tag injection - Add check to skip thinking tags when `toolResults` present - Add debug log for skipped injection ## Tests - `test_skips_thinking_tags_when_tool_results_present` - verifies thinking tags are NOT injected when toolResults present - `test_injects_thinking_tags_when_no_tool_results` - verifies normal messages still get thinking tags ## Verification ``` ✅ 213 passed (test_converters.py, test_auth_manager.py, test_thinking_parser.py) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 07:17:47 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/kiro-gateway-jwadow#60
No description provided.