From 98e0e6f8a9316ac1d7519f0536fd6872897e3e7e Mon Sep 17 00:00:00 2001 From: SidQin-cyber Date: Wed, 25 Feb 2026 09:37:50 +0800 Subject: [PATCH] fix(windows): make bonjour advertiser opt-in to avoid cmd flash Disable Bonjour advertiser startup on Windows by default (with explicit env opt-in) to prevent periodic cmd/arp helper windows from flashing during network probing. Co-authored-by: Cursor --- src/infra/bonjour.test.ts | 25 +++++++++++++++++++++++++ src/infra/bonjour.ts | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/src/infra/bonjour.test.ts b/src/infra/bonjour.test.ts index d8f976fdc41ac..513250968c446 100644 --- a/src/infra/bonjour.test.ts +++ b/src/infra/bonjour.test.ts @@ -307,4 +307,29 @@ describe("gateway bonjour advertiser", () => { await started.stop(); }); + + it("disables Bonjour on win32 unless explicitly enabled", async () => { + enableAdvertiserUnitMode(); + vi.spyOn(process, "platform", "get").mockReturnValue("win32"); + + const started = await startGatewayBonjourAdvertiser({ + gatewayPort: 18789, + sshPort: 2222, + }); + expect(createService).not.toHaveBeenCalled(); + await started.stop(); + + createService.mockClear(); + process.env.OPENCLAW_ENABLE_BONJOUR_WINDOWS = "1"; + const destroy = vi.fn().mockResolvedValue(undefined); + const advertise = vi.fn().mockResolvedValue(undefined); + mockCiaoService({ advertise, destroy }); + + const enabled = await startGatewayBonjourAdvertiser({ + gatewayPort: 18789, + sshPort: 2222, + }); + expect(createService).toHaveBeenCalledTimes(1); + await enabled.stop(); + }); }); diff --git a/src/infra/bonjour.ts b/src/infra/bonjour.ts index 7d405741a0ecd..95b956b90b77f 100644 --- a/src/infra/bonjour.ts +++ b/src/infra/bonjour.ts @@ -29,6 +29,14 @@ function isDisabledByEnv() { if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_BONJOUR)) { return true; } + // On Windows, ciao's network probing can spawn visible cmd.exe helpers on some + // hosts. Keep Bonjour opt-in there to avoid periodic console-window flashing. + if ( + process.platform === "win32" && + !isTruthyEnvValue(process.env.OPENCLAW_ENABLE_BONJOUR_WINDOWS) + ) { + return true; + } if (process.env.NODE_ENV === "test") { return true; }