OpenClaw / OpenClaw Core
Merged upstreamPerformanceMerged Aug 25, 2026

Avoid quadratic session migration over absent agent stores

Fixed OpenClaw Gateway session migration so configurations with many agents and no existing session stores scale linearly instead of performing filesystem-backed comparisons against every earlier path.

openclaw/openclaw · #126685

Gateway scalability fix

Missing per-agent session stores are now checked once instead of entering quadratic alias comparisons that caused an observed 57-minute startup stall at approximately 10,000 configured agents.

Problem

Session migration grouped every configured store path through alias detection before checking whether the file existed. With per-agent paths and empty stores, each new agent compared against all earlier paths using synchronous filesystem probes, blocking Gateway startup with quadratic work that produced an observed 57-minute outage near 10,000 agents.

Approach

Moved regular-file existence checking to the migration owner before alias grouping. Definitely absent or non-file paths are skipped, while filesystem errors retain the original conservative alias path so inaccessible stores continue to fail closed; existing shared, symlinked, and hard-linked stores keep their previous ownership behavior.

Impact and scope

  • Reduces absent-store discovery from quadratic comparisons to one filesystem probe per configured agent.
  • Removes a blocking startup path that delayed the Gateway HTTP listener, health monitoring, and channels on large installations.
  • Preserves migration safety for real stores, shared ownership, aliases, inaccessible paths, and repeated idempotent runs.

Validation

  • Added a 100-agent regression test that requires exactly one session-store probe per configured agent.
  • Production-owner evidence reports linear probe counts through 10,000 isolated missing stores with no migration changes or warnings.
  • PR evidence reports 46 focused migration and startup tests, the trusted production build, all 27 changed-file guards, issue closure, and verified upstream merge.