fix(cloudflare-workers): do not use i/o operations outside fetch context#4042
Conversation
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Code Review - PR #4042SummaryThis PR addresses a Cloudflare Workers-specific issue by conditionally preparing the runtime only when necessary. The change prevents I/O operations from running outside of the fetch context, which is prohibited in Cloudflare Workers. ✅ Positive Aspects
🔍 Issues & Concerns1. Logic Error - Missing
|
d987869 to
4e40c0b
Compare
PR Review: fix(cloudflare-workers): do not use i/o operations outside fetch contextSummaryThis PR addresses a Cloudflare Workers limitation by preventing unnecessary runtime preparation when it's not needed. The change is well-targeted and the import reorganization is a nice cleanup. Bug: Dev Mode RegressionThe condition uses the raw input config object rather than the parsed config with defaults applied: if (config.serverless?.spawnEngine || config.serveManager) {From // Determine serveManager: default to true in dev mode without endpoint, false otherwise
const serveManager = config.serveManager ?? (isDevEnv && \!endpoint);In dev mode ( Cloudflare Workers is unaffected because Suggested fix — move the condition inside the // Auto-prepare on next tick (gives time for sync config modification)
setTimeout(() => {
const parsedConfig = this.parseConfig();
if (parsedConfig.serverless?.spawnEngine || parsedConfig.serveManager) {
// biome-ignore lint/nursery/noFloatingPromises: fire-and-forget auto-prepare
this.#ensureRuntime();
}
}, 0);This handles the Cloudflare Workers case (no I/O outside fetch context when neither flag is set), preserves dev mode behavior (auto-prepares when Minor: Comment placementThe comment moved inside the conditional, which is fine, but it describes the // Only auto-prepare when a local process will be needed. This avoids
// I/O operations outside the fetch context in environments like Cloudflare
// Workers where file system access is restricted.
if (...) {
// Deferred to next tick to allow sync config modifications to complete.
setTimeout(() => { ... }, 0);
}Test CoverageThe PR description has a good manual test plan, but an automated regression test would help catch this going forward — e.g., a test that verifies:
|
Graphite Automations"Test" took an action on this PR • (02/02/26)1 assignee was added to this PR based on Kacper Wojciechowski's automation. |
4e40c0b to
7fb6538
Compare
|
This change is part of the following stack: Change managed by git-spice. |

Closes RVT-5342
TL;DR
Only auto-prepare the runtime when necessary based on configuration.
What changed?
Added a conditional check before auto-preparing the runtime in the Registry constructor. Now, the runtime is only auto-prepared when either
config.serverless?.spawnEngineorconfig.serveManageris set to a truthy value.Also reordered the imports to place the Runtime import with the other imports from external files.
How to test?
serverless.spawnEngineset tofalseandserveManagerset tofalseserverless.spawnEngineorserveManagerset totrueWhy make this change?
This optimization prevents unnecessary runtime preparation when it's not needed based on the configuration. This can improve performance and reduce resource usage in scenarios where the runtime isn't required.