fix: handle missing Instance context in Read tool#8302
Closed
sureshsankaran wants to merge 1 commit intoanomalyco:devfrom
Closed
fix: handle missing Instance context in Read tool#8302sureshsankaran wants to merge 1 commit intoanomalyco:devfrom
sureshsankaran wants to merge 1 commit intoanomalyco:devfrom
Conversation
When the Read tool is executed outside of an Instance context (e.g., via MCP servers, plugins, or other non-standard code paths), accessing Instance.worktree throws a Context.NotFound exception. However, before this exception propagates, path.relative() receives undefined and throws a cryptic native binding error: TypeError: Binding expected string, TypedArray, boolean, number, bigint or null This fix gracefully handles missing Instance context by: 1. Wrapping Instance.worktree access in try-catch in read.ts 2. Wrapping Instance.containsPath() in try-catch in external-directory.ts 3. Falling back to path.basename() for the title when context is missing 4. Proceeding to ask for permission when containsPath check cannot run This is defensive programming that prevents cryptic errors in edge cases while maintaining normal behavior when Instance context is available.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
sureshsankaran
added a commit
to sureshsankaran/opencode
that referenced
this pull request
Jan 13, 2026
Gracefully handle missing Instance context to avoid cryptic native binding errors when tools are executed outside normal server flow (e.g., MCP, plugins). Related upstream PR: anomalyco#8302
Collaborator
|
How are you triggering this error? Instance should be there |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8301
path.basename()for title whenInstance.worktreeis unavailableProblem
When the Read tool is executed outside of an Instance context (e.g., via MCP, plugins), accessing
Instance.worktreethrows aContext.NotFoundexception. However, before this propagates,path.relative(undefined, filepath)throws:This is confusing and does not indicate the actual problem.
Solution
Wrap
Instance.worktreeandInstance.containsPath()access in try-catch blocks:read.ts: Fall back topath.basename(filepath)for the titleexternal-directory.ts: Proceed to ask for permission when containsPath check cannot runVerification