Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(desktop): never report a daemon log record as the Computer's exit reason

Dongdong Chen2b567df53bf9
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 78e6c21a..9927db68 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -275,7 +275,10 @@ Gateway and runs Agents. The daemon exits with the app.
`desktop` section puts the daemon in Desktop mode: no self-update, it exits
when its stdin closes, and it reports `{"type":"status",...}` lines on
stdout, which drive the tray and the SPA status. Its log goes to
- `<userData>/logs/computer-daemon.log`. Crashes restart with backoff; new
+ `<userData>/logs/computer-daemon.log`. Crashes restart with backoff; the
+ exit reason, logged with `computer_daemon.exited` and shown once starts
+ keep failing, is the last stderr line outside the daemon's log records (a
+ Go crash: its `panic:` line), or none; new
folders or a new name restart it once tasks finish.
On macOS it writes `{"type":"hello","features":["permissions.v1"]}` to
the daemon's stdin after spawn and answers `permission.request` lines with
diff --git a/apps/desktop/src/main/computer-daemon.test.ts b/apps/desktop/src/main/computer-daemon.test.ts
index b7c7ff27..8a7d0518 100644
--- a/apps/desktop/src/main/computer-daemon.test.ts
+++ b/apps/desktop/src/main/computer-daemon.test.ts
@@ -630,4 +630,57 @@ describe.skipIf(process.platform === "win32")("spawnDaemon", () => {
expect(reason).toBe("read Computer config: denied");
expect(readFileSync(log, "utf8")).toContain("starting\n");
});
+
+ const exitOf = async (script: string) => {
+ const directory = mkdtempSync(path.join(os.tmpdir(), "spawn-daemon-"));
+ const executable = path.join(directory, "daemon");
+ writeFileSync(executable, `#!/bin/sh\n${script}`);
+ chmodSync(executable, 0o755);
+ const log = path.join(directory, "logs", "computer-daemon.log");
+ const child = spawnDaemon(executable, log)("config.json", {});
+ return new Promise<[number | null, string?]>((resolve) =>
+ child.onExit((...exit) => resolve(exit)),
+ );
+ };
+
+ it("never takes a log record for the exit reason", async () => {
+ const [code, reason] = await exitOf(
+ [
+ 'echo "2026/11/17 20:26:26 INFO local_models.job_finished action=download exit_code=0" >&2',
+ 'echo "2026/11/17 20:29:38 WARN runtime.diagnostic type=pi status=ready" >&2',
+ "kill -9 $$",
+ ].join("\n"),
+ );
+ expect(code).toBeNull();
+ expect(reason).toBeUndefined();
+ });
+
+ it("keeps the error the daemon printed when log records follow it", async () => {
+ const [, reason] = await exitOf(
+ [
+ 'echo "2026/11/17 20:26:26 INFO daemon.started" >&2',
+ 'echo "read Computer config: private path is not owned by the current user" >&2',
+ 'echo "2026/11/17 20:26:27 INFO runner.shutdown phase=completed" >&2',
+ "exit 1",
+ ].join("\n"),
+ );
+ expect(reason).toBe(
+ "read Computer config: private path is not owned by the current user",
+ );
+ });
+
+ it("reports a Go panic by its panic line, not its stack trace", async () => {
+ const [code, reason] = await exitOf(
+ [
+ 'echo "panic: assignment to entry in nil map" >&2',
+ "echo >&2",
+ 'echo "goroutine 1 [running]:" >&2',
+ 'echo "main.main()" >&2',
+ 'echo "\t/src/main.go:10 +0x1d" >&2',
+ "exit 2",
+ ].join("\n"),
+ );
+ expect(code).toBe(2);
+ expect(reason).toBe("panic: assignment to entry in nil map");
+ });
});
diff --git a/apps/desktop/src/main/computer-daemon.ts b/apps/desktop/src/main/computer-daemon.ts
index 5fd584d8..dceacb73 100644
--- a/apps/desktop/src/main/computer-daemon.ts
+++ b/apps/desktop/src/main/computer-daemon.ts
@@ -545,6 +545,12 @@ export class ComputerDaemonModule implements Module {
// Starts the daemon executable with only the given environment. Its stderr
// (the daemon log) and any stdout that is not a status line go to logFile.
+// A record of the daemon's log: Go's log package prefix, then the level.
+const LOG_RECORD =
+ /^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? (?:DEBUG|INFO|WARN|ERROR)\b/;
+// The first line of a Go runtime crash.
+const GO_CRASH = /^(?:panic|fatal error): /;
+
export const spawnDaemon =
(executable: string, logFile: string): SpawnDaemon =>
(configFile, env) => {
@@ -576,9 +582,15 @@ export const spawnDaemon =
});
};
child.stderr.pipe(log, { end: false });
+ // The daemon prints why it stopped as its last line outside its log;
+ // its log records (a timestamp, then the level) may come from any time
+ // before. A Go runtime crash leads with its panic line, then a trace.
+ let crashed = false;
createInterface({ input: child.stderr }).on("line", (line) => {
const text = line.trim();
- if (text) reason = text.slice(0, 500);
+ if (!text || crashed || LOG_RECORD.test(text)) return;
+ crashed = GO_CRASH.test(text);
+ reason = text.slice(0, 500);
});
createInterface({ input: child.stdout }).on("line", (line) => {
if (line.startsWith("{")) for (const listener of lines) listener(line);