[Workers Assets] _headers updates are dropped when wrangler deploy hits "No updated asset files to upload"

Open
#17,192 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Start by tracing how Wrangler handles static asset uploads during wrangler versions upload and wrangler deploy, especially the empty upload-session path that logs “No updated asset files to upload.” Compare how the _headers metadata is submitted and carried into the new Worker version when assets are uploaded versus when the upload is empty. Done means the deployed version retains the submitted _headers rules even when no asset files need uploading.

Written by the indexing model from the issue text.

Description

What versions & operating system are you using?
  • Wrangler: 4.166.0 (running in Cloudflare Workers Builds, Linux x64)
  • Node: 24.22.1, pnpm: 12.10.1
  • Framework / Adapter: [email protected], @astrojs/[email protected] (redirected dist/server/wrangler.json with assets.directory = "../client")
Please provide a link to a minimal reproduction

Public repository where this reproduced twice in a row on Workers Builds: https://github.com/withxat/ImI (see public/_headers added/updated in commit 46a9690 / PR #37, and again across PR #38).

Describe the Bug

When a Workers Builds PR preview runs npx wrangler versions upload and uploads new/modified static assets along with an updated _headers file, the resulting preview Worker version stores the updated _headers correctly in resources.script_runtime.assets.raw_headers and resources.script_runtime.assets.headers.rules.

Minutes later, when the same PR is merged to main and Workers Builds runs npx wrangler deploy, /assets-upload-session returns empty buckets (No updated asset files to upload. Proceeding with deployment...) because the preview build already uploaded the identical static asset hashes. On that wrangler deploy, the newly created production Worker version silently drops the _headers update and reverts raw_headers / headers.rules to the previous production _headers (from before PR #37).

Evidence across 5 consecutive builds (same repo, config, and Wrangler version)

Every commit below has the Content-Security-Policy line under /* in public/_headers, and every build log confirms Vite + @astrojs/cloudflare generated a fresh dist/client/_headers (logging ✨ Parsed 12 valid header rules. and [@astrojs/cloudflare] Injected immutable Cache-Control for /_astro/* into _headers., which @astrojs/cloudflare only logs when dist/client/_headers does not already contain /_astro/*):

Worker Version Branch / Commit Deploy command Asset upload result assets.raw_headers includes new Content-Security-Policy
#288 PR #37 preview (46a9690) npx wrangler versions upload Uploaded new static assets Yes
#289 main (868e5e4, PR #37 merge) npx wrangler deploy Assets already uploaded by #288 No (reverted to pre-PR #37 _headers)
#290 main (db8acc9, docs-only) npx wrangler deploy No updated asset files to upload No
#291 PR #38 preview (ae425e5) npx wrangler versions upload Found 35 new or modified static assets Yes
#292 main (d6c14d5, PR #38 merge) npx wrangler deploy No updated asset files to upload No (reverted to pre-PR #37 _headers again)
Expected Behavior

metadata.assets.config._headers submitted with wrangler deploy should always update assets.raw_headers and assets.headers.rules on the new Worker version, even when /assets-upload-session returns empty buckets (No updated asset files to upload) — otherwise any _headers-only edit or PR merge following a preview upload cannot take effect in production.

Reproduction Steps
  1. Configure a Worker with Static Assets and Cloudflare Workers Builds (PR previews running npx wrangler versions upload, main deploys running npx wrangler deploy).
  2. Open a PR that edits public/_headers (e.g. adds a Content-Security-Policy header under /*) along with static asset changes.
  3. After the PR preview build succeeds, inspect GET /accounts/{account_id}/workers/scripts/{script_name}/versions/{version_id} — resources.script_runtime.assets.raw_headers and headers.rules["/*"].set contain the new header.
  4. Merge the PR to main so Workers Builds runs npx wrangler deploy and logs No updated asset files to upload. Proceeding with deployment....
  5. Inspect the newly deployed production version via the same API and check static asset HTTP response headers — the new header is missing and raw_headers has reverted to the older production _headers.
Please provide any relevant error logs

No errors or warnings are emitted in either build.

PR #38 preview (wrangler versions upload -> version #291, _headers updated):

06:06:37 [vite] ✓ 109 assets moved from "ssr" to "client" build output.
✨ Parsed 12 valid header rules.
06:06:38 [build] Rearranging server assets...
06:06:38 [@astrojs/cloudflare] Injected immutable Cache-Control for /_astro/* into _headers.
Executing user deploy command: npx wrangler versions upload
🌀 Building list of assets...
✨ Read 504 files from the assets directory /opt/buildhome/repo/dist/client
🌀 Starting asset upload...
🌀 Found 35 new or modified static assets to upload. Proceeding with upload...
✨ Success! Uploaded 35 files (452 already uploaded) (1.06 sec)
Uploaded imi (3.39 sec)

main merge 2 minutes later (wrangler deploy -> version #292, _headers reverted):

06:08:41 [vite] ✓ 109 assets moved from "ssr" to "client" build output.
✨ Parsed 12 valid header rules.
06:08:42 [build] Rearranging server assets...
06:08:42 [@astrojs/cloudflare] Injected immutable Cache-Control for /_astro/* into _headers.
Executing user deploy command: npx wrangler deploy
🌀 Building list of assets...
✨ Read 504 files from the assets directory /opt/buildhome/repo/dist/client
🌀 Starting asset upload...
No updated asset files to upload. Proceeding with deployment...
Uploaded imi (3.31 sec)
Deployed imi triggers (0.48 sec)
Dominant language
TypeScript
Stars
4.7k
Forks
1.7k
Avg merge
1d 22h
Merged PRs (30d)
282

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.