Skip to content

Multiple get_file_diff tool calls fail with concatenated JSON arguments #110

Open

Description

@pr0g88

Bug description

Proval fails during the planning step when reviewing a merge request that changes multiple files.

A review of an MR with a single changed file completes successfully. When the MR contains multiple changed files, Proval fails while processing get_file_diff tool calls.

Environment

  • Proval image: ghcr.io/seoes/proval:latest
  • Git provider: GitLab
  • Model: nemotron-3-ultra
  • LLM proxy: LiteLLM

Logs

For an MR with multiple changed files:

[Setup]
fetching pull request version
[Setup]
version ready head=37…
[Setup]
building pull request prompt
[Plan]
loop started
[Plan]
step 1: 1 tool call(s)
[Plan]
Get File Diff
{"filePath": "file1.py"}{"filePath": "file2.py"}{"filePath": "file3.py"}
[Plan]
Error · get_file_diff
JSON Parse error: Unable to parse JSON string
[Plan]
agent loop failed: JSON Parse error: Unable to parse JSON string

Activity

  1. added
    bug
    on Nov 20, 2026
  2. proval-0e6d07 commented on Nov 20, 2026

    @proval-0e6d07

    @pr0g88 Thanks for the logs. This does not look like a duplicate of an existing issue.

    The failure is in argument parsing, not GitLab or get_file_diff itself. get_file_diff only accepts one filePath string (apps/api/src/agent/pull-request/tool/get-file-diff.ts). The plan step received one tool call whose arguments are three JSON objects stuck together:

    {"filePath": "file1.py"}{"filePath": "file2.py"}{"filePath": "file3.py"}

    apps/api/src/agent/llm/loop.ts does JSON.parse(tc.arguments) and rethrows on failure, which matches agent loop failed: JSON Parse error: Unable to parse JSON string. Tool execute errors are returned to the model. Parse errors abort the whole plan loop. A single-file MR works because that string is valid JSON.

    Two likely sources, both consistent with step 1: 1 tool call(s):

    1. Streaming merge. OpenAI-compatible streaming in apps/api/src/agent/llm/openai.ts (accumulateChatCompletionStream) keys tool calls by tool_calls[].index and concatenates arguments. A missing index becomes 0. If LiteLLM or nemotron-3-ultra emits several get_file_diff calls with no index, or all index: 0, Proval will fold them into one call and concatenate the JSON. Tests in openai.streaming.test.ts only cover distinct indices.
    2. Model output. The model put concatenated JSON in a single arguments field. There is no splitter today.

    Either way Proval should not die here. Practical fixes:

    • Treat a new id at the same stream index as a new tool call, instead of appending arguments.
    • Split concatenated JSON objects into separate calls (or parse the first object and return a recoverable error for the rest).
    • On JSON.parse failure, return a tool error to the model instead of throwing, same as execute failures.

    If you can grab one raw LiteLLM stream chunk (or a non-streamed response) for a multi-file MR, the useful check is whether several tool_calls share index: 0 or omit index. That distinguishes a Proval merge bug from the model writing concatenated JSON. A single-file vs multi-file pair of those dumps would be enough.

  3. self-assigned this
    on Nov 22, 2026
  4. seoes commented on Nov 22, 2026

    @seoes
    Owner

    Hi @pr0g88!

    First of all, thanks for using Proval and reporting this issue

    Looks like tool call from LiteLLM got no index value so Proval push them as same index's value

    I made some update to parse those request to have their own index number and retry with failed tool call

    You can try docker image with version 0.4.1 or latest

    If you find any other issues, feel free to open additional issue

  5. pr0g88 commented on Nov 23, 2026

    @pr0g88
    Author

    Thanks for the fix. The issue is still reproducible with a multi-file MR.

    Proval logs one Get File Diff tool call with concatenated JSON arguments:
    {"filePath": "file1.py"}{"filePath": "file2.py"}{"filePath": "file3.py"}

    It then logs a JSON parse error. The subsequent LiteLLM request fails in the Ollama request transformation:
    json.loads(typed_tool["function"]["arguments"])
    JSONDecodeError: Extra data: line 1 column 29

    This suggests the malformed tool call is still being included in the conversation history sent on the next model call. The retries appear to resend the same invalid arguments and fail identically.

  6. seoes commented on Nov 23, 2026

    @seoes
    Owner

    Hi @pr0g88

    Looks like the Ollama case with LiteLLM was fixed in BerriAI/litellm#49183. It should return index for each tool calling

    The fix is in v1.108.5 and later (latest v1.108.15), but not in v1.109.x or v1.110.x yet. Can you try with one of those?

    If the error still occurs, let me know which LiteLLM version you're running and I'll look into it.

  7. reopened this on Nov 23, 2026
  8. pr0g88 commented on Nov 23, 2026

    @pr0g88
    Author

    Thanks, you were right. I was running an older LiteLLM version. I’ll upgrade to v1.108.15 and test again.

  9. seoes commented on Nov 23, 2026

    @seoes
    Owner

    Great. Please let me know if it works. I should made an document for it

    and again, thanks for reporting this issue. Agent loop got more reliable when tool calling failed (not only using litellm) thanks to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions