opencode
opencode copied to clipboard
Read tool crashes with "Binding expected string" error when Instance context is unavailable
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:
Instance.worktreethrowsContext.NotFound- Before that propagates,
path.relative()receivesundefined 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.