Loading a snapshot checks the coins cache against -dbcache only every 120000 coins. A coin can carry a script of up to 10000 bytes. A snapshot file made of such coins can push the cache about 1.2 GB past -dbcache between two checks.
I added a check once the cache has grown by 4 MiB since the last one, and kept the 120000-coin check. Typical coins reach the 4 MiB bound about every 30000 coins. The added cost is negligible. Between checks the cache can still exceed -dbcache by about 4 MiB. I added a case to feature_assumeutxo.py that loads 2000 coins with 10000-byte scripts under -dbcache=4. It fails without the change and passes with it. The coins and validation unit tests pass.
This is one of several PRs from a large audit of Bitcoin Core that I did with the help of LLM tools. The audit produced its evidence all at once, which is why the PRs arrive together. I understand each change fully and will answer review questions myself.