A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.
TypeScript
fix(daemon): force a Windows tree at once when the soft taskkill fails
Marcelito740e501a6ee0
diff --git a/packages/daemon/src/supervisor.ts b/packages/daemon/src/supervisor.tsindex 3c5b98d..f30fc4e 100644--- a/packages/daemon/src/supervisor.ts+++ b/packages/daemon/src/supervisor.ts@@ -264,12 +264,17 @@ export class AgentSupervisor {else resolve();};const onClose = () => finish();+ let forced = false;const escalate = (force: boolean) => {- if (this.child !== child) return;+ if (this.child !== child || (force && forced)) return;+ if (force) forced = true;void terminate(child, force, { platform, isCurrent: () => this.child === child }).catch((error: Error) => {errors.push(error.message);this.log(error.message);+ // taskkill /T without /F cannot end a windowless console process and fails at once:+ // force the tree now instead of waiting out the hard window.+ if (!force && platform === "win32") escalate(true);},);};diff --git a/packages/daemon/test/supervisor.test.ts b/packages/daemon/test/supervisor.test.tsindex 8464673..e726fac 100644--- a/packages/daemon/test/supervisor.test.ts+++ b/packages/daemon/test/supervisor.test.ts@@ -368,6 +368,40 @@ describe("AgentSupervisor", () => {},);+ it("forces a Windows tree at once when the soft taskkill fails, without waiting the hard window", async () => {+ // taskkill /T without /F cannot end a windowless console process: it exits 255 at once.+ const escalations: boolean[] = [];+ const { supervisor } = track(+ fakeSupervisor({+ platform: "win32",+ command: process.execPath,+ args: ["-e", STUBBORN_AGENT, "--"],+ stopTimeoutMs: 1,+ terminateProcessTree: async (child, force) => {+ escalations.push(force);+ if (!force) throw new Error("taskkill failed for process tree with exit code 255");+ child.kill("SIGKILL");+ return true;+ },+ }),+ );+ await supervisor.start();+ vi.useFakeTimers();+ const stopped = supervisor.stop();+ void stopped.catch(() => {});+ try {+ await vi.advanceTimersByTimeAsync(1);+ expect(escalations).toEqual([false, true]);+ vi.useRealTimers();+ await stopped;+ expect(supervisor.state).toBe("stopped");+ // The hard window's own escalation finds the child gone: nothing is forced twice.+ expect(escalations).toEqual([false, true]);+ } finally {+ vi.useRealTimers();+ }+ });+it("keeps both Windows default stages bounded without rejecting before taskkill can finish", async () => {const escalations: boolean[] = [];const { supervisor } = track(