I ended up trying an aggressive approach and deleted ~/Library/Application Support/Cursor. This did solve the problem, but does not explain why it happened in the first place and how to avoid it happening again.
Edit: The same problem as returned, within the space of 2 hours.
In case this is of use to anyone, I have found this issue might be related to using Jupyter notebooks. The error seems to consistently happen after changing to another .ipynb tab. Strangely, the problem can be fixed by switching to a tab with a different file format such as .py. Switching between .ipynb files then seems to work for a while.