[GH-ISSUE #34] BUG: Dead loop failed to write file #23

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

Originally created by @ykswang on GitHub (Jan 12, 2026).
Original GitHub issue: https://github.com/jwadow/kiro-gateway/issues/34

Kiro Gateway Version

v2.0.0

What happened?

opencode error:

Error: The write tool was called with invalid arguments: [
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "content"
    ],
    "message": "Invalid input: expected string, received undefined"
  },
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "filePath"
    ],
    "message": "Invalid input: expected string, received undefined"
  }
].
Please rewrite the input so it satisfies the expected schema.

gateway log:
2026-01-12 21:37:42 | INFO | logging:callHandlers:1737 - 127.0.0.1:60307 - "POST /v1/messages HTTP/1.1" 200
2026-01-12 21:38:59 | WARNING | kiro.parsers:_finalize_tool_call:415 - Failed to parse tool 'write' arguments: Expecting ',' delimiter: line 1 column 88 (char 87). Raw: {"filePath": "/Users/cc/Documents/Code/mock-all/docs/plans/2026-01-12-mock-all-impl.md"
2026-01-12 21:38:59 | INFO | kiro.routes_anthropic:stream_wrapper:288 - HTTP 200 - POST /v1/messages (streaming) - completed
2026-01-12 21:39:02 | INFO | kiro.routes_anthropic:messages:144 - Request to /v1/messages (model=claude-opus-4-5, stream=True)
2026-01-12 21:39:05 | INFO | logging:callHandlers:1737 - 127.0.0.1:60307 - "POST /v1/messages HTTP/1.1" 200
2026-01-12 21:40:19 | WARNING | kiro.parsers:_finalize_tool_call:415 - Failed to parse tool 'write' arguments: Expecting ',' delimiter: line 1 column 88 (char 87). Raw: {"filePath": "/Users/cc/Documents/Code/mock-all/docs/plans/2026-01-12-mock-all-impl.md"
2026-01-12 21:40:19 | INFO | kiro.routes_anthropic:stream_wrapper:288 - HTTP 200 - POST /v1/messages (streaming) - completed

claude code failed,too

Debug Logs

Image Image
Originally created by @ykswang on GitHub (Jan 12, 2026). Original GitHub issue: https://github.com/jwadow/kiro-gateway/issues/34 ### Kiro Gateway Version v2.0.0 ### What happened? opencode error: ``` Error: The write tool was called with invalid arguments: [ { "expected": "string", "code": "invalid_type", "path": [ "content" ], "message": "Invalid input: expected string, received undefined" }, { "expected": "string", "code": "invalid_type", "path": [ "filePath" ], "message": "Invalid input: expected string, received undefined" } ]. Please rewrite the input so it satisfies the expected schema. ``` gateway log: 2026-01-12 21:37:42 | INFO | logging:callHandlers:1737 - 127.0.0.1:60307 - "POST /v1/messages HTTP/1.1" 200 2026-01-12 21:38:59 | WARNING | kiro.parsers:_finalize_tool_call:415 - Failed to parse tool 'write' arguments: Expecting ',' delimiter: line 1 column 88 (char 87). Raw: {"filePath": "/Users/cc/Documents/Code/mock-all/docs/plans/2026-01-12-mock-all-impl.md" 2026-01-12 21:38:59 | INFO | kiro.routes_anthropic:stream_wrapper:288 - HTTP 200 - POST /v1/messages (streaming) - completed 2026-01-12 21:39:02 | INFO | kiro.routes_anthropic:messages:144 - Request to /v1/messages (model=claude-opus-4-5, stream=True) 2026-01-12 21:39:05 | INFO | logging:callHandlers:1737 - 127.0.0.1:60307 - "POST /v1/messages HTTP/1.1" 200 2026-01-12 21:40:19 | WARNING | kiro.parsers:_finalize_tool_call:415 - Failed to parse tool 'write' arguments: Expecting ',' delimiter: line 1 column 88 (char 87). Raw: {"filePath": "/Users/cc/Documents/Code/mock-all/docs/plans/2026-01-12-mock-all-impl.md" 2026-01-12 21:40:19 | INFO | kiro.routes_anthropic:stream_wrapper:288 - HTTP 200 - POST /v1/messages (streaming) - completed claude code failed,too ### Debug Logs <img width="1387" height="1273" alt="Image" src="https://github.com/user-attachments/assets/b8d6634a-d9d4-4cca-91a0-465145e9ecf1" /> <img width="1723" height="315" alt="Image" src="https://github.com/user-attachments/assets/f2913985-1620-4401-a193-1569e9f29190" />
kerem 2026-02-27 07:17:29 +03:00
Author
Owner

@ykswang commented on GitHub (Jan 12, 2026):

kiro_request_body.json
request_body.json
response_stream_raw.txt

<!-- gh-comment-id:3738763063 --> @ykswang commented on GitHub (Jan 12, 2026): [kiro_request_body.json](https://github.com/user-attachments/files/24566419/kiro_request_body.json) [request_body.json](https://github.com/user-attachments/files/24566417/request_body.json) [response_stream_raw.txt](https://github.com/user-attachments/files/24566418/response_stream_raw.txt)
Author
Owner

@jwadow commented on GitHub (Jan 14, 2026):

Hey, thanks for the logs.
Figured it out - this is not a Kiro Gateway bug.

Kiro API truncates the stream when tool call arguments are too large. Claude was trying to write a huge plan to a file, but the API cut off after filePath, never sending content. Results in broken JSON.

The dead loop happens because OpenCode does not handle repeated failures. When write fails 2-3 times with the same error, OpenCode should inject an ephemeral system message to hint the model to change approach. Without such hints, Claude just keeps retrying the same thing forever.

Added clearer logging for these cases, but cannot fix the core issue.

I suggest opening an issue in the OpenCode repo - they need to add handling for repeated tool call failures via "ephemeral hints".

Workaround: ask the model to write large files in chunks.

<!-- gh-comment-id:3751763951 --> @jwadow commented on GitHub (Jan 14, 2026): Hey, thanks for the logs. Figured it out - this is not a Kiro Gateway bug. Kiro API truncates the stream when tool call arguments are too large. Claude was trying to write a huge plan to a file, but the API cut off after filePath, never sending content. Results in broken JSON. The dead loop happens because OpenCode does not handle repeated failures. When write fails 2-3 times with the same error, OpenCode should inject an ephemeral system message to hint the model to change approach. Without such hints, Claude just keeps retrying the same thing forever. Added clearer logging for these cases, but cannot fix the core issue. I suggest opening an issue in the OpenCode repo - they need to add handling for repeated tool call failures via "ephemeral hints". **Workaround: ask the model to write large files in chunks.**
Author
Owner

@g0dev commented on GitHub (Jan 14, 2026):

"message": "Invalid input: expected string, received undefined"

I also started seeing this only recently. Before this it was working fine for the same kind of write tool calls.

So it looks like Kiro API might have changed something and is now truncating the stream more aggressively when the tool arguments get big.

<!-- gh-comment-id:3752090406 --> @g0dev commented on GitHub (Jan 14, 2026): > "message": "Invalid input: expected string, received undefined" I also started seeing this only recently. Before this it was working fine for the same kind of write tool calls. So it looks like Kiro API might have changed something and is now truncating the stream more aggressively when the tool arguments get big.
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#23
No description provided.