Skip to content

fix(session): distinguish malformed known-tool input from unknown tools#25788

Closed
johanhallberg wants to merge 1 commit into
anomalyco:devfrom
johanhallberg:fix/known-tool-malformed-input
Closed

fix(session): distinguish malformed known-tool input from unknown tools#25788
johanhallberg wants to merge 1 commit into
anomalyco:devfrom
johanhallberg:fix/known-tool-malformed-input

Conversation

@johanhallberg

@johanhallberg johanhallberg commented May 5, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #25789

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR distinguishes two different tool-call repair failure cases:

  1. A model calls a tool that does not exist.
  2. A model calls a valid/known tool, but the tool input is malformed.

Previously, both cases were routed through the invalid tool in a way that made malformed input for a valid tool look like a generic invalid/unknown tool call.

The change extracts the classification logic into repairToolCallFailure() and keeps the existing lowercase tool-name repair behavior.

The invalid tool now accepts optional type and hint fields so callers can distinguish:

  • unknown_tool
  • known_tool_invalid_input

This gives users and maintainers clearer feedback when a valid tool was selected but its input could not be parsed.

How did you verify your code works?

Tested locally with:

cd packages/opencode
bun test --timeout 30000 test/session/llm.test.ts
bun test --timeout 30000 test/tool/parameters.test.ts
bun run typecheck

Results:

  • test/session/llm.test.ts: 17 pass, 0 fail
  • test/tool/parameters.test.ts: 54 pass, 0 fail
  • bun run typecheck: pass

I also ran a manual smoke test with a patched source build:

  • normal write tool usage still works
  • large single-write requests still work
  • intentionally unknown tool calls are reported as unknown_tool
  • malformed input for a known tool is covered by regression tests

Screenshots / recordings

N/A — this is not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

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

Based on my search, I found two potentially related PRs:

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

    • Related because it also addresses tool input repair and validation in LLM sessions
  2. PR fix: prevent invalid tool from leaking into model error messages #23264: "fix: prevent invalid tool from leaking into model error messages"

    • Related because it deals with how invalid tool calls are handled and reported in the session

These PRs share similar concerns around tool-call handling, error classification, and session management, though they may be addressing different aspects of the problem.

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@johanhallberg

Copy link
Copy Markdown
Author

Thanks — I checked the related issues.

This PR is intentionally narrow. It does not try to solve all malformed/truncated tool-call recovery behavior. It only distinguishes the repair result for two cases that currently collapse into the same invalid path:

  1. unknown tool name → type: "unknown_tool"
  2. known tool name with malformed/unparseable input → type: "known_tool_invalid_input"

This should complement, not replace, the broader recovery work discussed in #18108, #15906, and #21900.

The goal is to give downstream handling and users a clearer error classification without changing the existing lowercase tool-name repair behavior.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed input for a known tool is reported like an unknown tool call

1 participant