Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix: daemon restart have no logs
Gus55f015b96e71
diff --git a/src/cli/daemon/daemon.test.ts b/src/cli/daemon/daemon.test.tsindex 8887297c1..17b832ad0 100644--- a/src/cli/daemon/daemon.test.ts+++ b/src/cli/daemon/daemon.test.ts@@ -941,6 +941,18 @@ describe("spawnSessionRunner", () => {const decoded = JSON.parse(Buffer.from(encoded, "base64").toString("utf-8"));expect(decoded.logFilePath).toBe("/tmp/alook/daemon/session-runners/t1.log");});++ it("spawns with stdio ignore when openSync fails (disk full)", () => {+ mockOpenSync.mockImplementation(() => { throw new Error("ENOSPC: no space left on device"); });++ const child = spawnSessionRunner(makeSpawnInput() as any);++ expect(spawn).toHaveBeenCalledTimes(1);+ const call = vi.mocked(spawn).mock.calls[0];+ expect((call[2] as any).stdio).toEqual(["ignore", "ignore", "ignore"]);+ expect(child.unref).toHaveBeenCalled();+ expect(mockCloseSync).not.toHaveBeenCalled();+ });});describe("pruneSessionRunnerLogs", () => {@@ -961,14 +973,14 @@ describe("pruneSessionRunnerLogs", () => {});it("does not delete when at or below limit", () => {- const files = Array.from({ length: 50 }, (_, i) => `${i}.log`);+ const files = Array.from({ length: 500 }, (_, i) => `${i}.log`);mockReaddirSync.mockReturnValue(files);pruneSessionRunnerLogs();expect(mockUnlinkSync).not.toHaveBeenCalled();});- it("deletes oldest files when over limit, keeping newest 50", () => {- const files = Array.from({ length: 55 }, (_, i) => `${i}.log`);+ it("deletes oldest files when over limit, keeping newest 500", () => {+ const files = Array.from({ length: 505 }, (_, i) => `${i}.log`);mockReaddirSync.mockReturnValue(files);mockStatSync.mockImplementation((p: string) => {const name = p.split("/").pop()!;@@ -992,7 +1004,7 @@ describe("pruneSessionRunnerLogs", () => {mockReaddirSync.mockReturnValue(files);mockStatSync.mockReturnValue({ mtimeMs: 0 });pruneSessionRunnerLogs();- // Only 2 .log files, well under 50 limit+ // Only 2 .log files, well under 500 limitexpect(mockUnlinkSync).not.toHaveBeenCalled();});});diff --git a/src/cli/daemon/daemon.ts b/src/cli/daemon/daemon.tsindex e56504673..42a0ec269 100644--- a/src/cli/daemon/daemon.ts+++ b/src/cli/daemon/daemon.ts@@ -49,7 +49,7 @@ function isCommandAvailable(cmd: string): boolean {}}-const MAX_SESSION_RUNNER_LOGS = 50;+const MAX_SESSION_RUNNER_LOGS = 500;export function pruneSessionRunnerLogs(): void {const logDir = sessionRunnerLogDir();@@ -376,14 +376,19 @@ export async function startDaemon(if (profile) args.push("--profile", profile);if (serverUrl) args.push("--server", serverUrl);const logPath = daemonLogFilePath();- mkdirSync(dirname(logPath), { recursive: true, mode: 0o700 });- const logFd = openSync(logPath, "a", 0o600);+ let logFd: number | undefined;+ try {+ mkdirSync(dirname(logPath), { recursive: true, mode: 0o700 });+ logFd = openSync(logPath, "a", 0o600);+ } catch (e) {+ log.error(`Failed to open daemon log file ${logPath}`, e);+ }const child = spawn(process.execPath, args, {detached: true,- stdio: ["ignore", logFd, logFd],+ stdio: logFd != null ? ["ignore", logFd, logFd] : ["ignore", "ignore", "ignore"],});child.unref();- closeSync(logFd);+ if (logFd != null) closeSync(logFd);log.info(`Spawned new daemon (pid=${child.pid}), logs: ${logPath}`);}clearTimeout(timeout);@@ -403,14 +408,19 @@ export function spawnSessionRunner(input: SessionRunnerInput): ChildProcess {input.logFilePath = logFilePath;const encoded = Buffer.from(JSON.stringify(input)).toString("base64");- const fd = openSync(logFilePath, "a");+ let fd: number | undefined;+ try {+ fd = openSync(logFilePath, "a");+ } catch (e) {+ log.error(`Failed to open log file ${logFilePath}`, e);+ }const child = spawn(process.execPath, [sessionRunnerPath, encoded], {detached: true,- stdio: ["ignore", fd, fd],+ stdio: fd != null ? ["ignore", fd, fd] : ["ignore", "ignore", "ignore"],});child.unref();- closeSync(fd);+ if (fd != null) closeSync(fd);return child;}