Skip to content

fix(core): isolate invalid plugin tools during materialize#37934

Closed
BrightonXX wants to merge 8 commits into
anomalyco:v2from
BrightonXX:tool-materialize-isolate
Closed

fix(core): isolate invalid plugin tools during materialize#37934
BrightonXX wants to merge 8 commits into
anomalyco:v2from
BrightonXX:tool-materialize-isolate

Conversation

@BrightonXX

@BrightonXX BrightonXX commented Jul 20, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #35963

Type of change

  • Bug fix

What does this PR do?

A structurally invalid plugin tool (missing description, undecodable schema, opaque object from a different module copy) throws inside materialize() and breaks every subsequent model step in the Location because no definition list can be produced.

materialize() now wraps each definition() call in try/catch. On failure: log a warning with the tool name and error, drop the registration from the direct map so later settle() calls do not surface it as usable, and continue building the rest of the catalog. The dropped tool settles as Unknown tool: <name> instead of re-throwing.

How did you verify your code works?

cd packages/core && bun test test/session-runner-tool-registry.test.ts   # 17 pass, 0 fail
bun turbo typecheck --filter=@opencode-ai/core...                         # 17/17 green

Reverse verification: reverting packages/core/src/tool/registry.ts makes the new test fail with TypeError: Cannot read properties of undefined (reading '~context') from inside materialize().

Screenshots / recordings

Not applicable — this is a core logic change, not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Brighton added 2 commits July 20, 2026 21:14
…#35963)

A plugin could register a structurally invalid tool (missing description,
undecodable input schema, opaque object from a different module copy) that
only failed when its definition was read inside `materialize()`. The throw
broke every subsequent model step in the Location because no definition
list could be produced - existing and newly created sessions all failed
with `TypeError: Invalid Tool value`, and the bad plugin stayed listed as
active because registration itself never validated the runtime.

Build each tool definition defensively: wrap the call in try/catch, log a
warning with the offending tool name and error, drop the registration so
later materializations and settle() do not surface it as a usable tool,
and keep the rest of the catalog intact. Settling a dropped tool now
returns the normal `Unknown tool: <name>` error path instead of
re-throwing.

Adds a regression test that registers one good tool and one broken tool
(constructed without an `input` schema so `inputJsonSchema(tool.input)`
throws) and asserts materialize() returns only the good definition, that
the broken tool settle path returns `Unknown tool`, and that the good
tool still executes.

Fixes anomalyco#35963
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@BrightonXX

Copy link
Copy Markdown
Author

@github-actions recheck issue

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 20, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@BrightonXX BrightonXX closed this Jul 20, 2026
@BrightonXX BrightonXX reopened this Jul 20, 2026
@BrightonXX BrightonXX closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant