Skip to content

plugin: session-hook plugin activation triggers failed reload and wipes provider registry #52618

Closed as duplicate

Description

@gabrielferreira-cit

Summary

Saving a plugin file that registers a session.hook("http.request", ...) triggers repeated failed to reload plugins: TypeError: re is not a function across locations, and the provider/model registry drops all custom providers (51 models -> 8). Reverting the file to a no-op restores everything. Observed 4/4 correlated cycles, including once on a freshly restarted service.

Environment

  • opencode version: 2.0.21
  • OS: Linux 7.0.0-34-generic (linux x64)
  • Terminal: WarpTerminal, TERM=xterm-256color, COLORTERM=truecolor
  • Shell: /bin/zsh
  • Install/channel: latest
  • Active plugins: opencode-models-discovery@latest, superpowers@git+https://github.com/obra/superpowers.git, local rtk.ts

Reproduction

  1. Add ~/.config/opencode/plugins/strip-store.ts:
    export default {
      id: "strip-store",
      setup: async (ctx) => {
        await ctx.session.hook("http.request", async (event) => {
          if (event.model.providerID !== "my-gateway") return
          const req = event.request
          if (!(req.headers.get("content-type") ?? "").includes("application/json")) return
          const body = JSON.parse(await req.clone().text())
          if (!("store" in body)) return
          delete body.store
          const headers = new Headers(req.headers)
          headers.delete("content-length")
          event.request = new Request(req.url, {
            method: req.method,
            headers,
            body: JSON.stringify(body),
            duplex: "half",
          })
        })
      },
    }
  2. Save the file; the server reloads plugins.
  3. List models: custom providers vanish (only built-in opencode/* remain). The log shows per-location failed to reload plugins with cause="Cause([Die(TypeError: re is not a function. (In 're()', 're' is an instance of Object))])", and occasionally Session.AgentNotFoundError for the configured default agent during the churn.
  4. Revert the file to setup: async () => {} -> registry recovers (verified 4 times).

Expected Behavior

The hook registers and unrelated providers/models are unaffected by a plugin reload.

Actual Behavior

Provider/model registry loses all custom providers on every activation; recovery requires reverting the file (plus sometimes a manual discovery refresh, as the discovery inventory can be left wiped at 0 models).

Additional Context

  • The same failed to reload plugins error (different minified name, fe is not a function) was logged on 2026-09-24 with no such file present, so a pre-existing reload bug is likely being triggered rather than caused by this plugin's code. The plugin itself always reports loading plugin with no load error.
  • While providers vanish, the models-discovery inventory stays intact (42 models / 1 provider), pointing the failure at provider/model registry assembly during reload, not at discovery or at the hook's request handling (the hook body was verified working against an isolated probe endpoint).
  • Related: filed alongside this is the missing compatibility.supportsStore config-schema key, which is why the hook workaround was needed at all.

Activity

  1. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. nkoynov commented on Oct 7, 2026

    @nkoynov

    Another trigger and the blast radius on 2.0.24: saving a local plugin file (content-digested) reloads that plugin and every plugin after it in boot order, and the built-in post plugins always come after local ones (ConfigProviderPlugin, ConfigAgentPlugin, ConfigSkillPlugin, ConfigPolicyPlugin, …), in every booted Location. Measured: config agents gone for ~90 ms, half the skills for ~150 ms, a custom provider briefly missing from GET /api/provider. A turn running during reloads also gets skill-removed/added and full Code Mode catalog notices, up to ~20 KB per reload.

  3. opencodejr commented on Oct 28, 2026

    @opencodejr

    Thanks for the detailed report and the correlation testing. I think this is a duplicate of #49982. There, a plugin reload on the background service fails with the same failed to reload plugins … TypeError: <x> is not a function. (In '<x>()', '<x>' is an instance of Object). After that, everything the plugin generation had registered disappears from every location until the reload succeeds or the service restarts. In that report it was custom agents and commands; for you it shows up as the custom providers and models going missing. Your note that the same error appeared earlier without this file fits: your hook plugin looks like the trigger, not the cause.

    Possible duplicates and closely related issues, ordered from most to least likely:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  4. opencodejr commented on Oct 29, 2026

    @opencodejr

    Closing this as a duplicate of #49982, since there's been no reply in the past day saying how this differs. Both reports describe the same problem: a plugin reload fails with TypeError: <x> is not a function. (In '<x>()', '<x>' is an instance of Object), and afterwards everything the plugins had registered is missing in every location. For you that meant the custom providers and models; in #49982 it was custom agents and commands. Please follow #49982 for updates. The open PR #57775 addresses the instance of Object error, and #57089 covers a related reload failure. If you can show that this behaves differently, for example the providers disappearing without a failed to reload plugins error, please comment here and we'll take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions