From 2dc73bb8cf2d09d1f3c8b44f4b09eb01d98f7afd Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Sat, 12 Sep 2026 06:43:42 +0300 Subject: [PATCH] coding-agent/modes/daemon: fix stop when the client already disconnected --- .../.changes/daemon-stop-detached-client.md | 1 + .../src/modes/daemon/daemon-supervisor.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 packages/coding-agent/.changes/daemon-stop-detached-client.md diff --git a/packages/coding-agent/.changes/daemon-stop-detached-client.md b/packages/coding-agent/.changes/daemon-stop-detached-client.md new file mode 100644 index 000000000..422e83c97 --- /dev/null +++ b/packages/coding-agent/.changes/daemon-stop-detached-client.md @@ -0,0 +1 @@ +- Fixed stop and kill failing when the target worker's client had already disconnected. diff --git a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts index c21e33b21..fa133cabe 100644 --- a/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts +++ b/packages/coding-agent/src/modes/daemon/daemon-supervisor.ts @@ -6657,16 +6657,20 @@ export class DaemonSupervisor { worker.transcriptCaches.clear(); worker.snapshotCache.clear(); worker.snapshotGenerations?.clear(); - if (worker.client) { + const client = worker.client; + if (client) { if (archiveSession) { - await worker.client + await client .requestWorker({ type: "worker_archive_and_shutdown" }, force ? 1000 : 5000) .catch(() => undefined); } else { - await worker.client.request({ type: "shutdown" }, force ? 1000 : 5000).catch(() => undefined); + await client.request({ type: "shutdown" }, force ? 1000 : 5000).catch(() => undefined); + } + client.close(); + // A reconnect can swap in another client while the shutdown request is in flight. + if (worker.client === client) { + worker.client = undefined; } - worker.client.close(); - worker.client = undefined; } else if (directChild) { directChild.child.kill("SIGTERM"); } else if (this.processIdentity(entryPid, entryStartId) === "current") { -- 2.51.2