Skip to content

[StaticAssets] Avoid caching responses for missing manifest assets - #70062

Merged
pavelsavara merged 4 commits into
dotnet:mainfrom
pavelsavara:browser-boot-cache-server
Nov 4, 2026
Merged

pavelsavara merged 4 commits into
dotnet:mainfrom
pavelsavara:browser-boot-cache-server

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

[StaticAssets] Avoid caching responses for missing manifest assets

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Return non-cacheable 404s when a manifest asset disappears.

Description

When a file referenced by a static-assets manifest disappears, StaticAssetsInvoker catches FileNotFoundException and clears the response. Clearing resets it to an empty 200 response. A browser can cache that response and later reuse it for a fingerprinted Blazor boot resource.

  • Return 404 with Cache-Control: no-store after clearing the missing-file response, and log the missing asset.
  • In the development runtime handler, check that the source file exists before reading its length. Otherwise the request can throw before the invoker handles the missing asset.
  • Add eight HTTP integration cases covering development/runtime patching and production behavior, compressed and uncompressed responses, and removal before or after a successful request. They check the missing response and successful serving after restoration.
  • Preserve existing caching of healthy assets. This does not evict already-poisoned browser caches; loader recovery is implemented separately in [wasm] Reload failed force-cache assets through existing retries runtime#136527.

Validation

Commands were run from the repository root after . .\activate.ps1.

dotnet test .\src\StaticAssets\test\Microsoft.AspNetCore.StaticAssets.Tests.csproj -c Debug -bl /p:UseIisNativeAssets=false /p:RunAnalyzers=false --filter FullyQualifiedName~MissingAssetReturnsNonCacheableNotFound

Before the fix: 8 failed, 0 passed, 0 skipped. The four production cases returned an empty 200 instead of 404; the four development cases threw FileNotFoundException while reading the missing file's length.

dotnet test .\src\StaticAssets\test\Microsoft.AspNetCore.StaticAssets.Tests.csproj -c Debug -bl /p:UseIisNativeAssets=false /p:RunAnalyzers=false --filter FullyQualifiedName~StaticAssetsIntegrationTests

After the fix: 70 passed, 0 failed, 0 skipped, including all eight new cases.

Analyzers were temporarily disabled on the command line with the author's authorization because the unmodified dependency projects fail public-API analyzers locally. No analyzer suppression or build workaround is included in this PR. No browser E2E tests were run for this server-only change; the regression is exercised at the real HTTP static-asset endpoint via TestServer.

Contributes to #69488; this server-side prevention change does not by itself resolve existing poisoned browser caches.
Contributes to dotnet/runtime#135090

Note

This PR was generated with GitHub Copilot and reviewed and validated in a local coding session.

Avoid clearing a missing manifest asset response back to an empty 200.
Return 404 with no-store so transient deployment gaps cannot poison the
browser HTTP cache. Let the invoker handle missing development files
without reading their unavailable length.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 11:15
@github-actions github-actions Bot added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Oct 27, 2026

Copilot AI 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.

🔵 Needs a closer look

Required frozen-revision review evidence was unavailable, leaving approval checks incomplete and requiring final human review.

No open issues 🎉

What changed in this PR

This PR prevents missing manifest-backed static assets from producing cacheable empty responses. It addresses server-side prevention for #69488 without clearing already-poisoned browser caches.

Changes:

  • Return 404 with Cache-Control: no-store and log missing assets.
  • Check file existence before reading metadata in development runtime patching.
  • Add eight HTTP integration cases covering environment, compression, prior requests, and asset restoration.
File Description
src/​StaticAssets/​test/​StaticAssetsIntegrationTests.cs Tests missing-asset responses and recovery after restoration.
src/​StaticAssets/​src/​StaticAssetsInvoker.cs Returns and logs non-cacheable missing-file responses.
src/​StaticAssets/​src/​Development/​StaticAssetDevelopmentRuntimeHandler.cs Guards metadata access when the source file is missing.

Review effort: Balanced

@pavelsavara pavelsavara added area-blazor Includes: Blazor, Razor Components and removed area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares labels Oct 27, 2026
@PureWeen

PureWeen commented Nov 3, 2026

Copy link
Copy Markdown
Member

/review

@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.

Reviewed frozen head a4464fe530d7c421c2dd456dce65315159c4675a against merge base 6e70df47c3a16e5b06d8b610ff95414c212c2bfd and base tip/guidance commit 66e2adb4e0297e445686cb7a70d6c9aa84dcf3af.

One P2 finding: missing manifest assets still use stale fast-path responses for HEAD and matching conditional requests because the new non-cacheable 404 is reached only while sending a body. The fix should perform a fresh file-provider existence check before request precondition/HEAD fast paths and retain the catch for deletion races.

The routed docs/CrossCuttingGuidance.md review completed with gpt-5.6-sol (runtime effort default; runtime-reported model matched). It assessed all in-scope cross-cutting topics; security assessment and worker-side execution were explicitly excluded. No public API, analyzer, trimming/AOT, package, template, or metadata change was present. No material changed area lacked routed guidance.

Existing feedback contained no equivalent actionable finding: the bot review reported no open issues but noted unavailable frozen evidence, the human review was approval-only, and the invocation comment contained only /review. This is deduplication, not endorsement. There were no unresolved candidates.

Coordinator validation used the supplied worktree at the exact frozen SHA. After installing the pinned SDK and targeted restore, a temporary two-case TestServer test warmed the endpoint, deleted the asset, then sent HEAD or GET with the prior ETag. dotnet test ./src/StaticAssets/test/Microsoft.AspNetCore.StaticAssets.Tests.csproj -c Debug --no-restore /p:UseIisNativeAssets=false /p:RunAnalyzers=false --filter FullyQualifiedName~MissingAssetFastPathsReturnNonCacheableNotFound failed 2/2: HEAD observed 200 and conditional GET observed 304 where 404 was expected. The temporary test was removed. An initial run was unavailable before SDK setup; one targeted restore attempt used an incorrect relative project path before the absolute-path restore succeeded. No repository-wide test suite or browser workflow was run.

Limitations: review evidence is tracked Git content only; symlink, submodule, and LFS targets are inert. Feedback posted after bundle preparation was not observable.

Generated by ASP.NET Core Pull Request Review for #70062 · copilot · gpt56 · 132.4 AIC · ⌖ 31.2 AIC · ⊞ 20K
Comment /review to run again

@PureWeen PureWeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One additional issue was validated at the frozen head.

Human-directed and GitHub Copilot-generated.

pavelsavara and others added 2 commits November 3, 2026 14:20
Check current file-provider state before HEAD, precondition, and invalid
range responses, retaining the existing send/catch path for ordinary GETs.
Share non-cacheable missing-file handling with development runtime patching
so retained compressed artifacts cannot hide a deleted original source.

Add 52 regression rows covering cached metadata and source-only deletion.
All new rows failed before the fix; all 124 StaticAssets tests pass.

Co-authored-by: Copilot <[email protected]>
@PureWeen

PureWeen commented Nov 3, 2026

Copy link
Copy Markdown
Member

/review

@PureWeen

PureWeen commented Nov 3, 2026

Copy link
Copy Markdown
Member

Copilot's local review panel found no issues to raise at this commit.

@pavelsavara
pavelsavara enabled auto-merge (squash) November 4, 2026 07:54
@pavelsavara
pavelsavara removed the request for review from oroztocil November 4, 2026 11:01
@pavelsavara
pavelsavara disabled auto-merge November 4, 2026 11:02
@pavelsavara
pavelsavara merged commit 85fbddc into dotnet:main Nov 4, 2026
34 checks passed
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 10%

No docs needed: the PR fixes missing manifest asset handling to return a non-cacheable 404. No public API, configuration or template signals were found.

Documentation surfaces considered

  • Conceptual article: Not required — Bug fix for missing-asset handling; no new public API, option, or documented behavior changes.
  • Migration guidance: Not required — No user action needed when upgrading.
  • Breaking change: Not required — No API removal or established behavior change; it corrects an erroneous empty 200 response.

@pavelsavara

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 4fa9fb22 Deployed Nov 4, 2026 by pavelsavara via conclusion #187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-approved area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants