Skip to content

fix: await async generator return value in warpgrep_codebase_search (Bun compatibility Issue)#25

Merged
bhaktatejas922 merged 1 commit into
morphllm:mainfrom
fpdy:fix/warpgrep-snapshot-worktree-fallback
Jun 17, 2026
Merged

fix: await async generator return value in warpgrep_codebase_search (Bun compatibility Issue)#25
bhaktatejas922 merged 1 commit into
morphllm:mainfrom
fpdy:fix/warpgrep-snapshot-worktree-fallback

Conversation

@fpdy

@fpdy fpdy commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

warpgrep_codebase_search consistently returned no contexts when the plugin runs inside OpenCode (Bun runtime):

Search failed: search returned no error details.

Root cause

The morphsdk WarpGrepClient.execute() with streamSteps: true is an async generator. Its final return processAgentResult(...) hands back a Promise. Per ECMAScript spec, async generators should auto-await return values, and Node.js does. Bun does not — it yields the unresolved Promise as the .next() value.

The plugin consumed the generator with:

const { value, done } = await generator.next();
if (done) {
  result = value;  // ← Promise, not WarpGrepResult
  break;
}

So result was a Promise whose .success was undefined, and formatWarpGrepResult returned the generic failure message.

Fix

One line:

result = await value as WarpGrepResult;

This is harmless on Node.js (await on a non-Promise is a no-op) and fixes Bun.

Fixes #24.

Changes

  • Explicitly await the async generator return value in warpgrep_codebase_search.execute().
  • Add a test that verifies the result is correctly resolved under Bun.

Diagnosis trail

Initial hypothesis (worktree pointing at OpenCode snapshot git dir) was ruled out by diagnostic logging: directory and worktree both correctly pointed at the real workspace (isWorktreeGitMetadata=false). The actual issue was found by dumping the result object, which had all fields undefined — confirming an unresolved Promise was being used as the result.

Direct SDK calls via node succeeded because Node.js auto-awaits async generator return values per spec. The failure only occurred through the plugin running inside OpenCode (Bun runtime).

Reproduction

warpgrep_codebase_search({
  "search_term": "Find README.md and CHANGELOG.md files in this repository."
})

Result before fix:

Search failed: search returned no error details.

After fix: returns contexts for README.md and CHANGELOG.md.

Validation

$ bun test
67 pass
0 fail
170 expect() calls

$ bun run typecheck
(clean)

$ bun run build
(clean)

Baseline before changes was 66 pass / 0 fail; the one new test brings it to 67 pass / 0 fail.

Verified end-to-end in OpenCode (Bun runtime): warpgrep_codebase_search now returns contexts successfully.

Environment

  • @morphllm/opencode-morph-plugin: 2.0.13
  • @morphllm/morphsdk: 0.2.173
  • OpenCode: 1.16.2 (Bun runtime)
  • OS: macOS

Notes

This is a plugin-side workaround for a Bun runtime quirk. The underlying issue is in morphsdk'"'"'s async generator (return processAgentResult(...) without await), but since morphsdk is a separate package and the one-line await works across both Node.js and Bun, the plugin-side fix is the safest minimal change.

The morphsdk WarpGrepClient.execute() async generator returns a Promise
from processAgentResult() via `return promise`. Node.js auto-awaits it
per ECMAScript spec, but Bun does not — the unresolved Promise becomes
the .next() value.

Without the explicit await, result was a Promise whose .success was
undefined, and formatWarpGrepResult returned the generic failure message:
"Search failed: search returned no error details."

The fix is a single line: `result = await value`. This is harmless on
Node.js (await on a non-Promise is a no-op) and resolves the Promise on
Bun.

Closes morphllm#24
@fpdy fpdy force-pushed the fix/warpgrep-snapshot-worktree-fallback branch from c2e7c53 to 9a8d60a Compare June 14, 2026 02:29
@fpdy fpdy changed the title fix: warpgrep_codebase_search searches snapshot git dir instead of workspace fix: await async generator return value in warpgrep_codebase_search (Bun compatibility) Jun 14, 2026
@fpdy fpdy changed the title fix: await async generator return value in warpgrep_codebase_search (Bun compatibility) fix: await async generator return value in warpgrep_codebase_search (Bun compatibility Issue) Jun 14, 2026
@bhaktatejas922 bhaktatejas922 merged commit 27208e7 into morphllm:main Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warpgrep_codebase_search returns no contexts when OpenCode passes snapshot git dir as worktree

2 participants