Skip to content

fix(cli): surface real tool name when tool call repair fails - #13446

Merged
johnnyeric merged 9 commits into
Kilo-Org:mainfrom
maphew:fix/repair-invalid-tool-surfaces-real-name
Sep 1, 2026
Merged

fix(cli): surface real tool name when tool call repair fails#13446
johnnyeric merged 9 commits into
Kilo-Org:mainfrom
maphew:fix/repair-invalid-tool-surfaces-real-name

Conversation

@maphew

@maphew maphew commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

What

When a model emits a tool call that cannot be repaired by case-insensitive matching, experimental_repairToolCall renamed the call to the hidden invalid tool. That tool is deliberately excluded from activeTools, so the AI SDK rejected the repaired call with a confusing, self-inflicted error:

Model tried to call unavailable tool 'invalid'. Available tools: question, bash, read, glob, grep, task, webfetch, todowrite, websearch, codesearch.

invalid is not in the available list, and the message does not say which tool the model actually tried to call, so the model cannot self-correct.

Why

Users hit this repeatedly (#6905). The invalid fallback never executes in practice: activeTools filters it out of the execution tool set, so the repair path produces a NoSuchToolError for invalid instead of the intended "invalid arguments" feedback. The same confusion also contributes to retry loops like #11844, where a model cannot learn from the error.

Change

The repair function now returns null when it cannot map the tool call to a real tool. The AI SDK then surfaces the original error with the actual tool name and the available tool list:

Model tried to call unavailable tool 'Write'. Available tools: question, bash, read, glob, grep, task, webfetch, todowrite, websearch, codesearch.

The model now sees exactly what it emitted and which tools exist, so it can repair the call itself (case mismatch, wrong tool, or malformed arguments all report truthfully).

Verification

  • New regression test drives the full AI SDK stream with a model tool call to a non-existent Write tool and asserts the tool-error event names Write and does not mention invalid. The test fails against the old code with the exact reported message and passes with the fix.
  • bun test ./test/session/llm.test.ts — 31 pass, 0 fail.
  • bun run typecheck in packages/opencode — clean.
  • bun run script/check-opencode-annotations.ts --worktree — clean.

Related

maphew and others added 3 commits August 26, 2026 04:21
When the model emits a malformed tool call that cannot be repaired by
case-insensitive matching, experimental_repairToolCall renamed the call
to the hidden "invalid" tool. That tool is excluded from activeTools,
so the AI SDK rejected it with a confusing "unavailable tool 'invalid'"
error that did not tell the model what it did wrong.

Return null instead so the original NoSuchToolError or
InvalidToolInputError surfaces with the actual tool name and the list of
available tools, letting the model self-correct.

Fixes Kilo-Org#6905

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
The experimental_repairToolCall fallback that produced tool calls named
"invalid" was replaced with null in this PR, so nothing generates
"invalid" tool calls anymore. Remove the now-orphaned InvalidTool
definition, its registry registration, and its TUI renderer, along with
the parameters test and snapshot that covered it.

Agent-Signature: kilo-auto/efficient-remove-orphaned-invalid-tool on behalf of maphew
@maphew
maphew marked this pull request as ready for review August 26, 2026 20:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6176d61f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import { WebFetchTool } from "./webfetch"
import { WriteTool } from "./write"
import { InvalidTool } from "./invalid"
import { SkillTool } from "./skill"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the upstream invalid-tool cleanup out of this fix

Returning null from the repair callback is sufficient to correct the reported behavior, but this hunk also begins an unnecessary cleanup that deletes the upstream invalid tool and modifies its registry, CLI renderer, and schema tests across five shared files. Retaining that now-unused definition avoids expanding Kilo's upstream delta and the resulting merge-conflict surface; the repository explicitly requires shared-file changes to be minimal and prohibits unnecessary upstream refactoring.

AGENTS.md reference: AGENTS.md:L185-L190

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed: the invalid-tool cleanup was reverted in 4c2b02e (Revert "refactor(tool): remove orphaned invalid tool"), restoring packages/opencode/src/tool/invalid.ts, the registry registration, the TUI renderer, and the schema test/snapshot to their upstream state. The branch now touches only the repair callback in session/llm.ts plus its regression test and changeset — the upstream diff is minimal again.

@kilo-code-bot

kilo-code-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • .changeset/invalid-tool-repair-surfaces-real-name.md
  • packages/opencode/src/session/llm.ts
  • packages/opencode/test/session/llm.test.ts
Previous Review Summary (commit f6176d6)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit f6176d6)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (8 files)
  • .changeset/invalid-tool-repair-surfaces-real-name.md
  • packages/opencode/src/cli/cmd/run/tool.ts
  • packages/opencode/src/session/llm.ts
  • packages/opencode/src/tool/invalid.ts
  • packages/opencode/src/tool/registry.ts
  • packages/opencode/test/session/llm.test.ts
  • packages/opencode/test/tool/__snapshots__/parameters.test.ts.snap
  • packages/opencode/test/tool/parameters.test.ts

Reviewed by grok-4.6 · Input: 132.4K · Output: 7.7K · Cached: 267.3K

Review guidance: REVIEW.md from base branch main

maphew and others added 5 commits August 26, 2026 13:33
This reverts commit f6176d6.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…-name

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…tool-surfaces-real-name

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…shard)

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

maphew commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Merge-readiness check complete:

  • Codex finding addressed: the unrelated invalid-tool cleanup was reverted (4c2b02e); the branch now touches only the repair callback in session/llm.ts plus its regression test and changeset.
  • Branch synced with main (0 behind), no merge conflicts.
  • CI green (all checks pass).
  • New regression test verified locally.

Ready for human review.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@johnnyeric
johnnyeric merged commit f1330ac into Kilo-Org:main Sep 1, 2026
31 checks passed
@johnnyeric

Copy link
Copy Markdown
Contributor

Thanks @maphew for the contribution. Was able to reproduce the fix and it's now merged.

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.

Kilo CLI throws "unavailable tool 'invalid'" error when attempting file operations

2 participants