Skip to content

fix(opencode): stop exporting functions from the plugin — crashes opencode 1.18.30 boot - #92

Open
dianedef wants to merge 1 commit into
Cannon07:mainfrom
dianedef:fix/opencode-plugin-function-export-crash
Open

dianedef wants to merge 1 commit into
Cannon07:mainfrom
dianedef:fix/opencode-plugin-function-export-crash

Conversation

@dianedef

Copy link
Copy Markdown

Problem

opencode (>= the 1.18 line, tested on opencode-ai@1.18.30) fails to start when the code-preview plugin is installed: opencode run dies with Unexpected server error. Check server logs for details. and the server logs show:

  • plugin config hook failedundefined is not an object (evaluating 'N.config')
  • Event listener failedundefined is not an object (evaluating 'V.event')

Root cause is the plugin module's named function export runWithSpuriousRetry. opencode's plugin loader treats any export whose value is a function as a plugin factory. When it can't process it (it has no config/event shape), it throws during startup — before the first prompt. Every other export form is fine (default export, named const with a scalar, named const whose value is an object).

Reproduced standalone with minimal plugins against opencode 1.18.30:

plugin module shape opencode run ping
export async function f() {} (+/- default) crash (server error)
export const f = async () => {} crash (server error)
default export only pong
export const retry = { run: ... } + default pong

Fix

  • backends/opencode/index.ts — drop the export keyword from runWithSpuriousRetry and expose it as a property on a const object: export const retry = { runWithSpuriousRetry }. The plugin module now only has a default export (its hooks) plus the const, so the server boots.
  • tests/backends/opencode/retry_test.ts — read the helper from mod.retry.runWithSpuriousRetry instead of mod.runWithSpuriousRetry.

Behavior is unchanged: the hooks still call the same retry helper, and the unit guard still exercises it.

Verification

  • With a project containing the patched plugin: opencode run pingpong (exit 0). Before the fix, the same setup → Unexpected server error (exit 1). Tested on Windows, opencode 1.18.30.
  • tsx tests/backends/opencode/retry_test.ts → all 5 checks pass, ALL OK.

….30 loader crashes on it

opencode's plugin loader treats any export whose value is a function as a
plugin factory and crashes the server at startup ('plugin config hook failed
(N.config)'). The plugin's named export runWithSpuriousRetry (added for the
retry unit guard) therefore broke opencode launch entirely: 'Unexpected server
error' before the first prompt.

Expose it as a property on a const object instead ('retry.runWithSpuriousRetry')
and point retry_test.ts at that. Reproduced standalone: opencode run fails to
boot with the function-valued export present, boots cleanly (\pong\) without
it; the retry guard still passes (ALL OK).
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.

1 participant