anomalyco / anomalyco/opencode

server: failed plugin reload on config change silently drops custom agents and commands until restart

Open
#49,982 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Summary

On v2.0.9 running as the background service (opencode serve --service, desktop app), config edits repeatedly fail with ERROR failed to reload plugins — TypeError: pe is not a function. After these failed reloads, the live service silently loses all file-discovered custom agents and commands: /api/agent and /api/command (and the TUI pickers) degrade to builtins only until the service is restarted. A freshly started server on the identical config loads everything, so the definitions and config are valid.

Environment

  • opencode version: 2.0.9
  • OS: Darwin 27.0.0 (darwin arm64), macOS
  • Terminal: OpenCode desktop app (session host); TERM_PROGRAM=Apple_Terminal, TERM=xterm-256color
  • Shell: /bin/zsh
  • Install/channel: latest; binary at ~/.opencode/bin/opencode, background service mode
  • Active plugins: none in final state (transient local plugins were registered and removed during the session that triggered the bug; config has no plugin key afterwards)

Reproduction

  1. Set up custom agents (e.g. ~/.config/opencode/agent/review.md) and commands (project .opencode/commands/*.md ×23, global ~/.config/opencode/commands/*.md ×1). Start the background service and confirm via /api/agent / /api/command that they are loaded.
  2. With the service running (active sessions, MCP servers connected, two locations booted: home + project), edit ~/.config/opencode/opencode.json repeatedly — in my case registering then removing local plugin entries, including a moment where a registered plugin's files were deleted before its config key was removed.
  3. Each reload logs: ERROR failed to reload plugins cause="Cause([Die(TypeError: pe is not a function. (In 'pe()', 'pe' is an instance of Object))])"
  4. Afterwards /api/agent returns only the 7 builtins (custom review agent gone) and /api/command returns only the 2 builtins (all 24 custom commands gone). No error is logged at the moment the catalogs degrade — the loss is silent.
  5. opencode service restart → everything comes back.

Honest trigger caveat: on an isolated opencode serve (no --service, no connected clients) I could not trigger the crash with an mtime touch, a byte-identical rewrite, or adding a valid no-op plugin entry. It reproduced only on the shared --service instance with active sessions and multiple booted locations, which points at the concurrent/multi-location reload path also seen in #48121.

Expected Behavior

A failed plugin reload should not take down the agent/command catalogs, and file-discovered agents/commands should remain registered. Note the agent/command directories are not subscribed by any watcher (only skills and config files are), so once the catalogs degrade there is no self-healing path short of a restart.

Actual Behavior

Log excerpts (paths trimmed; timestamps UTC):

13:07:26 ERROR failed to reload plugins cause="Cause([Die(TypeError: pe is not a function. (In 'pe()', 'pe' is an instance of Object))])"
13:25:02 ERROR failed to reload plugins cause=… (same defect, recurs ≥10× over ~30 min)
13:35:19 WARN  failed to load plugin target="<project>/.opencode/plugin/aios-canary" cause="ENOENT …"   (plugin files removed before config key)
13:35:19 ERROR failed to reload plugins cause=… (same TypeError, ×3 in <200 ms)

After this window, on the still-running service:

/api/agent    → build, compaction, explore, general, plan, summary, title   (custom "review" agent gone)
/api/command  → init, review                                                 (23 project + 1 global commands gone)

Same binary + same config on a fresh opencode serve: 8 agents (incl. review) and 26 commands load correctly — verified twice on isolated instances.

Additional Context

  • Workaround: opencode service restart.
  • During the same window the background service also restarted twice without user action (may be unrelated, included for completeness).
  • Recurring WARN failed to load OpenCode provider config … 401 GET https://opencode.ai/console/api/v2/config also appears on both healthy and unhealthy instances — likely unrelated auth noise.
  • Related issues in the same subsystem: #48121 (concurrent location plugin reloads crash with r.base.get), #44920, #44975. The new part reported here is the silent loss of the agent/command catalogs until restart.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure in opencode serve --service with active sessions and multiple booted locations, then inspect the config/plugin reload path and the /api/agent and /api/command entry points. Compare the behavior with a fresh isolated server and review related issue #48121. Done means a failed reload does not silently remove file-discovered agents or commands, and the catalogs remain available without a restart.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.