Skip to content

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

@sureshsankaran

Description

@sureshsankaran

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions