Skip to content

fix(stack): reuse the Deno cache when booting Edge Function workers - #7347

Merged
Coly010 merged 2 commits into
developfrom
columferry/cli-2850-stack-mode-edge-functions-that-boot-at-the-same-moment-fail
Oct 27, 2026
Merged

Coly010 merged 2 commits into
developfrom
columferry/cli-2850-stack-mode-edge-functions-that-boot-at-the-same-moment-fail

Conversation

@Coly010

@Coly010 Coly010 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

In stack mode, Edge Functions that boot at the same time can fail with 503 BOOT_ERROR. The logs show Failed caching npm package … File exists (os error 17), or No such file or directory when reading a cached package file. This sets noModuleCache: false when the stack bootstrap creates user workers, which is what classic functions serve already does.

What's going on

noModuleCache: true puts the worker's Deno cache into reload mode. Each worker builds its own npm cache, so nothing is shared between workers, and each one downloads every npm package it imports again. When that package is already in the shared DENO_DIR, Deno extracts it again in place, over the live copy, deleting and recreating each file. Two workers doing that at the same time collide, and a worker that reads a file in the middle of it finds it missing.

flowchart TD
  boot["Worker boots and imports npm:pkg"] --> flag{"noModuleCache"}
  flag -- "false" --> cached{"pkg in the cache?"}
  cached -- "yes" --> reuse["Reuse it"]
  cached -- "no" --> temp["Extract to a temp dir,<br/>then rename into place"]
  flag -- "true" --> cached2{"pkg in the cache?"}
  cached2 -- "no" --> temp
  cached2 -- "yes" --> inplace["Extract again in place,<br/>over the live copy"]
  inplace --> fail["Concurrent boots collide<br/>503 BOOT_ERROR"]
Loading
sequenceDiagram
  participant A as Worker A
  participant C as Shared Deno cache
  participant B as Worker B
  A->>C: create pkg/README.md (exists, so delete it)
  B->>C: create pkg/README.md (succeeds)
  A->>C: create pkg/README.md
  C-->>A: File exists (os error 17)
  Note over A: 503 BOOT_ERROR
Loading

This explains the odd parts of the report:

  • A package that isn't cached yet goes through the temp dir and rename, which is safe. That's why a cold first round often passes, and why a warm-up request doesn't help.
  • Native keeps its cache across stop and start, so it fails much more often than Docker, whose new container starts with an empty cache.
  • forceCreate: true boots a new worker for every request, so every request goes down this path. I've left it as it is, because it's what makes edits show up without a restart.

Against Edge Runtime directly, with only this flag changed, 40 of 64 concurrent boots failed with it on and none of 112 failed with it off.

What changes

  • npm packages and remote modules are reused from the cache instead of being downloaded and extracted on every boot, so boots are quicker too.
  • An exact version that isn't cached yet still resolves, because Deno fetches package info again when resolution fails. Floating versions like npm:x@latest stay on the cached version until the cache resets (a new container on Docker, stack destroy on native). That matches classic functions serve and deno run.
  • Local function code is still read from disk on every boot, so edits show up straight away.
  • A new integration test serves a package from a local npm registry, warms the cache, then boots several workers at once. It checks that they all succeed and that the package is downloaded only once.

Earlier bootstraps and classic functions serve use false. If true was there for something I've missed, I'm happy to talk it through.

Linked issue

Closes #7321 (CLI-2850)

The stack bootstrap created user workers with `noModuleCache: true`, which
puts each worker's Deno cache into reload mode. Every worker then downloads
its npm packages again and, when a package is already cached, re-extracts it
in place in the shared cache. Workers booting at the same time collide on the
same files and fail with 503 BOOT_ERROR ("File exists (os error 17)" or
"No such file or directory").

Create workers with `noModuleCache: false`, as classic `functions serve`
does, so cached packages are reused. Add an integration test that boots
workers concurrently against a local npm registry and checks the cached
package is not downloaded again.

Closes #7321
@Coly010 Coly010 self-assigned this Oct 27, 2026
@Coly010
Coly010 marked this pull request as ready for review October 27, 2026 13:08
@Coly010
Coly010 requested a review from a team as a code owner October 27, 2026 13:08

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

Both independent reviews reported zero findings. Inspection of the PR code found no additional issues: the cache setting, generated bundle, and regression tests are consistent. No fundamental conflict with the pending next-branch work was identified. Tests were not run during adjudication.

Findings

No issues found.

Stats

Claude findings: 0 · Codex findings: 0 · Confirmed: 0 · Refuted: 0 · Uncertain: 0


Models: claude-opus-5-5 + gpt-6.1-sol · Trigger: auto · Workflow run

This review runs once per PR. A maintainer can request another with a /ai-review comment.

@Coly010
Coly010 added this pull request to the merge queue Oct 27, 2026
Merged via the queue into develop with commit 2918d93 Oct 27, 2026
47 checks passed
@Coly010
Coly010 deleted the columferry/cli-2850-stack-mode-edge-functions-that-boot-at-the-same-moment-fail branch October 27, 2026 14:34
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.

Stack mode: edge functions that boot at the same moment fail with 503 BOOT_ERROR ("Failed caching npm package … File exists (os error 17)")

2 participants