anomalyco / anomalyco/opencode

"Unavailable tool" error message lists every available tool, burning thousands of tokens on repeated occurrences

Open
#41,047 0 comments 1 reaction 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 7, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Related upstream trigger: #33618 (Qwen via OpenRouter sporadically emits phantom/invalid tool calls). This issue is about the cost of the error response, which is independent of that bug.

When a model emits a malformed/invalid tool call (e.g. a phantom unknown tool call, which happens occasionally with some models during parallel tool batching), the harness responds with an error message that enumerates the complete list of available tools:

The arguments provided to the tool are invalid: Model tried to call unavailable
tool 'unknown'. Available tools: <full list of 100+ tool names…>

In a session with many MCP servers configured (~130 tools in my setup), each of these error messages injects several thousand tokens into the context. The underlying model behavior can repeat dozens of times in a single session (observed with openrouter/qwen/qwen3.8-max), so this adds up to a very large amount of wasted tokens and cost — far more than the invalid call itself.

A secondary effect: when the invalid call is part of a parallel batch, sibling tool calls in the same batch sometimes get aborted ("Tool execution aborted"), forcing the agent to re-issue them — more tokens and slower progress.

Expected behavior

The error should be minimal and actionable, e.g.:

Tool 'unknown' is not available. See the system prompt for the list of available tools.

The model already has the tool list in its system prompt; repeating it in every error message provides no additional value and is very expensive.

Suggested fix
  • Truncate/omit the Available tools: … enumeration from the error message (or cap it to a short prefix / first N names).
  • Optionally, deduplicate: if the same invalid-tool error already occurred in the session, return an even shorter message on repeats.
Environment
  • opencode CLI (latest at time of writing)
  • Model: openrouter/qwen/qwen3.8-max (observed repeatedly), likely model-agnostic
  • Setup: ~130 tools configured via MCP servers (supabase, atlascloud, cloudflare, agentmemory, etc.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.