fix(plugin): restart a server left on a retired plugin root

A plugin update applied mid-session (/plugin followed by /reload-plugins)
fires no SessionStart, so the bootstrap's version handover never runs and the
dashboard server keeps executing a cache directory Claude Code has already
discarded. /ccam-open then rebuilt the bundle from the new root against that
old server, and the new bundle called routes the old server never had:
/api/lanes/pipeline-stats fell through to /:id and rendered "lane not found",
/api/workflows/skill-usage fell through to the SPA catch-all and broke
JSON.parse on the returned HTML. Both Workflows panels showed an error while
the code they needed was sitting on disk.

plugin-open now re-runs bootstrap when the live server's recorded pluginRoot
differs from the current one, or when no server is live at all. Bootstrap
already owns the stop/start and the dependency install the new root may need,
so this only restores the trigger that a mid-session update skips.
This commit is contained in:
2026-08-26 10:57:03 +07:00
parent 79e56c3221
commit c017f6dad9
3 changed files with 20 additions and 4 deletions
+13 -1
View File
@@ -6,7 +6,10 @@
* on session start, so client-only routes (e.g. `/run`) work the moment
* `claude` is started, not just the API and MCP tools. `/ccam-open` re-runs
* this standalone — a no-op when the bundle already matches — as a fallback
* for `--force` rebuilds or a first build that failed during bootstrap.
* for `--force` rebuilds or a first build that failed during bootstrap, and it
* re-runs bootstrap first when the live server belongs to a retired plugin root
* (a mid-session `/plugin` update) so the new bundle is not left calling routes
* the running server never had.
*
* The client source is copied out of the (replaced-on-update) plugin cache into
* the runtime dir before building, so neither the cache nor the checkout is
@@ -74,12 +77,21 @@ function dashboardUrl() {
}
if (require.main === module) {
// A plugin update applied mid-session (/plugin + /reload-plugins) fires no
// SessionStart, so the server keeps executing a cache dir Claude Code has
// already retired: a bundle rebuilt from the new root then calls routes that
// old server never had. Hand the version handover back to bootstrap, which
// owns stop/start and the dependency install the new root may need.
const stale = (boot.readState() || {}).pluginRoot !== PLUGIN_ROOT || !boot.serverIsLive();
if (stale) boot.bootstrap();
const result = buildClient({ force: process.argv.includes("--force") });
if (result === "failed") {
console.error("Client build failed — the API and MCP tools still work.");
process.exitCode = 1;
} else {
if (result === "built") console.log("Dashboard UI built.");
if (stale) console.log("Server restarted on the current plugin version.");
console.log(dashboardUrl());
}
}