-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Plugin tools not registered when loaded twice by OpenClaw Gateway #1210
Description
Summary
When OpenClaw Gateway starts, the OpenViking plugin is loaded twice with different cacheKey, causing tool registration to be skipped on the second load due to pluginRegistrationState not being reset.
Environment
- OpenClaw version: 2026.3.28
- OpenViking version: 0.2.15
- Node: v22.22.0
Problem
The beginPluginRegistration() function uses a module-level variable pluginRegistrationState to track registration status. When OpenClaw Gateway loads the plugin twice (with different cacheKey), the second load finds pluginRegistrationState === "registered" and returns null, skipping tool registration.
Root Cause
OpenClaw Gateway calls loadOpenClawPlugins twice:
- First with
preferSetupRuntimeForChannelPlugins: true(cacheKey: "prefer-setup") - Second without this parameter (cacheKey: "full")
The different cacheKey causes the plugin to be loaded again, but the module-level state persists.
Proposed Fix
In src/index.ts, modify beginPluginRegistration:
function beginPluginRegistration(api: OpenClawPluginApi): number | null {
// Reset state for re-registration when loaded with different cacheKey
if (pluginRegistrationState === "registered") {
api.logger.info("openviking: resetting registration state for re-registration");
pluginRegistrationState = "idle";
activeRegistrationToken = null;
}
if (pluginRegistrationState !== "idle") {
api.logger.info(DUPLICATE_REGISTRATION_LOG);
return null;
}
pluginRegistrationState = "registering";
const token = ++nextRegistrationToken;
activeRegistrationToken = token;
return token;
}Related
- OpenClaw Issue: Plugin tools not registered when loaded twice with different cacheKey (preferSetupRuntimeForChannelPlugins) openclaw/openclaw#60219
Workaround
Users can apply the above fix locally in ~/.openclaw/extensions/openviking/index.ts.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status