🌊 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): report the running daemon's TTL in daemon status (#4238) (#4241)
kevine733bda3188b
diff --git a/v3/@claude-flow/cli/__tests__/daemon-status-ttl-4238.test.ts b/v3/@claude-flow/cli/__tests__/daemon-status-ttl-4238.test.tsnew file mode 100644index 0000000000..31efa823ff--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/daemon-status-ttl-4238.test.ts@@ -0,0 +1,53 @@+/**+ * #4238: `daemon status` printed the TTL of the status process's own+ * default-config WorkerDaemon (12h), not the running background daemon's,+ * so a daemon started with `--ttl 0` was reported as self-shutting down.+ * The background daemon persists its real config in daemon-state.json.+ */+import { afterEach, describe, expect, it, vi } from 'vitest';+import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { tmpdir } from 'node:os';+import { daemonCommand } from '../src/commands/daemon.js';+import { output } from '../src/output.js';+import type { CommandContext } from '../src/types.js';++const originalCwd = process.cwd();+let workspace: string | undefined;++afterEach(() => {+ process.chdir(originalCwd);+ vi.restoreAllMocks();+ if (workspace) rmSync(workspace, { recursive: true, force: true });+ workspace = undefined;+});++async function statusBoxFor(config: Record<string, unknown>): Promise<string> {+ workspace = mkdtempSync(join(tmpdir(), 'daemon-status-ttl-'));+ const stateDir = join(workspace, '.claude-flow');+ mkdirSync(stateDir, { recursive: true });+ // A live PID stands in for the background daemon.+ writeFileSync(join(stateDir, 'daemon.pid'), String(process.pid));+ writeFileSync(join(stateDir, 'daemon-state.json'), JSON.stringify({ running: true, config }));+ process.chdir(workspace);+ const lines: string[] = [];+ vi.spyOn(output, 'printBox').mockImplementation((content: string | string[]) => {+ lines.push(...(Array.isArray(content) ? content : [content]));+ });+ vi.spyOn(output, 'writeln').mockImplementation(() => undefined);+ const status = daemonCommand.subcommands!.find(c => c.name === 'status')!;+ await status.action!({ args: [], flags: {}, cwd: workspace, interactive: false } as unknown as CommandContext);+ return lines.join('\n');+}++describe('daemon status TTL (#4238)', () => {+ it('reports TTL off when the running background daemon has ttlMs 0', async () => {+ const box = await statusBoxFor({ ttlMs: 0 });+ expect(box).toContain('off (runs until stopped)');+ expect(box).not.toContain('(self-shutdown)');+ });++ it('reports the background daemon TTL rather than the 12h default', async () => {+ expect(await statusBoxFor({ ttlMs: 2 * 3600000 })).toContain('TTL: 2h (self-shutdown)');+ });+});diff --git a/v3/@claude-flow/cli/src/commands/daemon.ts b/v3/@claude-flow/cli/src/commands/daemon.tsindex 7e88e63944..1f950d1656 100644--- a/v3/@claude-flow/cli/src/commands/daemon.ts+++ b/v3/@claude-flow/cli/src/commands/daemon.ts@@ -1294,12 +1294,18 @@ const statusCommand: Command = {// its real consent state into daemon-state.json — prefer that when it// is the one running.let aiWorkersEnabled = status.config.aiWorkersEnabled;+ // #4238: same for the TTL — a daemon started with `--ttl 0` must not be+ // reported with this process's 12h default.+ let ttlMs = status.config.ttlMs;if (bgRunning) {try {const st = JSON.parse(fs.readFileSync(join(projectRoot, '.claude-flow', 'daemon-state.json'), 'utf-8'));if (typeof st?.config?.aiWorkersEnabled === 'boolean') {aiWorkersEnabled = st.config.aiWorkersEnabled;}+ if (typeof st?.config?.ttlMs === 'number' && Number.isFinite(st.config.ttlMs)) {+ ttlMs = st.config.ttlMs;+ }} catch { /* no/partial state — fall back to in-process config */ }}@@ -1315,8 +1321,8 @@ const statusCommand: Command = {`Status: ${statusIcon} ${statusText}${mode}`,`PID: ${displayPid}`,status.startedAt ? `Started: ${status.startedAt.toISOString()}` : '',- status.config.ttlMs > 0- ? `TTL: ${Math.round(status.config.ttlMs / 3600000)}h (self-shutdown)`+ ttlMs > 0+ ? `TTL: ${Math.round(ttlMs / 3600000)}h (self-shutdown)`: `TTL: ${output.dim('off (runs until stopped)')}`,// #2661: surface the AI-consent gate so "why is audit local-only?"// is answerable from `daemon status` alone.