Skip to content

fix(session): detect empty tool args from gpt-5.5 and prevent abort loop#25511

Closed
codeg-dev wants to merge 1 commit intoanomalyco:devfrom
codeg-dev:fix-gpt55-empty-tool-args
Closed

fix(session): detect empty tool args from gpt-5.5 and prevent abort loop#25511
codeg-dev wants to merge 1 commit intoanomalyco:devfrom
codeg-dev:fix-gpt55-empty-tool-args

Conversation

@codeg-dev
Copy link
Copy Markdown

@codeg-dev codeg-dev commented May 3, 2026

Description

Fixes #20227

This PR addresses the recurring Tool execution aborted errors experienced when using gpt-5.5 (and other models) that cause empty or invalid tool arguments during streaming JSON serialization. This manifests as an infinite abort loop in the apply_patch tool, rendering the model unusable for file modification tasks.

The ai SDK, when streaming tool arguments as JSON, occasionally serializes complex multiline strings (like patchText) as an empty {} when the model provides malformed or truncated JSON. This empty payload is then passed to the tool execution layer, which aborts because required parameters are missing. Because the model receives the same invalid history on retry, it repeats the error, creating a doom loop.

Changes

  1. llm.tsexperimental_repairToolCall: Added detection for empty tool arguments (rawInput == null or Object.keys(rawInput).length === 0). When detected for the apply_patch tool, it injects a structured error message directing the model to retry with valid arguments, rather than letting the tool executor abort.
  2. processor.tstool-call event handler: Added an early-exit guard that immediately fails a tool call with a clear error message if the input arguments are empty. This prevents the tool from even starting execution and avoids the downstream Tool execution aborted loop.

References

Notes

This is a runtime-level mitigation, not a complete fix for the underlying model behavior. It prevents the abort loop by:

  • Intercepting invalid tool calls before they reach the executor.
  • Providing the model with feedback to retry.
  • Falling back gracefully instead of crashing.

A more fundamental fix would require changes in how the ai SDK or the model serializes streaming JSON, tracked in the upstream PRs referenced above.

Checklist

  • I have read the CONTRIBUTING.md guide.
  • My code follows the existing style in the affected files.
  • I have run bun typecheck and it passes.
  • I have added tests (if applicable).
  • I have updated documentation (if applicable).

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate/Related PRs Found:

  1. PR fix: Repair truncated JSON tool inputs in LLM session #24289: "fix: Repair truncated JSON tool inputs in LLM session"

    • Directly related: addresses truncated/malformed JSON in tool inputs, which is the core issue this PR tackles
  2. PR fix(opencode): repair malformed JSON in tool call arguments #23067: "fix(opencode): repair malformed JSON in tool call arguments"

    • Related: handles repair of malformed JSON in tool arguments, overlapping with the experimental_repairToolCall logic
  3. PR fix: prevent invalid tool from leaking into model error messages #23264: "fix: prevent invalid tool from leaking into model error messages"

    • Related: deals with invalid tool error handling and message construction to prevent feedback loops
  4. PR feat(processor): add plugin stream hooks for tool streaming lifecycle #25245: "feat(processor): add plugin stream hooks for tool streaming lifecycle"

    • Potentially related: affects tool streaming behavior which could interact with the tool argument validation added in this PR

These PRs all address aspects of tool execution robustness and error handling. PR #24289 appears to be the closest match as it specifically targets truncated/malformed JSON in tool inputs.

@codeg-dev codeg-dev marked this pull request as ready for review May 3, 2026 01:45
@codeg-dev
Copy link
Copy Markdown
Author

Clarification on Related PRs

I see the bot flagged several related PRs (#24289, #23067, #23264). Here's how this PR differs:

#24289 / #23067 (both targeting llm.ts JSON repair) — These focus on repairing malformed JSON once a tool call is already received. Our PR adds detection at the source — when args are completely empty, we prevent the tool from even executing and provide clear retry feedback.

#23264 (prevent invalid tool error leaking) — Addresses error message construction in tool error handling, not empty argument detection.

Our unique contribution:

  • Dual protection: llm.ts intercepts at the LLM level + processor.ts guards at the execution level
  • No-op safety: Empty args trigger immediate failToolCall with descriptive error, preventing the doom loop
  • Model-agnostic: Works for any model that produces empty tool args, not just gpt-5.5

This complements rather than duplicates the JSON repair work in #24289/#23067.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 3, 2026
@github-actions github-actions Bot closed this May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] GPT-5.4 repeatedly sends empty apply_patch tool calls ({}), causing Tool execution aborted, while GPT-5.3 Codex does not

1 participant