From 565a81562ea3e0403f5505dd2415b89e5239f3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=9D=E7=81=B5=E4=BA=91?= Date: Tue, 27 Jan 2026 16:04:10 +0800 Subject: [PATCH] fix(gateway): respond before writing config in skills.update to prevent connection abort When enabling/disabling a skill via the Web UI, the skills.update RPC method would write the config file before sending the response. This caused the config file watcher to trigger a gateway restart (SIGUSR1) before the HTTP response could be sent to the client, resulting in connection abort errors. This change ensures the response is sent first by using setImmediate() to defer the config file write until after the response has been delivered. Fixes issue where skills toggle in Web UI would cause: - Unhandled promise rejection: AbortError: This operation was aborted - Gateway crash with "Failed running 'dist/entry.js gateway --force'" --- src/gateway/server-methods/skills.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gateway/server-methods/skills.ts b/src/gateway/server-methods/skills.ts index 955e05d0d..b6c85f840 100644 --- a/src/gateway/server-methods/skills.ts +++ b/src/gateway/server-methods/skills.ts @@ -176,7 +176,14 @@ export const skillsHandlers: GatewayRequestHandlers = { ...cfg, skills, }; - await writeConfigFile(nextConfig); + // Respond first to ensure the client receives the response before any gateway restart respond(true, { ok: true, skillKey: p.skillKey, config: current }, undefined); + // Write config asynchronously after responding to avoid aborting the response + // when the config file watcher triggers a gateway restart (SIGUSR1) + setImmediate(() => { + writeConfigFile(nextConfig).catch(() => { + // Config write errors are logged elsewhere; catch here to prevent unhandled rejection + }); + }); }, };