anomalyco / anomalyco/opencode
read tool: offset validation error message is misleading (says >=0 but schema requires >0)
@neriousy is already working on this.
Since Sep 2, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Summary
The read tool's offset parameter validation error message is misleading: it says "Expected a value greater than or equal to 0" but the actual schema requires PositiveInt (> 0, i.e. ≥ 1). Additionally, LLM models occasionally hallucinate offset: -1 for the optional parameter, triggering the validation error.
Environment
- opencode version: 0.0.0-beta-18866
- OS: Windows_NT 10.0.26200 (win32 x64)
- Terminal: Unavailable (desktop Electron app)
- Shell: pwsh (PowerShell 7)
- Install/channel: beta (OpenCode Desktop)
- Active plugins:
./plugins/opencode-image,op-anthropic-auth-v2,opencode-mermaid-renderer@0.0.3
Reproduction
- Open a session in OpenCode Desktop with any model that may hallucinate optional parameters (e.g. free models like MiMo V2.5, DeepSeek V4 Flash Free, or similar)
- Ask the agent to read a file, e.g.
Read .local\share\opencode\log\opencode.log - If the model generates
offset: -1in the tool call arguments, the read tool fails with a validation error
Note: This is intermittent — it depends on whether the LLM model decides to explicitly pass the optional offset parameter with an invalid value.
Expected Behavior
The error message should accurately reflect the schema constraint. The schema defines offset as PositiveInt (> 0), so the error should say "Expected a value greater than 0" or "Expected a positive integer". Alternatively, the schema could be relaxed to NonNegativeInt (≥ 0) since offset 0 is a valid starting position.
Additionally, optional parameters with invalid values could be silently dropped (treated as absent) rather than throwing a hard error, especially for read-only operations.
Actual Behavior
When a model generates offset: -1:
Invalid arguments for tool "read":
- offset: Expected a value greater than or equal to 0
Arguments provided:
{
"path": "C:\\Users\\...\\.local\\share\\opencode\\log\\opencode.log",
"offset": -1,
"limit": 2000
}
Two issues:
-
Misleading error message: The schema uses
PositiveInt(which isInt.check(isGreaterThan(0))= ≥ 1), but the error says "greater than or equal to 0" — this is theNonNegativeIntconstraint, notPositiveInt. The error message doesn't match the actual validation. -
Optional parameter should not cause hard failure:
offsetis defined as optional inPageInput. When the model provides an invalid value for an optional parameter, the tool should either use the default or drop the invalid value, not fail entirely.
Additional Context
Schema code (from bundled node-BBwF64dM.js):
// Line 53750-53751:
PositiveInt = exports_Schema.Int.check(exports_Schema.isGreaterThan(0)); // > 0 (i.e. ≥ 1)
NonNegativeInt = exports_Schema.Int.check(exports_Schema.isGreaterThanOrEqualTo(0)); // ≥ 0
// Line 396510:
PageInput = exports_Schema.Struct({
offset: PositiveInt.pipe(exports_Schema.optional), // requires ≥ 1, but error says ≥ 0
limit: PositiveInt.check(exports_Schema.isLessThanOrEqualTo(MAX_READ_LINES)).pipe(exports_Schema.optional)
});
Proposed fixes (pick one or combine):
- Fix error message to say "greater than 0" (match the actual
PositiveIntconstraint) - Change schema to
NonNegativeIntso offset 0 is allowed (0 is a valid file offset) - For optional parameters, drop invalid values silently and use defaults instead of failing
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.