Skip to content

fix: handle custom tool import failures gracefully in registry#12270

Open
mguttmann wants to merge 1 commit intoanomalyco:devfrom
mguttmann:fix/tool-registry-resilience
Open

fix: handle custom tool import failures gracefully in registry#12270
mguttmann wants to merge 1 commit intoanomalyco:devfrom
mguttmann:fix/tool-registry-resilience

Conversation

@mguttmann
Copy link

Summary

Fixes #12269 — the tool registry now catches and logs errors when a custom tool fails to import (e.g. due to unresolvable dependencies) instead of crashing the entire registry initialization.

Changes

  • packages/opencode/src/tool/registry.ts — wrap import(match) in try/catch, log warning and skip tools that fail to load
  • packages/opencode/test/tool/registry.test.ts — fix the loads tools with external dependencies without crashing test to verify resilience (registry doesn't crash) rather than expecting the tool to be loaded when its dependencies can't be resolved

Context

Commit 556adad67 (#12227) added a test that creates a custom tool importing cowsay, but the dependency is never installed in the test's temp directory. This causes a deterministic failure on CI that blocks all PRs targeting dev:

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]

881 pass / 1 fail

The production code fix (try/catch) is also good defensive programming — if bun install fails for any reason (network error, disk full, etc.), the registry should still work for all other tools rather than crashing entirely.

The tool registry now catches and logs errors when a custom tool
fails to import (e.g. due to unresolvable dependencies) instead of
crashing the entire registry initialization.

Also fixes the 'loads tools with external dependencies without
crashing' test which was failing on CI because cowsay was never
installed in the temp directory.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

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.

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

1 participant