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

Closed
opened 2026-02-16 17:53:02 -05:00 by yindo · 0 comments
Owner

Originally created by @sureshsankaran on GitHub (Jan 13, 2026).

Originally assigned to: @rekram1-node on GitHub.

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.

Originally created by @sureshsankaran on GitHub (Jan 13, 2026). Originally assigned to: @rekram1-node on GitHub. ## 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: ```typescript 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.
yindo closed this issue 2026-02-16 17:53:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5466