From 3c865aa6fcea60d9caa340fd113dbca5620a0948 Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Wed, 29 Jul 2026 04:35:04 +0800 Subject: [PATCH] fix(runtime): keep operation deadlines alive --- electron/bridges/compressUploadBridge.cjs | 2 -- electron/bridges/externalMcp/boundedCliCommand.cjs | 1 - electron/bridges/scriptBridge.test.cjs | 4 ++-- electron/plugins/companionSupervisor.cjs | 1 - electron/plugins/contributionIconRasterizer.cjs | 1 - electron/scripts/scriptRuntime.test.cjs | 4 ++-- 6 files changed, 4 insertions(+), 9 deletions(-) diff --git a/electron/bridges/compressUploadBridge.cjs b/electron/bridges/compressUploadBridge.cjs index f7d03b5aa..76a0faf78 100644 --- a/electron/bridges/compressUploadBridge.cjs +++ b/electron/bridges/compressUploadBridge.cjs @@ -246,7 +246,6 @@ function runRemoteExec(sshClient, command, options = {}) { finish(new Error(`Remote command timed out after ${timeoutMs / 1000} seconds`)); if (!stream) invalidateSshTransport(sshClient); }, timeoutMs); - if (typeof timeout.unref === 'function') timeout.unref(); if (signal?.aborted) { onAbort(); @@ -427,7 +426,6 @@ async function checkTarAvailable(signal) { }; const onAbort = () => stop(); const timeout = setTimeout(stop, LOCAL_TAR_PROBE_TIMEOUT_MS); - if (typeof timeout.unref === 'function') timeout.unref(); if (signal?.aborted) { stop(); return; diff --git a/electron/bridges/externalMcp/boundedCliCommand.cjs b/electron/bridges/externalMcp/boundedCliCommand.cjs index f3758aad4..4f033a456 100644 --- a/electron/bridges/externalMcp/boundedCliCommand.cjs +++ b/electron/bridges/externalMcp/boundedCliCommand.cjs @@ -148,7 +148,6 @@ function runBoundedCliCommand(deps, command, args = [], options = {}) { error.code = "CLI_TIMEOUT"; rejectAndTerminate(error); }, timeoutMs); - timeoutTimer.unref?.(); if (signal?.aborted) onAbort(); }); } diff --git a/electron/bridges/scriptBridge.test.cjs b/electron/bridges/scriptBridge.test.cjs index a35e8b0f5..975c41d38 100644 --- a/electron/bridges/scriptBridge.test.cjs +++ b/electron/bridges/scriptBridge.test.cjs @@ -1912,11 +1912,11 @@ test("script sendLine invalidates startup seed before later waits", async () => permissionMode: "auto", }); - await delay(80); + await waitUntil(() => writes.some((data) => String(data).includes("echo hi"))); assert.ok(writes.some((data) => String(data).includes("echo hi"))); // Startup seed must be gone: waits should not resolve on old READY / old prompt. - await delay(80); + await delay(20); const midRun = sentRunUpdates.at(-1).find((run) => run.scriptId === "send-invalidates-seed"); assert.equal(midRun.status, "running"); diff --git a/electron/plugins/companionSupervisor.cjs b/electron/plugins/companionSupervisor.cjs index 082012bb5..4a7bd2063 100644 --- a/electron/plugins/companionSupervisor.cjs +++ b/electron/plugins/companionSupervisor.cjs @@ -297,7 +297,6 @@ class CompanionRpcPeer { this.#retireResponseId(key); reject(new PluginRpcError(RPC_ERRORS.deadlineExceeded, `Companion request timed out: ${method}`)); }, timeoutMs); - timer.unref?.(); this.pending.set(key, { resolve, reject, timer }); try { this.#send({ jsonrpc: "2.0", id, method, ...(params === undefined ? {} : { params }) }); diff --git a/electron/plugins/contributionIconRasterizer.cjs b/electron/plugins/contributionIconRasterizer.cjs index ab684c345..7b81cf8a0 100644 --- a/electron/plugins/contributionIconRasterizer.cjs +++ b/electron/plugins/contributionIconRasterizer.cjs @@ -10,7 +10,6 @@ function withTimeout(promise, timeoutMs, message) { promise, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(message)), timeoutMs); - timer.unref?.(); }), ]).finally(() => clearTimeout(timer)); } diff --git a/electron/scripts/scriptRuntime.test.cjs b/electron/scripts/scriptRuntime.test.cjs index 71456b30d..b5dcd0ccf 100644 --- a/electron/scripts/scriptRuntime.test.cjs +++ b/electron/scripts/scriptRuntime.test.cjs @@ -240,11 +240,11 @@ test("createScriptRuntime heartbeat remains healthy while a host request is paus isPaused: () => paused, isAborted: () => false, onStatusChange: () => {}, - syncExecutionTimeoutMs: 20, + syncExecutionTimeoutMs: 250, }); const execution = runtime.execute("await nct.screen.send('after-pause');"); - setTimeout(() => { paused = false; }, 80); + setTimeout(() => { paused = false; }, 400); await execution; assert.deepEqual(writes, ["after-pause"]); assert.equal(_getActiveScriptWorkerCountForTests(), 0);