Skip to content

Investigate bootstrap-time runtime import failures in plugin initialization #82

@NaNomicon

Description

@NaNomicon

Summary

The plugin can fail during startup because some transitive dependencies are imported too early during plugin bootstrap.

This issue tracks investigation and potential fixes for bootstrap-time runtime failures caused by eager top-level imports in the plugin dependency graph.

Current observed failures

We have seen bootstrap-time failures such as:

  1. Transformers / sharp path

    Missing 'default' export in module '.../node_modules/sharp/lib/index.js'
  2. OpenCode provider / OIDC path

    Export named 'getVercelOidcToken' not found in module '.../@vercel/oidc/dist/index.js'

What we know so far

  • The failure happens during plugin bootstrap, before the affected features are actually used.
  • Top-level imports can pull in runtime-sensitive dependencies too early.
  • This appears to affect transitive dependency graphs, not just the immediate plugin entrypoint code.
  • The sharp-related failure has also been reproduced in a clean OpenCode environment, so it does not appear to be only host-specific setup noise.

Likely problematic bootstrap edges

1. Embedding stack

src/services/embedding.ts imports @xenova/transformers at module top level.

That means the plugin may reach the sharp dependency graph during startup even when local embeddings are not needed for the active config or code path.

2. OpenCode provider stack

src/index.ts imports ./services/ai/opencode-provider.js at module top level.

That can pull in the AI/provider/OIDC stack during startup even when provider-backed features are not needed immediately.

Candidate directions to test later

These are hypotheses to verify, not confirmed fixes:

  1. Lazy-load transformers

    • defer @xenova/transformers until local embeddings are actually needed
    • goal: avoid reaching sharp during plugin bootstrap
  2. Lazy-load OpenCode provider stack

    • defer ./services/ai/opencode-provider.js until provider-backed logic is actually needed
    • goal: avoid reaching OIDC-related dependencies during plugin bootstrap

Important caution

These changes may only defer failures rather than fully fix them.

A successful bootstrap is useful, but we still need to verify that the deferred code paths work correctly once exercised.

Repro notes

Example repro command:

opencode debug config --print-logs

Suggested next steps

  1. Build minimal repros for each bootstrap edge

    • transformers/sharp
    • opencode-provider/oidc
  2. Test lazy-loading one dependency edge at a time

  3. Verify two things separately:

    • plugin startup succeeds
    • deferred runtime path still works when actually invoked
  4. Compare behavior across:

    • plain Bun
    • clean OpenCode environment
    • local OpenCode install
  5. Decide whether the long-term fix belongs in:

    • plugin bootstrap structure
    • dependency strategy
    • upstream runtime issue tracking
    • or a combination of the above

Status

Tracking issue only.
Implementation and validation will happen in a later pass.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions