I had the same issue where variable colours/pylance would seem to just stop working randomly.
I found the issue was that pyright was indexing too many files (working in many repos at the same time, and some other podman related folders). I included a pyrightconfig.json file at the root of my workspace and excluded the paths with loads of files that I wasn't using at the time and it seemed to fix the issue straight away.
pyright info: https://github.com/microsoft/pyright/blob/main/docs/configuration.md