mirror of
https://github.com/jwadow/kiro-gateway.git
synced 2026-04-25 01:15:57 +03:00
[GH-ISSUE #5] "Improperly formed request" error on agent-mode payloads w/ codex client #5
Labels
No labels
bug
bug
enhancement
enhancement
fixed
fixed
invalid
needs-info
needs-testing
pull-request
question
upstream
wontfix
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/kiro-gateway-jwadow#5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stunl0ck on GitHub (Dec 17, 2025).
Original GitHub issue: https://github.com/jwadow/kiro-gateway/issues/5
Environment
Problem
Simple chat completions work fine. However, when using the gateway with an agent client that makes tool calls, requests fail with:
What I Tested
Key finding: Even with MCP tools disabled (only Codex's core
shell,apply_patch,update_plantools), a fresh session fails after just a few tool calls. This isn't about accumulated history — something in the tool call/result conversion breaks for Kiro's API.Debug Data
Using
DEBUG_LAST_REQUEST=true, I captured:request_body.json— incoming OpenAI-format requestkiro_request_body.json— converted Kiro-format request (~95KB)The conversion appears complete (valid JSON, ends with
profileArn), but Kiro's API rejects it.Suspected Cause
Either:
toolResults/assistantResponseMessage.toolUsesconversion doesn't match what Kiro expectsQuestions
@jwadow commented on GitHub (Dec 17, 2025):
@stunl0ck thanks for feedback
Good news - v1.0.4 is out and should fix your "MCP disabled, fails after 2-3 tool calls" scenario
What was fixed
The root cause was tool_calls being lost during message merging. When Codex CLI sends multiple assistant messages with tool_calls consecutively, the gateway was losing the second and subsequent tool_calls. This caused Kiro API to return
{"message":"Improperly formed request.","reason":null}because it receivedtoolResultwithout a correspondingtoolUse.What to test
Update to v1.0.4: https://github.com/jwadow/kiro-openai-gateway/releases/tag/v1.0.4
Test your 3rd "MCP disabled" scenario - this should now work ✅
Test your 2nd "48 MCP tools" scenario - this one I'm less certain about. If it still fails, it might be hitting Kiro API's payload size limits. Please report back!
New debugging feature
If you still encounter issues, v1.0.4 has a new debug mode that's much more convenient:
DEBUG_MODE=errors # Only saves logs when requests fail (4xx, 5xx)P.S. Again, report about your issues. We'll investigate further. If the issues persist, we need you to attach both files for each problem. Because I definitely won't install 48 MCP tools 🤑
@stunl0ck commented on GitHub (Dec 17, 2025):
v1.0.4 is working great!
Tested with MCP tools enabled (48 tools) + agent-mode workflow using Codex CLI and all requests succeeding, multiple tool calls in a row, no more "Improperly formed request" errors.
Logs showing consistent 200s:
POST /v1/chat/completions (model=claude-opus-4-5, stream=True) 200 OK
POST /v1/chat/completions (model=claude-opus-4-5, stream=True) 200 OK
... (many more)
The tool_calls merging fix was exactly what was needed. Thanks for the quick turnaround! 😄