Skip to content

Race condition in agents.create: runtimeConfigSnapshot not invalidated, causing agents.update to fail on second WebSocket connection #37175

@robgfl45

Description

@robgfl45

Bug Report

Summary

When Mission Control (or any client) calls agents.create followed immediately by agents.update on a separate WebSocket connection, the agents.update fails with agent not found despite the agent having been successfully created 8ms earlier.

Root Cause

In daemon-cli.js, the local writeConfigFile function calls clearConfigCache() but does not reset runtimeConfigSnapshot. This means the in-memory snapshot remains stale after a config write. Any subsequent loadConfig() call on a different connection returns the old snapshot, which doesn't include the newly created agent.

async function writeConfigFile(cfg, options = {}) {
    clearConfigCache();           // ✅ clears disk cache
    // ❌ runtimeConfigSnapshot is NOT reset here
    // ...
}

Fix

Add runtimeConfigSnapshot = null; immediately after clearConfigCache() in the local writeConfigFile in daemon-cli.js:

async function writeConfigFile(cfg, options = {}) {
    clearConfigCache();
    runtimeConfigSnapshot = null;  // ← add this line
    // ...
}

Reproduction

  1. Configure a fresh OpenClaw gateway
  2. Pair it with Mission Control
  3. Observe: agents.create succeeds, agents.update fails 8ms later with agent not found
  4. MC generates a new UUID on every retry — pairing never completes

Log Evidence

agents.create ✓ 51ms  conn=eb477c21
agents.update ✗ 1ms   conn=549eea83 — agent not found
[reload] config change applied  ← 500ms too late

Impact

Every new OpenClaw instance paired with Mission Control fails on first setup. The workaround (manually patching daemon-cli.js) is not acceptable for production deployments.

Version

OpenClaw 2026.3.2 (85377a2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions