Skip to content

Implement atomic file operations for URL fetch caching#14843

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/use-atomic-fetch-rename
Closed

Implement atomic file operations for URL fetch caching#14843
Copilot wants to merge 2 commits intomainfrom
copilot/use-atomic-fetch-rename

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

URL content caching in runtime_import.cjs was vulnerable to race conditions and partial writes when multiple workflow runs fetched the same URL concurrently.

Changes

  • Atomic write-then-rename pattern in fetchUrlContent():
    • Write to temporary file: ${cacheFile}.tmp.${process.pid}.${Date.now()}
    • Atomic rename via fs.renameSync() (POSIX guarantee)
    • Cleanup temp file on error
// Write to temporary file first
const tempFile = `${cacheFile}.tmp.${process.pid}.${Date.now()}`;
fs.writeFileSync(tempFile, data, "utf8");

// Atomic rename - file is either complete or absent
fs.renameSync(tempFile, cacheFile);

This ensures cache files are never partially written - concurrent readers either see the complete file or no file at all.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement atomic fetch and rename for URLs in JavaScript Implement atomic file operations for URL fetch caching Feb 10, 2026
Copilot AI requested a review from pelikhan February 10, 2026 22:06
@pelikhan pelikhan closed this Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments