Skip to content

Plugin tools not registered when loaded twice by OpenClaw Gateway #1210

@highland0971

Description

@highland0971

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:

  1. First with preferSetupRuntimeForChannelPlugins: true (cacheKey: "prefer-setup")
  2. 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

Workaround

Users can apply the above fix locally in ~/.openclaw/extensions/openviking/index.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions