Skip to content

fix: fix cache analysis not rendering when edge cache miss occurs #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 5, 2025

This PR fixes an issue where sometimes no cache analysis would be rendered at all, causing the UI to fall back to displaying raw headers instead of a proper cache analysis.

Problem

The issue occurred when a request had the following characteristics:

  • Cache status showed a miss (e.g., "Netlify Edge"; fwd=miss)
  • No function-related headers were present (Debug-X-NF-Function-Type, Debug-X-NF-Edge-Functions)
  • CDN was involved (indicated by Debug-X-BB-Host-Id header)

In this scenario, the getServedBySource function would throw an error instead of handling this valid case gracefully.

Root Cause

The getServedBySource function was missing a fallback case for when:

  • No cache hits were found (all cache entries had hit: false)
  • No function headers were present
  • But CDN was still involved in serving the request

Solution

Added a fallback in getServedBySource that checks for the presence of Debug-X-BB-Host-Id header when no cache hits or function headers are found. This header indicates CDN involvement, so the CDN served the request (likely a cache miss that was forwarded to origin).

// If no cache hits and no function headers, but CDN was involved (indicated by Debug-X-BB-Host-Id),
// then the CDN served the request (likely a cache miss that was forwarded to origin)
if (cacheHeaders.has('Debug-X-BB-Host-Id'))
  return ServedBySource.CDN

Testing

  • Added comprehensive test case reproducing the exact issue scenario with the provided headers
  • Added unit test for the new fallback logic in getServedBy
  • All existing tests continue to pass (100 tests total)
  • Verified with the exact headers from the issue report

Impact

Users will no longer encounter the "raw headers only" display when cache misses occur without function headers. The cache inspector will properly analyze and display cache information in all valid scenarios.

Fixes #91.


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

@Copilot Copilot AI changed the title [WIP] Sometimes no cache analysis is rendered at all? Fix cache analysis not rendering when cache miss occurs without function headers Jul 5, 2025
@Copilot Copilot AI requested a review from serhalp July 5, 2025 00:35
Copilot finished work on behalf of serhalp July 5, 2025 00:35
@serhalp serhalp changed the title Fix cache analysis not rendering when cache miss occurs without function headers fix: fix cache analysis not rendering when edge cache miss occurs Jul 5, 2025
Copy link
Owner

@serhalp serhalp left a comment

Choose a reason for hiding this comment

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

this project uses pnpm. delete the lockfile.

Copy link
Contributor Author

Copilot AI commented Jul 5, 2025

this project uses pnpm. delete the lockfile.

Done! Deleted the package-lock.json file since the project uses pnpm. (fb52dda)

@Copilot Copilot AI requested a review from serhalp July 5, 2025 02:24
Copilot finished work on behalf of serhalp July 5, 2025 02:24
@Copilot Copilot AI requested a review from serhalp July 5, 2025 03:01
Copilot finished work on behalf of serhalp July 5, 2025 03:01
@serhalp serhalp marked this pull request as ready for review July 5, 2025 14:20
Comment on lines +163 to +173
const cacheStatus: ParsedCacheStatusEntry[] = [
{
cacheName: 'Netlify Edge',
parameters: {
hit: false,
fwd: 'miss',
stored: false,
collapsed: false,
},
},
]
Copy link
Owner

Choose a reason for hiding this comment

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

this one is realistic, but while we're refactoring the logic let's update the fixture in the other tests to be realistic. for example the durable cache one should have a Netlify Edge miss, the function one should have Netlify Edge and Durable Cache misses, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated test fixtures to be realistic! The durable cache test now includes a Netlify Edge miss, and the function/edge function tests include both Netlify Edge and Netlify Durable misses. (fc87dc2)

Comment on lines 56 to 59
// Check for the specific case of a single Netlify Edge miss - this handles the weird
// Netlify Cache-Status behavior where a miss on the CDN edge means the request was
// forwarded to CDN origin. According to Netlify's cache behavior, when there's a miss
// on "Netlify Edge", the request gets forwarded to the CDN origin to fetch the static asset.
Copy link
Owner

Choose a reason for hiding this comment

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

there's one detail missing here. this only applies when there's a miss on the edge node, but a hit at the CDN origin. This can only be detected by the presence of a cache status entry for Netlify Edge that is a miss and no entries at all for subsequent caches. There's a miss on the edge node, but a hit at the CDN origin. This can only be detected by the presence of a cache status entry for Netlify Edge that is a miss and no entries at all for subsequent caches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the CdnOrigin detection logic to properly handle the case you described. Now checks for Netlify Edge miss AND no subsequent cache hits (not just single entry). This correctly detects when there's a miss on edge but hit at CDN origin. (fc87dc2)

@Copilot Copilot AI requested a review from serhalp July 5, 2025 14:29
Copilot finished work on behalf of serhalp July 5, 2025 14:29
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.

Sometimes no cache analysis is rendered at all?
2 participants