Jupyter Kernel WebSocket Connection Fails After Initial Success in Cursor

Description:
The Jupyter kernel in Cursor fails to start with a “WebSocket is not defined” error after initially working. This issue occurs specifically in Cursor but works fine in VSCode with the same environment and configuration. The problem affects both Jupyter notebooks (.ipynb files) and dynamic Python files (notebooks) in Cursor.

Steps to Reproduce:

  1. Install or reinstall Cursor
  2. Open either a Python file or .ipynb file in Cursor
  3. Try to run the file using the Jupyter kernel
  4. The first run might work successfully
  5. Subsequent attempts to run the file result in the error

Expected Behavior:
The Jupyter kernel should start and maintain a stable connection, allowing code execution in both Python files and .ipynb notebooks.

Actual Behavior:
After the initial successful run, subsequent attempts to start the kernel fail with the following error: Failed to start the Kernel '.venv_soc (Python 3.10.5)'. View Jupyter log for further details. WebSocket is not defined

Environment Details:

  • Operating System: macOS (darwin 23.3.0, arm64)
  • Cursor Version: 1.96.2
  • Jupyter Extension Version: 2024.11.0
  • Python Extension Version: 2024.12.3
  • Pylance Extension Version: 2024.8.1
  • Python Version: 3.10.5
  • Virtual Environment: .venv_soc

Impact on Usage:
The problem is particularly disruptive because it affects both traditional Jupyter notebooks (.ipynb) and dynamic Python files which forces me to go back to VSCode

Additional Information:

  • The same setup works perfectly in VSCode
  • The issue occurs after the first successful run
  • Reinstalling Cursor temporarily fixes the issue (works once, then fails again)
  • The error logs show that the kernel process dies unexpectedly with “ExitCode: undefined”
  • The WebSocket connection fails to establish after the initial success

Troubleshooting Attempts:

  1. Cleaned up Jupyter runtime files
  2. Reinstalled kernel specs
  3. Verified Jupyter and ipykernel installations
  4. Tried different Python files and notebooks
  5. Restarted Cursor multiple times

The issue appears to be related to how Cursor manages WebSocket connections for the Jupyter kernel, as the same environment and configuration work without issues in VSCode.

Here is the Jupyter Output log: jupyter_output_log.txt (10.7 KB)