opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Read tool crashes with "Binding expected string" error when Instance context is unavailable

Open sureshsankaran opened this issue 23 hours ago • 0 comments

Bug Description

The Read tool throws a cryptic error when executed outside of an Instance context:

TypeError: Binding expected string, TypedArray, boolean, number, bigint or null

Root Cause

In src/tool/read.ts line 28, Instance.worktree is accessed directly without error handling:

const title = path.relative(Instance.worktree, filepath)

When the Instance context (AsyncLocalStorage) is not available:

  1. Instance.worktree throws Context.NotFound
  2. Before that propagates, path.relative() receives undefined
  3. path.relative() is a native Bun binding that throws the cryptic error

When This Occurs

  • MCP server tool execution paths
  • Plugin tool invocations
  • Direct tool testing without full server bootstrap
  • Any code path that does not go through Instance.provide()

Expected Behavior

The Read tool should gracefully handle missing Instance context and fall back to reasonable defaults (e.g., path.basename() for the title).

Reproduction

This is an edge case that occurs when tools are executed outside the normal server middleware flow. It was discovered while using the ralph-wiggum plugin for iterative development loops.

sureshsankaran avatar Jan 13 '26 23:01 sureshsankaran