GeezerVison is showing github.com — plugin: npm plugin update/reload race drops custom providers until /reload · Issue #62068 · anomalyco/opencode
plugin: npm plugin update/reload race drops custom providers until /reload #62068DescriptionSummary
Updating an npm plugin can delete the versioned cache directory that the plugin loader still references. The reload then fails with ENOENT, and that location's provider catalog silently falls back to built-ins plus auto-discovered providers. Custom providers disappear from /api/provider, /api/model, and the model picker until POST /api/location/reload (TUI /reload) is run.
Environment
- opencode version: 2.2.5 (release channel
latest, installed via mise)
- OS: Linux 7.2.8-9-omarchy x86_64 (Omarchy/Arch)
- Terminal:
TERM=xterm-256color, COLORTERM=truecolor, TERM_PROGRAM unset
- Shell:
/usr/bin/bash
- Install/channel:
latest
- Active plugins:
opencode-mem@latest (resolved to 2.41.0 at the time)
Reproduction
-
Configure an npm plugin by package name and at least one custom OpenAI-compatible provider, for example:
{
"plugin": ["opencode-mem"],
"provider": {
"custom": {
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "http://127.0.0.1:8080/v1" },
"models": { "my-model": { "name": "My Model" } }
}
}
}
-
Trigger plugin cache reconciliation for the location, e.g. run opencode update, or start the TUI while an update is in flight, so ~/.cache/opencode/npm/<plugin>@latest/<timestamp> is replaced.
-
While the location is booting or reloading, the plugin loader still references the previous <timestamp> directory.
-
Observe failed to reload plugins with ENOENT in ~/.local/share/opencode/log/opencode.log, and the custom provider missing from /api/provider for that location.
Expected Behavior
The plugin reload should use the new cache path, or fail without dropping the provider catalog. If plugin activation fails, the last settled provider/model catalog should remain available, or the location should retry automatically, instead of serving an incomplete catalog.
Actual Behavior
After the failure, this query:
opencode api get '/api/provider?location%5Bdirectory%5D=%2Fhome%2Fdavie%2FWork'
returned only opencode and auto-discovered ollama (named "Ollama", not the configured "Ollama (local)"). The configured strata provider was absent. /api/model likewise had no strata models.
Exact log line:
timestamp=2026-11-05T13:07:35.864Z level=ERROR run=6d8606f3 message="failed to reload plugins" cause="Cause([Die(BuildMessage: ENOENT reading \"/home/davie/.cache/opencode/npm/opencode-mem@latest/1793792513300/node_modules/opencode-mem/dist/services/turso/lifecycle.js\")])" http.span=1458 role=server
The other location (/home/davie) was unaffected once its plugin cache was present.
Additional Context
Workaround: wait for the new cache directory to be written, then run opencode api post /api/location/reload (TUI /reload). Both locations then loaded the plugin from .../1793884281668/... and the strata provider/models reappeared. No new plugin errors were logged.
Frequency: the same failure occurred on 2026-10-25, 2026-10-29, 2026-11-02, 2026-11-04 and 2026-11-05, each time with a different opencode-mem@latest/<timestamp> cache directory. It looks like the plugin cache reconciliation removes or replaces the old version before an in-flight reload finishes.
Note: the third-party app update (a local model server) was unrelated; this reproduced with the plugin cache churn alone.
Possibly related: #49982 (failed plugin reload drops agents/commands until restart), #61131 (concurrent npm install LockTimeoutError), #60312 (stale failed plugin load), #61525 (hot-reload never recovers from a failed import). Activityopencodejr commented on Nov 5, 2026 Thanks for the detailed report. I reproduced this on 2.2.5.
Steps: an isolated opencode serve with "plugin": ["opencode-mem"] (2.41.0) and a custom @ai-sdk/openai-compatible provider.
- At startup,
/api/provider lists opencode and custom.
- I swapped the
~/.cache/opencode/npm/opencode-mem@latest/<timestamp> folder for a new one and triggered a reload. It loaded from the new folder and custom was still there.
- After a second round of cache changes, the next reload failed with exactly your error,
failed to reload plugins ... ENOENT reading ".../opencode-mem@latest/<first timestamp>/.../dist/services/turso/lifecycle.js". After that, /api/provider returned only opencode and did not recover on its own.
What seems to happen: the missing path is the original cache folder. When the old plugin instance shuts down during the reload, opencode-mem lazily imports lifecycle.js from that folder, which the cache cleanup has already deleted. The whole reload then fails, and the location is left without the providers from your config.
Latest dev: I couldn't test this meaningfully. Running from source loads plugins from a different cache, so the cleanup step never runs. 2.2.5 is still the latest release, and the code involved hasn't changed since then, so it most likely still happens. For now, your workaround (/reload, or opencode api post /api/location/reload, once the new cache folder exists) is the way to recover.
The script below reproduces it against the server API.
Related: #49982 (a failed plugin reload drops registry entries until restart), #62030, #61131, #60312, #61525.
Reproduction script (repro.sh)
#!/usr/bin/env bash
# Repro for #62068: deleting/replacing the npm plugin cache generation that a
# running plugin came from makes the next plugin reload die with ENOENT, and
# the location's provider catalog loses the configured custom provider.
# Usage: ./repro.sh (uses `opencode` from PATH)
# OC_DEV=/path/to/opencode-checkout ./repro.sh (runs from source)
set -u
ROOT=$(mktemp -d /tmp/opencode/repro-62068.XXXX)
export HOME=$ROOT/home XDG_CONFIG_HOME= XDG_CACHE_HOME= XDG_DATA_HOME= XDG_STATE_HOME=
mkdir -p "$HOME/.config/opencode" "$ROOT/proj"
CFG=$HOME/.config/opencode/opencode.json
cat > "$CFG" <<'EOF'
{
"plugin": ["opencode-mem"],
"provider": {
"custom": {
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "http://127.0.0.1:8080/v1" },
"models": { "my-model": { "name": "My Model" } }
}
}
}
EOF
PORT=${PORT:-4577}
cd "$ROOT/proj"
if [ -n "${OC_DEV:-}" ]; then
bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" \
"$OC_DEV/packages/cli/src/index.ts" serve --port $PORT --hostname 127.0.0.1 --print-logs > "$ROOT/serve.log" 2>&1 &
else
opencode serve --port $PORT --hostname 127.0.0.1 --print-logs > "$ROOT/serve.log" 2>&1 &
fi
SRV=$!
trap 'kill $SRV 2>/dev/null' EXIT
until grep -q "server password" "$ROOT/serve.log" 2>/dev/null; do sleep 1; done
PW=$(grep -o 'server password .*' "$ROOT/serve.log" | awk '{print $3}')
Q="location%5Bdirectory%5D=$(python3 -c "import urllib.parse,sys;print(urllib.parse.quote(sys.argv[1],safe=''))" "$ROOT/proj")"
providers() { curl -s -u "opencode:$PW" "http://127.0.0.1:$PORT/api/provider?$Q" | python3 -c "import json,sys;d=json.load(sys.stdin);print(d.get('_tag') or [p['id'] for p in d['data']])"; }
bump() { python3 -c "import json,sys;p=sys.argv[1];d=json.load(open(p));d['provider']['custom']['name']=sys.argv[2];json.dump(d,open(p,'w'),indent=2)" "$CFG" "$1"; }
CACHE=$HOME/.cache/opencode/npm/opencode-mem@latest
for i in $(seq 1 60); do out=$(providers); [[ "$out" == *custom* ]] && break; sleep 2; done
echo "1. initial providers: $out generations: $(ls $CACHE)"
# Replace the cache generation (what update/reconciliation does): new generation, old one removed.
OLD=$(ls $CACHE | head -1); cp -a "$CACHE/$OLD" "$CACHE/$(date +%s%3N)"; rm -rf "$CACHE/$OLD"
bump A; sleep 12
echo "2. after generation swap + reload: $(providers) generations: $(ls $CACHE)"
# Cache churn again: generations removed, next reload reinstalls.
rm -rf "$CACHE"/*; bump B; sleep 30
echo "3. after second churn + reload: $(providers) generations: $(ls $CACHE)"
echo "--- plugin reload errors:"
grep 'failed to reload plugins' "$ROOT/serve.log" | cut -c1-400
Run it: bash repro.sh
ccclucky commented on Nov 5, 2026 I traced this on current dev. When an npm plugin update swaps generations, the replaced plugin's teardown runs inside Plugin.activate (packages/core/src/plugin.ts, the previous-slots loop). A teardown defect — e.g. a shutdown hook lazily importing a file from an already pruned cache generation — propagates through Scope.close and aborts the whole activation: the old registrations are already gone, the replacement generation never loads, and the location keeps serving built-ins until the next reload trigger. That matches the reported failed to reload plugins / ENOENT log.
I'd like to fix this by isolating per-plugin teardown failures during activation (log and continue, mirroring the existing "failed to clean up disabled plugin" handling), with a regression test that activates a replacement over a plugin whose shutdown dies. The provider catalog then rebuilds from the new generation instead of falling back to built-ins. ccclucky commented on Nov 5, 2026 Following up on this — I'd like to pick up the remaining cause you pointed out on my PR: the cache cleanup in packages/util/src/npm.ts can delete a generation that a running plugin instance still imports from. collect() only keeps the two newest generations plus anything younger than 7 days, so a long-lived server loses its loaded generation once two updates have landed and the original generation aged out.
Plan for a focused PR:
- When the plugin registry activates an instance loaded from an npm cache generation, it records a small lease marker under the shared state directory (generation path + pid + hostname) and removes it when the instance's activation scope closes. The activation scope is exactly the lifetime whose teardown and lazy imports must keep working across a reload handover.
collect() skips generations whose marker process is still alive, and prunes stale markers (dead pid on this host) as housekeeping.
No heartbeat timer: process liveness covers suspended laptops, and a crashed holder stops pinning as soon as its pid is gone, so recovery doesn't depend on a TTL. I'll follow up with the PR.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|