Skip to content

Fix daemon busy-wait loop causing 100% CPU usage#1052

Open
cetex wants to merge 1 commit intoruvnet:mainfrom
cetex:fix/daemon-busy-wait-loop
Open

Fix daemon busy-wait loop causing 100% CPU usage#1052
cetex wants to merge 1 commit intoruvnet:mainfrom
cetex:fix/daemon-busy-wait-loop

Conversation

@cetex
Copy link

@cetex cetex commented Jan 30, 2026

Summary

  • processPendingWorkers() in worker-daemon.ts busy-waits when a worker is deferred by canRunWorker() (e.g. CPU load above threshold). The deferred worker gets pushed back onto the queue and the while loop immediately retries, creating a tight loop that reads /proc/loadavg and /proc/meminfo millions of times per second, driving CPU to 100% and making the load condition self-sustaining.
  • Added break when executeWorkerWithConcurrencyControl() returns null (worker deferred). The worker is already back in the queue and will be retried when the next scheduled worker completes via its finally block.

Test plan

  • Ran claude-flow daemon start and confirmed CPU stays low
  • Triggered worker tasks and verified they still execute correctly

🤖 Generated with claude-flow

When a pending worker was deferred by canRunWorker() (e.g. CPU load
above threshold), it was pushed back onto the pendingWorkers queue
and executeWorkerWithConcurrencyControl returned null. The while loop
in processPendingWorkers() immediately retried since the queue was
non-empty and no workers were running, creating a tight loop that
read /proc/loadavg and /proc/meminfo millions of times per second.

The loop itself drove CPU to 100%, keeping load average permanently
above the threshold, making it self-sustaining.

Break out of the loop when a worker is deferred. The worker is already
back in the queue and will be retried when the next scheduled worker
completes (each worker's finally block calls processPendingWorkers).

Co-Authored-By: claude-flow <ruv@ruv.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant