From cb593bf5eefa65feac7349360fd7e1278eabb948 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 21:55:26 +0000 Subject: [PATCH 1/2] Initial plan From 8be344074bf4d90f6ac8da9d4bdd09cb90b66bbf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 22:04:39 +0000 Subject: [PATCH 2/2] Implement atomic file operations for URL fetching in runtime_import.cjs Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/runtime_import.cjs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/actions/setup/js/runtime_import.cjs b/actions/setup/js/runtime_import.cjs index ec31047b8c8..f4b4f69fff0 100644 --- a/actions/setup/js/runtime_import.cjs +++ b/actions/setup/js/runtime_import.cjs @@ -466,9 +466,30 @@ async function fetchUrlContent(url, cacheDir) { }); res.on("end", () => { - // Cache the content - fs.writeFileSync(cacheFile, data, "utf8"); - resolve(data); + // Use atomic write-then-rename pattern to prevent partial writes + // Generate unique temporary filename with process ID and timestamp + const tempFile = `${cacheFile}.tmp.${process.pid}.${Date.now()}`; + + try { + // Write to temporary file first + fs.writeFileSync(tempFile, data, "utf8"); + + // Atomic rename (POSIX guarantee) - ensures file is either completely written or not present + fs.renameSync(tempFile, cacheFile); + + resolve(data); + } catch (error) { + // Clean up temporary file on error + try { + if (fs.existsSync(tempFile)) { + fs.unlinkSync(tempFile); + } + } catch (cleanupError) { + // Ignore cleanup errors + } + const errorMessage = error instanceof Error ? error.message : String(error); + reject(new Error(`Failed to cache URL content: ${errorMessage}`)); + } }); }) .on("error", err => {