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): report the daemon's exit after its log is written

LeoXingd06924ab73f8
diff --git a/apps/desktop/src/main/computer-daemon.ts b/apps/desktop/src/main/computer-daemon.ts
index bed05541..14ec5ac4 100644
--- a/apps/desktop/src/main/computer-daemon.ts
+++ b/apps/desktop/src/main/computer-daemon.ts
@@ -8,6 +8,7 @@ import {
} from "node:fs";
import path from "node:path";
import { createInterface } from "node:readline";
+import { finished } from "node:stream";
import type { RuntimeState } from "../shared/api.js";
import type {
@@ -549,13 +550,20 @@ export const spawnDaemon =
});
const lines: ((line: string) => void)[] = [];
const exits: ((code: number | null, reason?: string) => void)[] = [];
+ let exiting = false;
let exited: { code: number | null; reason?: string } | undefined;
let reason: string | undefined;
const exit = (code: number | null): void => {
- if (exited) return;
- exited = { code, ...(reason ? { reason } : {}) };
+ if (exiting) return;
+ exiting = true;
+ const result = { code, ...(reason ? { reason } : {}) };
log.end();
- for (const listener of exits) listener(code, reason);
+ // Listeners hear of the exit once the log file holds everything the
+ // daemon wrote, or once the log has failed.
+ finished(log, () => {
+ exited = result;
+ for (const listener of exits) listener(result.code, result.reason);
+ });
};
child.stderr.pipe(log, { end: false });
createInterface({ input: child.stderr }).on("line", (line) => {