anomalyco / anomalyco/opencode

read tool: offset validation error message is misleading (says >=0 but schema requires >0)

Open
#46,807 2 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Sep 2, 2026.

2.0
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

  1. 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)
  2. Ask the agent to read a file, e.g. Read .local\share\opencode\log\opencode.log
  3. If the model generates offset: -1 in 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:

  1. Misleading error message: The schema uses PositiveInt (which is Int.check(isGreaterThan(0)) = ≥ 1), but the error says "greater than or equal to 0" — this is the NonNegativeInt constraint, not PositiveInt. The error message doesn't match the actual validation.

  2. Optional parameter should not cause hard failure: offset is defined as optional in PageInput. 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):

  1. Fix error message to say "greater than 0" (match the actual PositiveInt constraint)
  2. Change schema to NonNegativeInt so offset 0 is allowed (0 is a valid file offset)
  3. For optional parameters, drop invalid values silently and use defaults instead of failing

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.