Very Occasional Wrong Page Displayed on URLs utiziling Worker Script

We’ve started having a really strange, albeit fairly rare issue (seems to occur about once per week) where a client’s site is displaying a page 100% correctly, but at the wrong URL. Here’s what we’ve noticed:

  1. A user will visit /page-a but is served content for /page-b.
  2. It is highly infrequent – we’ll have a few customers report it a couple of times per week and when they do, most others are seeing the correct page (guessing it’s only getting cached incorrectly on a few nodes).
  3. From what we have observed, it is only pages that utilize a particular worker script, which I have included below. Pages seem to “swap” with each other using the worker script. This is what tips my suspicion to something going on on CF vs something at the origin.
  4. We get quite a bit of traffic to our site and, without changing anything on the origin, this started in early October 2021.

This worker script really just serves three of our highest traffic pages and is solely in place to reconcile ad traffic so that /page-a?gtm=blahblahblah is keyed in the cache to /page-a I have disabled the worker scripts below, for now, to ensure that the behavior ceases.

If anyone can see anything in the worker script below that may cause that kind of behavior, I’d appreciate it.

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event))
});

const someOtherHostname = "www.oursite.com";

async function handleRequest(event) {
  const request = event.request;

  // Cache Object
  const cache = caches.default;

  let response;
  
  //If the request is a POST request, we should make the cache 
  // Dynamic and return the request. 
  if(request.method.toUpperCase() === 'POST') {
      // Always pull from the origin. 
      response = await fetch(request);

      // Must use Response constructor to inherit all of response's fields
      response = new Response(response.body, response);

     // No caching.  
      response.headers.set("CF-Worker", "Query_POST");
      response.headers.set("Cache-Control", "max-age=0, no-store");

      return response;
  }

  // URL Requested
  const cacheUrl = new URL(request.url);

  // Map to Our Site
  cacheUrl.hostname = someOtherHostname;

  // Get the URL without the Query String
  constUrlWithoutQueryString = `${cacheUrl.protocol}//${cacheUrl.hostname}${cacheUrl.pathname}`;

  // Get this request from this zone's cache 
  response = await cache.match(constUrlWithoutQueryString);

  if (!response) {    

    //If not in cache, get it from origin
    response = await fetch(request);

    // Must use Response constructor to inherit all of response's fields
    response = new Response(response.body, response);

    response.headers.set("CF-Worker", `Query_${request.method}`);

    //If a GET Request; store it. 
    if(request.method.toUpperCase() === 'GET') {
      // Store the fetched response as cacheKey
      // Use waitUntil so computational expensive tasks don't delay the response
      event.waitUntil(cache.put(constUrlWithoutQueryString, response.clone())); 
    }

  }  

  return response;
}