Skip to content

fix: daemon resource thresholds incompatible with macOS (upstream #1078)#5

Open
blackms wants to merge 1 commit intomainfrom
codex/recreate-pr-1078-daemon-macos
Open

fix: daemon resource thresholds incompatible with macOS (upstream #1078)#5
blackms wants to merge 1 commit intomainfrom
codex/recreate-pr-1078-daemon-macos

Conversation

@blackms
Copy link
Owner

@blackms blackms commented Feb 6, 2026

Replica upstream

Questa PR ricrea nel fork la fix upstream:

Contenuto

  • Correzione soglie risorse daemon incompatibili con macOS
  • Soglia CPU resa core-aware invece di valore fisso troppo basso
  • minFreeMemoryPercent resa compatibile con semantica os.freemem() su macOS
  • Rimosso --quiet hardcoded nello spawn background per miglior diagnosi

Metodo

Cherry-pick del commit upstream f95a4d55af3172c03219c8212873aca60e893c27 (con -x).

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Adjusted resource thresholds for improved macOS compatibility
    • CPU load checking now uses dynamic, core-aware thresholds
    • Daemon startup messages now visible in logs for better debugging
    • Enhanced error messages to display resource threshold values when limits are exceeded

The daemon canRunWorker() resource check has two threshold defaults that
prevent workers from ever executing on macOS:

1. maxCpuLoad: 2.0 — os.loadavg() returns system-wide load (not per-core),
   so an 8-core Mac under normal workload reports ~8-16, far exceeding 2.0.
   Changed to 0 (dynamic) with core-aware threshold of cpus().length * 3.

2. minFreeMemoryPercent: 20 — macOS os.freemem() only reports truly unused
   RAM (not reclaimable cache), typically showing 1-5% on a Mac even with
   plenty available. Changed to 1%.

Also removed hardcoded --quiet flag from background daemon spawn that
suppressed all worker event logging to the log file.

Fixes ruvnet#1077

(cherry picked from commit f95a4d5)
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

The changes modify daemon startup and resource threshold behavior. The background daemon startup no longer suppresses output messages, and resource threshold defaults have been updated with CPU load now using a core-aware dynamic calculation when disabled.

Changes

Cohort / File(s) Summary
Daemon Startup Configuration
v3/@claude-flow/cli/src/commands/daemon.ts
Removed --quiet flag from background daemon invocation, allowing startup messages to be logged instead of suppressed.
Worker Daemon Resource Thresholds
v3/@claude-flow/cli/src/services/worker-daemon.ts
Updated default resource thresholds (maxCpuLoad from 2.0 to 0, minFreeMemoryPercent from 20 to 1); implemented dynamic CPU threshold calculation based on CPU core count when maxCpuLoad is disabled; enhanced error messages to include actual threshold values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The daemon now speaks its truth out loud,
No silent whispers in the background crowd,
With cores counted and thresholds made wise,
The worker runs smart beneath watchful eyes.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing daemon resource thresholds incompatible with macOS, referencing the upstream issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/recreate-pr-1078-daemon-macos

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@v3/`@claude-flow/cli/src/services/worker-daemon.ts:
- Around line 248-257: The cpuThreshold calculation can become zero when
os.cpus().length === 0; update the fallback to ensure a minimum core count
(e.g., use Math.max(os.cpus().length, 1)) so the dynamic threshold isn't zero.
Specifically, in the block that computes cpuThreshold (references: cpuThreshold,
this.config.resourceThresholds.maxCpuLoad, os.cpus().length, cpuLoad) replace
the fallback expression with a core-aware expression that applies a floor of 1
core before multiplying (or otherwise enforce a non-zero minimum threshold) so
the subsequent cpuLoad > cpuThreshold check behaves correctly in
containerized/restricted environments.

Comment on lines +248 to +257
// CPU check: use configured threshold, or if 0 (default), compute a
// dynamic core-aware threshold (3x core count). os.loadavg() returns
// the system-wide load average, not per-core, so on an 8-core machine
// a load of 8 means 100% utilization — not overload.
const cpuThreshold = this.config.resourceThresholds.maxCpuLoad > 0
? this.config.resourceThresholds.maxCpuLoad
: os.cpus().length * 3;

if (cpuLoad > cpuThreshold) {
return { allowed: false, reason: `CPU load too high: ${cpuLoad.toFixed(2)} > ${cpuThreshold}` };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Edge case: os.cpus().length can be 0 in some environments, making the fallback threshold 0.

In certain containerized or restricted environments, os.cpus() may return an empty array. A threshold of 0 would cause cpuLoad > 0 to be almost always true, blocking all workers — ironically the same problem this PR fixes.

Consider adding a floor:

Proposed fix
     const cpuThreshold = this.config.resourceThresholds.maxCpuLoad > 0
       ? this.config.resourceThresholds.maxCpuLoad
-      : os.cpus().length * 3;
+      : Math.max(os.cpus().length, 1) * 3;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// CPU check: use configured threshold, or if 0 (default), compute a
// dynamic core-aware threshold (3x core count). os.loadavg() returns
// the system-wide load average, not per-core, so on an 8-core machine
// a load of 8 means 100% utilization — not overload.
const cpuThreshold = this.config.resourceThresholds.maxCpuLoad > 0
? this.config.resourceThresholds.maxCpuLoad
: os.cpus().length * 3;
if (cpuLoad > cpuThreshold) {
return { allowed: false, reason: `CPU load too high: ${cpuLoad.toFixed(2)} > ${cpuThreshold}` };
// CPU check: use configured threshold, or if 0 (default), compute a
// dynamic core-aware threshold (3x core count). os.loadavg() returns
// the system-wide load average, not per-core, so on an 8-core machine
// a load of 8 means 100% utilization — not overload.
const cpuThreshold = this.config.resourceThresholds.maxCpuLoad > 0
? this.config.resourceThresholds.maxCpuLoad
: Math.max(os.cpus().length, 1) * 3;
if (cpuLoad > cpuThreshold) {
return { allowed: false, reason: `CPU load too high: ${cpuLoad.toFixed(2)} > ${cpuThreshold}` };
🤖 Prompt for AI Agents
In `@v3/`@claude-flow/cli/src/services/worker-daemon.ts around lines 248 - 257,
The cpuThreshold calculation can become zero when os.cpus().length === 0; update
the fallback to ensure a minimum core count (e.g., use
Math.max(os.cpus().length, 1)) so the dynamic threshold isn't zero.
Specifically, in the block that computes cpuThreshold (references: cpuThreshold,
this.config.resourceThresholds.maxCpuLoad, os.cpus().length, cpuLoad) replace
the fallback expression with a core-aware expression that applies a floor of 1
core before multiplying (or otherwise enforce a non-zero minimum threshold) so
the subsequent cpuLoad > cpuThreshold check behaves correctly in
containerized/restricted environments.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

🔗 Integration Test Results

🔗 Cross-Agent Integration Test Report

Session ID: integration-20260206-223949-5ba1cfdbbb5b39751636dd70b3d07bcbd554c921
Timestamp: 2026-02-06T22:43:03.064Z
Overall Status: ✅ PASSED

Summary

  • Total Tests: 4
  • Passed: 4
  • Failed: 0
  • Success Rate: 100.0%

Test Results

Component Status Details
Agent Coordination Multi-agent communication and task distribution
Memory Integration Shared memory operations and synchronization
Fault Tolerance Failure recovery and system resilience
Performance Multi-agent performance and scalability

Recommendations

  • All integration tests passed successfully!

Next Steps

  1. Review detailed test artifacts
  2. Address any failed test scenarios
  3. Monitor integration performance in production

Generated by Cross-Agent Integration Test Pipeline

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.

2 participants