Skip to content

fix(plugin): skip cross-kind plugins in readV1Plugin detect mode - #31552

Closed
caniko wants to merge 1 commit into
anomalyco:devfrom
caniko:fix/readV1Plugin-detect-mode
Closed

caniko wants to merge 1 commit into
anomalyco:devfrom
caniko:fix/readV1Plugin-detect-mode

Conversation

@caniko

@caniko caniko commented Jun 9, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes # (no existing issue — this was discovered via canix config investigation)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The server plugin loader (packages/opencode/src/plugin/index.ts) calls readV1Plugin(mod, spec, "server", "detect") for every plugin in the user's config. When a TUI-only plugin (one that exports { id, tui } but not server) is configured via settings.plugin, the existing detect-mode guard only short-circuits when all three fields (id, server, tui) are absent. Since id and tui are present, the function proceeds to the kind-specific check and throws:

TypeError: Plugin ... must default export an object with server()

This error is caught and logged at ERROR level by the server loader, which is both noisy and misleading — the plugin is not a server plugin, it just happens to be configured in the same plugin array.

The fix adds two short-circuit guards after the existing detect check that also return early when the plugin lacks the field for the requested kind. This is safe because:

  • A plugin with only server is correctly skipped when kind = "tui" (previously it would have been caught by the tui === undefined check)
  • A plugin with only tui is correctly skipped when kind = "server" (the crash case being fixed)
  • A plugin with both server and tui is still rejected at line 293 (plugins must export one or the other, not both)
  • A plugin with neither id, server, nor tui still returns at line 283

How did you verify your code works?

  • Ran bun test test/plugin/shared.test.ts test/plugin/loader-shared.test.ts — 40 pass, 0 fail.
  • Manually traced the detect-mode control flow for each combination of (kind, server, tui, id) to confirm early-return behavior matches expectations.

Screenshots / recordings

N/A — logic-only change.

Checklist

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

When readV1Plugin is called with mode='detect' and kind='server', a
TUI-only plugin (with id and tui fields but no server field) should be
silently skipped instead of throwing TypeError.

The existing detect guard only checks whether ALL of {id, server, tui}
are absent. Add two additional guards that also short-circuit when the
plugin lacks the field for the requested kind.

This fixes the server plugin loader (plugin/index.ts) emitting ERROR
logs for every file-based TUI-only plugin configured via settings.plugin.
@github-actions

github-actions Bot commented Jun 9, 2026

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 added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No issue referenced. Please add Closes #<number> linking to the relevant issue.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 9, 2026
@github-actions github-actions Bot closed this Jun 9, 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