Smart proxies can serve incorrect content if remote is nil

Problem:
It seems when a smart proxy doesn’t have a remote set for a repository (eg. the data that should point to the main foreman server), it will serve a different repositories content (I’m assuming the previous repository in the list that does have a remote set). There’s no warning this is happening and could be really bad depending on which repository is being served.

I’ve verified the remote isn’t set as this returns nil when run in the console for the specific repository/smart proxy
smartproxy=SmartProxy::find(4)
Katello::Repository.find(300).backend_service(smartproxy).with_mirror_adapter.fetch_remote

Syncing the repo to the smart proxy fixes the issue
hammer -u -p capsule content synchronize --id 4 --repository-id=300

Expected outcome:
Rather than serve incorrect content, an error and 404 should be returned

Foreman and Proxy versions:
Foreman 3.11.1

Foreman and Proxy plugin versions:
Katello 4.13.0

Distribution and version:
AlmaLinux release 8.10

Other relevant data:
Smart proxies are in remote datacenters
Repositories on the main foreman server and all smart proxies are set to download content “On Demand”

I opened a ticket here Bug #37740: Smart proxies can serve incorrect content if remote is nil - Katello - Foreman but was encouraged to post to the community as well.