Skip to content

DefaultResourceLoader.reload() blocks event loop for 12-15s on Windows due to synchronous filesystem scanning #79899

@Pukerud

Description

@Pukerud

Problem

DefaultResourceLoader.reload() from @mariozechner/pi-coding-agent blocks the Node.js event loop for 12-15 seconds on every agent run on Windows/NTFS. This is caused by extensive use of synchronous filesystem operations:

  • readdirSync, statSync, readFileSync, existsSync — 21+ occurrences in resource-loader.js, 15+ in discovery-CVL9-KJt.js
  • These scan directories recursively across multiple locations on every reload() call

Directories scanned on every reload()

  • ~/.openclaw/extensions, ~/.openclaw/skills, ~/.openclaw/prompts, ~/.openclaw/themes
  • <workspace>/.openclaw/extensions, <workspace>/.openclaw/skills, etc.
  • ~/.agents/skills
  • Ancestor directory scanning via collectAncestorAgentsSkillDirs()
  • All npm package resolution paths

Impact

  • Event loop blocked: eventLoopDelayP99Ms=12297ms, eventLoopUtilization=1.0
  • Tool call timeouts: GatewayTransportError: gateway timeout after 10000ms
  • Duplicate Telegram messages: Preview cleanup queued behind blocked event loop
  • Slow WebSocket responses: chat.history 200-3800ms, node.list 248-2258ms
  • Subagent spawns: Every subagent also pays the 12s overhead

Log evidence

prep stages: totalMs=14809 stages=workspace-sandbox:1ms,skills:1ms,core-plugin-tools:2199ms,bootstrap-context:17ms,bundle-tools:790ms,system-prompt:4ms,session-resource-loader:11787ms@14799ms,agent-session:2ms,stream-setup:8ms

session-resource-loader alone accounts for 80% of prep time.

Environment

  • OpenClaw: 2026.5.7 (eeef486)
  • OS: Windows 10 (26200), NTFS
  • Node: v24.13.0
  • .openclaw directory: 14,560 files
  • Workspace skills: 64 files (after archiving 21 unused)

Proposed fixes

  1. Cache resource discovery results between runs — only rescan when file mtimes change
  2. Convert sync fs to async with fs.promises.* (though the reload must complete before the run starts, so this alone would not reduce total time — but it would stop blocking the event loop)
  3. Expose skip flagsDefaultResourceLoader already supports noExtensions, noSkills, noThemes, noPromptTemplates, noContextFiles constructor options, but OpenClaw does not expose these via config. Adding config options like agents.defaults.skipResourceTypes: ["themes", "prompts"] would let users opt out of unused resource types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.staleMarked as stale due to inactivity

    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