anomalyco / anomalyco/opencode
glob.path description can trigger unstable tool-calling behavior with llama.cpp/Qwen3-Coder
@neriousy is already working on this.
Since Aug 23, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
I found that the current description of the optional path parameter in the
built-in glob tool can trigger unstable tool-calling behavior when using
OpenCode with Qwen3-Coder through llama.cpp.
The current description is:
The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.
I confirmed this description is currently defined in:
packages/opencode/src/tool/glob.ts
Observed behavior
With Qwen3-Coder running through llama.cpp, the tool-calling behavior became
unstable when this description was present.
Depending on the model output, I observed:
- valid
globtool calls - repeated text instead of a tool call
- malformed tool-call-like text
- degenerate arguments containing repeated
? - in one case, llama.cpp aborted the request with:
Unexpected empty grammar stack after accepting piece: ? (30)
The underlying grammar crash appears to be a llama.cpp issue and I am reporting
that separately.
However, I found that simplifying the OpenCode tool description avoids the
problem in practice.
Workaround tested
I used OpenCode's tool.definition hook to rewrite only the glob.path
description to:
The directory to search in. If omitted, the current working directory is used. Must be a valid directory path if provided.
No behavior or schema structure was changed.
After applying this patch, OpenCode successfully executed the glob tool with
the same local model/backend.
Example:
> build · hermes-coder
✱ Glob "src/**/*.ts" 10 matches
1. /home/aaronmunguia/Code/hermes-agent-runtime/src/index.ts
2. /home/aaronmunguia/Code/hermes-agent-runtime/src/tools/weather.ts
3. /home/aaronmunguia/Code/hermes-agent-runtime/src/graph/agent.ts
Proposed change
I suggest simplifying the current description from:
The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.
to something like:
The directory to search in. If omitted, the current working directory is used. Must be a valid directory path if provided.
This keeps the same semantics while:
- reducing schema prompt length
- removing redundant negative instructions
- improving compatibility with local/open-source tool-calling models
- avoiding a generation pattern that exposed a llama.cpp grammar failure in my setup
Environment
OpenCode:
- 1.18.21
Model:
- Qwen3-Coder-30B-A3B-Instruct
- Q4_K_M GGUF
Backend:
- llama.cpp OpenAI-compatible
/v1/chat/completions --jinja- HIP / ROCm
llama.cpp:
- build b10587
- commit 3f545becc
OS:
- Fedora Linux
Additional note
The llama.cpp failure is output-dependent and not deterministic.
I do not think the OpenCode description itself is the root cause of the grammar
bug. Rather, the wording appears to influence the model's generated token path,
and some of those paths can expose the backend grammar issue.
The reason I am reporting this to OpenCode is that the description can be
simplified without losing any useful information, and the simpler version worked
reliably in my setup.
Plugins
No response
OpenCode version
1.18.21
Steps to reproduce
-
Configure OpenCode to use a local OpenAI-compatible backend served by llama.cpp.
-
Use Qwen3-Coder-30B-A3B-Instruct as the model.
-
Make sure the built-in
globtool is enabled with the currentpathparameter description:
The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.
- Run a prompt that forces a
globtool call, for example:
Use glob exactly once to find TypeScript files under src/.
After the tool returns, respond with only the first 3 file paths.
Do not use any other tool.
-
Repeat the request several times.
-
Observe that tool-calling can become unstable depending on the generated output. I observed different behaviors across runs, including:
- valid
globtool calls - repeated plain-text output instead of a tool call
- malformed tool-call-like text
- degenerate tool arguments containing repeated
? - one llama.cpp request abort with:
Unexpected empty grammar stack after accepting piece: ? (30)
- Patch only the
glob.pathdescription using OpenCode'stool.definitionhook to:
The directory to search in. If omitted, the current working directory is used. Must be a valid directory path if provided.
-
Restart OpenCode and run the same prompt again.
-
With the simplified description,
globtool calling works correctly in my setup.
Reproducibility note
The llama.cpp grammar failure is output-dependent and not deterministic, so the issue may not reproduce on every request.
The main reproducible observation on my setup is that simplifying only the glob.path description removes the unstable behavior without changing the tool schema or semantics.
Screenshot and/or share link
No response
Operating System
Fedora 44 Linux
Terminal
Kitty
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.