bug: tool.registry test fails on CI — custom tool import crashes registry when dependencies are missing #8596

Closed
opened 2026-02-16 18:10:21 -05:00 by yindo · 1 comment
Owner

Originally created by @mguttmann on GitHub (Feb 5, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

The test tool.registry > loads tools with external dependencies without crashing introduced in #12227 (556adad67) fails deterministically on CI:

error: Cannot find package 'cowsay' from '/tmp/opencode-test-xxx/.opencode/tools/cowsay.ts'
(fail) tool.registry > loads tools with external dependencies without crashing [269.71ms]

This blocks all PRs targeting dev — the test (linux) check fails with 881 pass / 1 fail.

Root cause

Two issues:

  1. No error handling in ToolRegistry.state()await import(match) on line 44 of registry.ts throws when a custom tool has unresolvable dependencies, crashing the entire registry initialization instead of gracefully skipping the broken tool.

  2. Test expects successful load without installing deps — the test creates a package.json with cowsay dependency but the dependency is never installed in the temp directory. Config.waitForDependencies() doesn't trigger the install in the test context. The test then asserts expect(ids).toContain("cowsay") which fails because the import throws.

Impact

Every PR targeting dev fails the test (linux) CI check. This started after #12227 was merged.

Suggested fix

  1. Wrap the import(match) in registry.ts with try/catch — log a warning and skip tools that fail to import
  2. Update the test expectation to not.toContain("cowsay") since the test name says "without crashing" (testing resilience, not successful loading)

PR with fix: incoming

Originally created by @mguttmann on GitHub (Feb 5, 2026). Originally assigned to: @rekram1-node on GitHub. ## Description The test `tool.registry > loads tools with external dependencies without crashing` introduced in #12227 (`556adad67`) fails deterministically on CI: ``` error: Cannot find package 'cowsay' from '/tmp/opencode-test-xxx/.opencode/tools/cowsay.ts' (fail) tool.registry > loads tools with external dependencies without crashing [269.71ms] ``` This blocks **all PRs** targeting `dev` — the `test (linux)` check fails with 881 pass / 1 fail. ## Root cause Two issues: 1. **No error handling in `ToolRegistry.state()`** — `await import(match)` on line 44 of `registry.ts` throws when a custom tool has unresolvable dependencies, crashing the entire registry initialization instead of gracefully skipping the broken tool. 2. **Test expects successful load without installing deps** — the test creates a `package.json` with `cowsay` dependency but the dependency is never installed in the temp directory. `Config.waitForDependencies()` doesn't trigger the install in the test context. The test then asserts `expect(ids).toContain("cowsay")` which fails because the import throws. ## Impact Every PR targeting `dev` fails the `test (linux)` CI check. This started after #12227 was merged. ## Suggested fix 1. Wrap the `import(match)` in `registry.ts` with try/catch — log a warning and skip tools that fail to import 2. Update the test expectation to `not.toContain("cowsay")` since the test name says "without crashing" (testing resilience, not successful loading) PR with fix: incoming
yindo closed this issue 2026-02-16 18:10:21 -05:00
Author
Owner

@wlioi commented on GitHub (Feb 5, 2026):

Related Issue: Zod TypeError in Custom Tools (#12336)

I reported a separate but related issue (#12336) about Zod schema validation failures when loading custom tools from the .opencode directory.

Summary of #12336

  • Error: TypeError: undefined is not an object (evaluating 'schema._zod.def')
  • Location: src/session/prompt.ts:704:62 (in resolveTools)
  • Root cause: Zod 4.1.8 toJSONSchema function lacks defensive checks when processing nested basic types like ZodString/ZodNumber
  • Trigger: Using @opencode-ai/plugin tool() function with Zod schema args

Connection to this issue

Both issues involve custom tool loading failures:

  • #12269: Dependency import failures (missing error handling)
  • #12336: Schema validation failures (missing Zod defensive checks)

Suggestion

Consider adding comprehensive error handling for custom tool loading that covers:

  1. Dependency resolution (your PR)
  2. Schema validation (needs separate fix)

The issue occurs when OpenCode internally calls z.toJSONSchema(item.parameters) during tool resolution.

@wlioi commented on GitHub (Feb 5, 2026): ## Related Issue: Zod TypeError in Custom Tools (#12336) I reported a separate but related issue (#12336) about Zod schema validation failures when loading custom tools from the `.opencode` directory. ### Summary of #12336 - **Error**: `TypeError: undefined is not an object (evaluating 'schema._zod.def')` - **Location**: `src/session/prompt.ts:704:62` (in `resolveTools`) - **Root cause**: Zod 4.1.8 `toJSONSchema` function lacks defensive checks when processing nested basic types like `ZodString`/`ZodNumber` - **Trigger**: Using `@opencode-ai/plugin` `tool()` function with Zod schema args ### Connection to this issue Both issues involve custom tool loading failures: - **#12269**: Dependency import failures (missing error handling) - **#12336**: Schema validation failures (missing Zod defensive checks) ### Suggestion Consider adding comprehensive error handling for custom tool loading that covers: 1. Dependency resolution (your PR) 2. Schema validation (needs separate fix) The issue occurs when OpenCode internally calls `z.toJSONSchema(item.parameters)` during tool resolution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8596