🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(daemon): explicit maxConcurrent/workerTimeoutMs win over saved daemon-state (#4462) (#4465)
rUvfe99f748c577
diff --git a/v3/@claude-flow/cli/__tests__/daemon-explicit-config-wins-4462.test.ts b/v3/@claude-flow/cli/__tests__/daemon-explicit-config-wins-4462.test.tsnew file mode 100644index 0000000000..436bb4a9be--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/daemon-explicit-config-wins-4462.test.ts@@ -0,0 +1,70 @@+/**+ * Regression guard for ruvnet/ruflo#4462.+ *+ * #2935 stopped a stale .claude-flow/daemon-state.json from overriding an+ * explicit resourceThresholds value, but the maxConcurrent and+ * workerTimeoutMs restores directly below it were left unconditional. A+ * `daemon.maxConcurrent` raised in config.json therefore had no effect while+ * a saved value existed. Precedence for both fields is now+ * constructor arg > config.json > saved state > default.+ */+import { describe, it, expect, afterEach } from 'vitest';+import { WorkerDaemon } from '../src/services/worker-daemon.js';+import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from 'fs';+import { join } from 'path';+import { tmpdir } from 'os';++describe('#4462 — explicit maxConcurrent / workerTimeoutMs beat daemon-state.json', () => {+ let tempDir: string;++ afterEach(() => {+ rmSync(tempDir, { recursive: true, force: true });+ process.removeAllListeners('SIGTERM');+ process.removeAllListeners('SIGINT');+ process.removeAllListeners('SIGHUP');+ });++ function setup(file?: Record<string, unknown>): string {+ tempDir = mkdtempSync(join(tmpdir(), 'daemon-4462-test-'));+ mkdirSync(join(tempDir, '.claude-flow', 'logs'), { recursive: true });+ if (file) writeFileSync(join(tempDir, '.claude-flow', 'config.json'), JSON.stringify(file));+ writeFileSync(+ join(tempDir, '.claude-flow', 'daemon-state.json'),+ JSON.stringify({ running: false, config: { maxConcurrent: 2, workerTimeoutMs: 111000 }, workers: {} }),+ );+ return tempDir;+ }++ it('config.json daemon.maxConcurrent / workerTimeoutMs win over saved state', () => {+ const dir = setup({ 'daemon.maxConcurrent': 5, 'daemon.workerTimeoutMs': 222000 });+ const c = new WorkerDaemon(dir).getStatus().config;+ expect(c.maxConcurrent).toBe(5);+ expect(c.workerTimeoutMs).toBe(222000);+ });++ it('constructor args win over saved state', () => {+ const dir = setup();+ const c = new WorkerDaemon(dir, { maxConcurrent: 7, workerTimeoutMs: 333000 }).getStatus().config;+ expect(c.maxConcurrent).toBe(7);+ expect(c.workerTimeoutMs).toBe(333000);+ });++ it('constructor arg wins over config.json', () => {+ const dir = setup({ 'daemon.maxConcurrent': 5 });+ expect(new WorkerDaemon(dir, { maxConcurrent: 7 }).getStatus().config.maxConcurrent).toBe(7);+ });++ it('with no explicit source, saved state is still restored', () => {+ const dir = setup();+ const c = new WorkerDaemon(dir).getStatus().config;+ expect(c.maxConcurrent).toBe(2);+ expect(c.workerTimeoutMs).toBe(111000);+ });++ it('per-field: an explicit maxConcurrent does not block restoring workerTimeoutMs', () => {+ const dir = setup({ 'daemon.maxConcurrent': 5 });+ const c = new WorkerDaemon(dir).getStatus().config;+ expect(c.maxConcurrent).toBe(5);+ expect(c.workerTimeoutMs).toBe(111000);+ });+});diff --git a/v3/@claude-flow/cli/src/services/worker-daemon.ts b/v3/@claude-flow/cli/src/services/worker-daemon.tsindex 456b825f2c..61e6296b37 100644--- a/v3/@claude-flow/cli/src/services/worker-daemon.ts+++ b/v3/@claude-flow/cli/src/services/worker-daemon.ts@@ -274,6 +274,9 @@ export class WorkerDaemon extends EventEmitter {// .claude-flow/daemon-state.json had persisted from a previous run.private fileConfigResourceThresholds?: { maxCpuLoad?: number; minFreeMemoryPercent?: number };+ // #4462 — the same record for maxConcurrent / workerTimeoutMs.+ private fileConfigScalars?: { maxConcurrent?: number; workerTimeoutMs?: number };+// #2661 root-fix — resolved once (git identity doesn't change at runtime)// and reused for lease heartbeats + supervisor election, both gated on// aiWorkersEnabled since they only matter for the recurring AI schedule.@@ -295,6 +298,7 @@ export class WorkerDaemon extends EventEmitter {maxCpuLoad: fileConfig.maxCpuLoad,minFreeMemoryPercent: fileConfig.minFreeMemoryPercent,};+ this.fileConfigScalars = { maxConcurrent: fileConfig.maxConcurrent, workerTimeoutMs: fileConfig.workerTimeoutMs };// CPU-proportional smart default instead of hardcoded 2.0const cpuCount = WorkerDaemon.getEffectiveCpuCount();@@ -858,10 +862,16 @@ export class WorkerDaemon extends EventEmitter {this.config.resourceThresholds.minFreeMemoryPercent = rt.minFreeMemoryPercent;}}- if (typeof saved.config?.maxConcurrent === 'number' && saved.config.maxConcurrent > 0) {+ // #4462 — same rule for the two scalar fields: constructor arg or+ // config.json beats saved state, which only fills in what neither set.+ const maxConcurrentExplicit = this.originalConfig?.maxConcurrent !== undefined+ || this.fileConfigScalars?.maxConcurrent !== undefined;+ const workerTimeoutExplicit = this.originalConfig?.workerTimeoutMs !== undefined+ || this.fileConfigScalars?.workerTimeoutMs !== undefined;+ if (!maxConcurrentExplicit && typeof saved.config?.maxConcurrent === 'number' && saved.config.maxConcurrent > 0) {this.config.maxConcurrent = saved.config.maxConcurrent;}- if (typeof saved.config?.workerTimeoutMs === 'number' && saved.config.workerTimeoutMs > 0) {+ if (!workerTimeoutExplicit && typeof saved.config?.workerTimeoutMs === 'number' && saved.config.workerTimeoutMs > 0) {this.config.workerTimeoutMs = saved.config.workerTimeoutMs;}