Skip to content

[Bug]: Performance bottleneck in resolveAgentRoute with large bindings configuration #36915

@songchenghao

Description

@songchenghao

Bug type

Crash (process/app exits or hangs)

Summary

Environment

Problem

resolveAgentRoute() causes 10+ second delays when processing messages in deployments with large numbers of bindings.

Log evidence:

2026-03-05T09:48:02.012Z - Message received from DingTalk WebSocket
... ~10 second gap ...
2026-03-05T09:48:21.233Z - [dingtalk] Inbound: from=宋成好 text="..."

Root Cause

src/routing/resolve-route.ts Line 322-370: getEvaluatedBindingsForChannelAccount()

const evaluated: EvaluatedBinding[] = listBindings(cfg).flatMap((binding) => {
  if (!matchesChannel(binding.match, channel)) {  // ← O(n) linear scan on EVERY message
    return [];
  }
  // ...
});
  • Time Complexity: O(n) where n = total bindings count
  • With 83,043 bindings: Every message triggers full array scan
  • Result: Prohibitive performance degradation

Proposed Solution

Add channel-specific peer index to EvaluatedBindingsIndex:

type EvaluatedBindingsIndex = {
  byPeer: Map<string, EvaluatedBinding[]>;
  byChannelPeer: Map<string, EvaluatedBinding[]>;  // NEW: O(1) channel:peer lookup
  // ... existing fields
};

Benefits:

  • Solves at framework level (all channels benefit)
  • O(1) peer lookups instead of O(n)
  • Maintains API compatibility
  • Minimal memory overhead

Impact

  • Enterprise deployments with 1000+ agents become unusable
  • Poor user experience (10s message delays)
  • Blocks scaling OpenClaw for large organizations

Use Case

Enterprise-wide DingTalk bot:

  • 9,000+ employees, each with isolated agent/workspace
  • Per-user routing via bindings: peer.id (user ID) → agentId
  • Single bot, zero end-user configuration

Files

  • src/routing/resolve-route.ts (line 322-370, 530-719)

Steps to reproduce

above

Expected behavior

above

Actual behavior

above

OpenClaw version

2026.3.1

Operating system

Ubuntu

Install method

docker

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug:crashProcess/app exits unexpectedly or hangs

    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