Skip to content

Bug: DuplicateOpenClawRuntimeError on gateway restart blocks plugin registration #159

Description

@wacke1

Bug Description

On gateway restart, memos-local-plugin fails to acquire its runtime lock during the brief window between SIGTERM and process death, causing DuplicateOpenClawRuntimeError to abort register(). All hooks and tools become unavailable until next restart.

Reproduction

  1. Gateway running with plugin loaded
  2. Run systemctl --user restart openclaw-gateway or openclaw gateway restart
  3. Check logs:
[plugins] memos-local-plugin failed during register: DuplicateOpenClawRuntimeError: memos-local OpenClaw runtime is already active (pid=XXXX)
  1. memos_search / memos_get tools unavailable, before_prompt_build hook not triggered

Root Cause

In runtime-lock.js, acquireOpenClawRuntimeLock() loop:

if (owner && pidIsAlive(owner.pid)) {
    throw new DuplicateOpenClawRuntimeError(lockDir, owner);  // BLOCKS here
}
// Only clears lock when !owner (owner is null)
if (!owner && !lockLooksStale(lockDir, now(), unwrittenOwnerStaleMs)) {
    throw new DuplicateOpenClawRuntimeError(lockDir, null);
}
fs.rmSync(lockDir, { recursive: true, force: true });

After SIGTERM, pidIsAlive(old_pid) returns true during the 100-500ms grace period before OS reclaims the PID. The lock-clear path only handles !owner, so it never triggers when owner exists and pid is alive.

Proposed Fix

Add retry with backoff when owner pid is alive:

if (owner && pidIsAlive(owner.pid)) {
    await new Promise(r => setTimeout(r, 200));
    continue;  // retry
}

Environment

  • OpenClaw: 2026.7.1-2
  • memos-local-plugin: 2.0.16 (npm) / 2.0.0-beta.5 (registered)
  • Node.js: 24.18.0
  • OS: Linux 7.0.14-6-pve (Proxmox)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions