Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylance crashing on Jupyter Notebook Cell Deletion #4685

Closed
justinmahendra opened this issue Aug 3, 2023 · 73 comments
Closed

Pylance crashing on Jupyter Notebook Cell Deletion #4685

justinmahendra opened this issue Aug 3, 2023 · 73 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@justinmahendra
Copy link

justinmahendra commented Aug 3, 2023

Environment data

  • Language Server version: v2023.8.10
  • OS and version: Windows 10 22H2 OS Build 22621.1992
  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.4

Repro Steps

  1. Add 2 new empty cells in Jupyter Notebook or Deleting any other cells in between cells. Deleting one would not instantly crash, but deleting another one will
  2. Proceed to delete the first created cell, then delete the second one (top to bottom). Deleting from bottom to top in order does not crash the server
  3. Crashed

Expected behavior

  1. Not crashing. Issue has been posted before in another report Crash on notebook reopen after cell reordering #4077, but this crash in reopen, not crashing the linting server

Logs

Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths:
    at _0x598038 (c:\Users\leejieun\.vscode\extensions\ms-python.vscode-pylance-2023.8.11\dist\server.bundle.js:1:897913)
    at c:\Users\leejieun\.vscode\extensions\ms-python.vscode-pylance-2023.8.11\dist\server.bundle.js:1:905158
    at _0x547bdc.<computed> (c:\Users\leejieun\.vscode\extensions\ms-python.vscode-pylance-2023.8.11\dist\server.bundle.js:1:905190)
    at _0x3822ba._onDidChangeNotebookDocumentAsync (c:\Users\leejieun\.vscode\extensions\ms-python.vscode-pylance-2023.8.11\dist\server.bundle.js:1:884105)
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 3, 2023
@justinmahendra
Copy link
Author

Downgrading to v2023.7.40 seems to have solved the issue. Bug maybe introduced in new version?

@Baumfried
Copy link

Can confirm, 2023.8.10 seems completely broken for notebooks.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 3, 2023

Can somebody post a gif of it happening? I cannot seem to reproduce the problem:

deletecells

@justinmahendra
Copy link
Author

bug_recording
Here's whats happening in my computer.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 3, 2023

Did you reorder any cells or put anything in the notebook before adding the 3? extra cells at the bottom? No matter how many cells or where I put them, I can't get it to crash. But maybe reordering first is necessary.

@justinmahendra
Copy link
Author

Freshly opened vscode using reload window, then added the cells. Just happen to me on this particular version. I can try using venv to follow your gif there. Might followup in 12 hours

@rchiodo
Copy link
Contributor

rchiodo commented Aug 3, 2023

Hmm, maybe it has to do with deleting the cells while pylance is loading. At least in your situation it looked like pylance hadn't finished starting when you were deleting.

@justinmahendra
Copy link
Author

I think i tried waiting a few seconds before deleting another cell. Still broke the server though. But deleting from bottom to top in order seems fine.

@Xavi422
Copy link

Xavi422 commented Aug 5, 2023

Did you reorder any cells or put anything in the notebook before adding the 3? extra cells at the bottom? No matter how many cells or where I put them, I can't get it to crash. But maybe reordering first is necessary.

I'm getting a similar issue when deleting cells in Jupyter notebook. See my post here for a video:

microsoft/vscode#189645 (comment)

I get the same error "Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths"

@Xavi422
Copy link

Xavi422 commented Aug 5, 2023

Note: Downgrading to v2023.7.40 doesn't solve the issue for me.

@zachmeador
Copy link

zachmeador commented Aug 8, 2023

Yep, same here. And downgrading won't help, since I've been having this issue for months. Glad to see that others are having it too.

I'm not sure if "crashing" is the right term, since it seems to continue to log to the output tab. But the functionality definitely dies, and won't recover on its own.

Related issues:

Some of my details:

  • Pylance version: 2023.8.10
  • Windows version: Server 2019 Standard, 10.0.17763
  • Miniconda, Python 3.11.3

Settings are mostly default, with these exceptions:

"python.analysis.completeFunctionParens": true,
"python.analysis.logLevel": "Information",
"python.analysis.typeCheckingMode": "basic"

What I see, which seems the same as OP:

2023-08-08 09:41:01.092 [info] Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths d:\xxx\eda.ipynb:pylance-notebook-cell:Y320sZmlsZQ==.py
    at _0x301f2e (c:\yyy\.vscode\extensions\ms-python.vscode-pylance-2023.8.10\dist\server.bundle.js:1:997269)
    at c:\yyy\.vscode\extensions\ms-python.vscode-pylance-2023.8.10\dist\server.bundle.js:1:1004473
    at _0x69059c.<computed> (c:\yyy\.vscode\extensions\ms-python.vscode-pylance-2023.8.10\dist\server.bundle.js:1:1004505)
    at _0x27861c._onDidChangeNotebookDocumentAsync (c:\yyy\.vscode\extensions\ms-python.vscode-pylance-2023.8.10\dist\server.bundle.js:1:983463)

And, just FYI, the pre-release version of Pylance (2023.8.11) has exactly the same issue.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

We really need a way to repro the problem. Nobody in house can seem to reproduce the issue. Does it happen no matter the notebook?

@zachmeador
Copy link

zachmeador commented Aug 8, 2023

I think the cleanest reproduction steps, which works for me, is something like this:

  1. Create a notebook file, let it connect to a kernel.
  2. Make a cell, with some code thing = 'thing', run it.
  3. Make a cell below that, add thing, run it, and hovering over it with your cursor should show the linting of the object.
  4. Make a new cell, anywhere, run it, and then delete it.
  5. Pylance should now be broken, and will log the above-mentioned exception. Linting no longer works.

Edit: Argh, now this won't replicate exactly this way. I ended up adding a cell at the top importing a package, like import pandas as pd, created and deleted some cells, and eventually it broke again. Strange.

Edit2: I keep attempting to find the most succinct way to replicate. And for some reason, creating a cell at the top and then deleting it seems to more consistently break Pylance? But, I know from my own work with large notebooks, it will consistently break without me deleting the top cell, and eventually breaks after deleting any cell. So, maybe some sort of effect here from the number of cells, amount of code, or session runtime of a notebook? Apologies, this is the best I can do I think - I don't understand how Pylance works, or how it works with Jupyter :-).

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

Yeah I still can't repro. Doesn't matter where I create a cell.

@Xavi422
Copy link

Xavi422 commented Aug 8, 2023

Yeah I still can't repro. Doesn't matter where I create a cell.

Can you try this?

I used D+D to delete the middle cell and Z to undo the delete

Untitled.video.mp4

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

Nope that works fine. Deleting the cell, moving it around, doesn't matter.

The code that's failing is detecting that we understand all of the cells in the notebook (they get turned into files that reference each other). When the error occurs, one of the cells is set to undefined for some reason.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

Can you try an experimental setting?

 "python.analysis.enableSyncServer": true

This changes how we handle LSP messages. That setting forces us to handle one message at a time. The bug here might be we're getting a delete for a notebook cell while we get an edit for a cell and the delete might be deleting a cell we were editing.

Sync server mode should make those two messages happen synchronously.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

Oh, should have said that new mode requires restarting VS code.

@thierry-bm
Copy link

Not helping on my side. The crash message looks slightly different though :

2023-08-08 15:17:38.324 [info] [Error - 15:17:38] Notification handler 'notebookDocument/didChange' failed with message: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths c:\xxx\zzz.ipynb:pylance-notebook-cell:X53sZmlsZQ==.py

@zachmeador
Copy link

That did make some progress. Autocomplete keeps working now, but objects are underlined as if they don't exist (reportUndefinedVariable). And then I'm getting the same log message as tierry-bm.

2023-08-08 15:57:35.015 [info] [Error - 3:57:35 PM] Notification handler 'notebookDocument/didChange' failed with message: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths c:\zzz\debug.ipynb:pylance-notebook-cell:W0sZmlsZQ==.py

image

image

@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

That probably means the 'crash' for the async server is not crashing the sync server. But the data is still messed up. Meaning it still repros.

@rchiodo rchiodo changed the title Lint Server crashing on Jupyter Notebook Cell Deletion Pylance crashing on Jupyter Notebook Cell Deletion Aug 8, 2023
@rchiodo
Copy link
Contributor

rchiodo commented Aug 8, 2023

Just to double check, everyone hitting this is using either the latest VS code insiders or VS code stable?

I tried with stable: 1.81
I tried with insiders: 1.82

Thought maybe VS code changed notebook sync messages.

@zachmeador
Copy link

I’m using stable, but tomorrow I can also try with insiders if that would be useful.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 9, 2023

I’m using stable, but tomorrow I can also try with insiders if that would be useful.

No, I don't think that matters. I really doubt VS code changed these messages at all. There's some race condition we have in Pylance.

@JoHof
Copy link

JoHof commented Aug 10, 2023

Using stable 1.81, ms-python.vscode-pylance-2023.8.20 on linux machine

pylance keeps crashing with mentioned error message. remote and local. Can reproduce by deleting two cells consecutively.

@starball5
Copy link

starball5 commented Aug 10, 2023

Related on Stack Overflow: Pylance in VS Code crashes when adding or deleting cells in a Jupyter notebook. I'm maintaining an answer post with what's been notably written here.

Apparently some need to downgrade further to 2023.7.30 (source).

@octave-ati
Copy link

octave-ati commented Aug 30, 2023

So since we are Wednesday can we get any confirmation that the pre release build that will be released today fixes this issue?

@aiden4977
Copy link

aiden4977 commented Aug 31, 2023

Problem was fixed after installing Pyright v1.1.325. I will update if it crashed again.

microsoft/pyright#5854


Update: well. it crashed again.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 31, 2023

There was an additional fix that isn't in Pyright. it's only in pylance at the moment.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 31, 2023

When we ship the next Pylance prerelease, the bug should be fixed. That would be 2023.8.51

@debonte
Copy link
Contributor

debonte commented Aug 31, 2023

This issue has been fixed in prerelease version 2023.8.51, which we've just released. You can find the changelog here: CHANGELOG.md

@debonte debonte closed this as completed Aug 31, 2023
@rchiodo
Copy link
Contributor

rchiodo commented Aug 31, 2023

The whole python linting/autocomplete experience is broken so regularly that it has become embarrassing for me to recommend VS Code to new users. It is always "it should be working today, lets see".

When it is working it's great. When it's not working its actually pretty hard to tell what might be wrong. This kind of nonsense can be triggered by a mistake as simple as setting up your project in a network drive, or a file path on a UNC path, or if file paths are too long. I've tried all the usual fixes but for the last week or so it has been pretty stubbornly broken.

@thehappycheese do you still have a UNC issue? That's likely this problem: #4357. Which I believe was related to how VS code prevented access to UNC drives. Can you log an issue whatever the problem may be?

@jzazo
Copy link

jzazo commented Sep 1, 2023

I am on v2023.8.51 of pylance and this does not seem to be fixed. I still get white text pretty often on imports. Need to refresh window.

@debonte
Copy link
Contributor

debonte commented Sep 1, 2023

I am on v2023.8.51 of pylance and this does not seem to be fixed. I still get white text pretty often on imports.

@jzazo, after that happens, if you add/delete/reorder a cell, does Pylance crash with an error like the one below? If not, it's a different issue.

2023-08-25 20:20:22.473 [info] Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths c:\temp\temp\4685repro_2\test.ipynb:pylance-notebook-cell:W0sZmlsZQ==.py
    at _0x35bbe7 (c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1025282)
    at c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1032550
    at _0x114e49.<computed> (c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1032582)
    at _0x4600bc._onDidChangeNotebookDocumentAsync (c:\Users\erikd\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.41\dist\server.bundle.js:1:1010710)

@raaaaaymond
Copy link

Can confirm that upgrading to Pylance 2023.8.51 worked for me. For now. Thank you all for working on this.

@jzazo
Copy link

jzazo commented Sep 1, 2023

I am not using jupyter or interpreted python, I am on a normal python module, and pylance stops working. Yeah, it may happen when I reorder code, is that possible?

@debonte
Copy link
Contributor

debonte commented Sep 1, 2023

I am not using jupyter or interpreted python, I am on a normal python module, and pylance stops working. Yeah, it may happen when I reorder code, is that possible?

@jzazo, the identifying behavior of this issue is the crash. The fact that semantic highlighting stops working just before the crash is a symptom of the underlying problem, but there are many reasons that semantic highlighting could stop working. It's impossible for this crash to occur without opening a notebook. The code where the "Chained file path x doesn't match cellFilePaths" check is performed is only executed when VS Code tells Pylance that a notebook has been opened or modified.

So what you're seeing is a different issue. Can you please open a new issue?

The only existing issue I found that looked similar is #4513, but I don't think there's enough detail there yet for us to know if it's the same as your issue. So open a new one and we can always resolve it as a duplicate after investigation if appropriate.

@jzazo
Copy link

jzazo commented Sep 1, 2023

Thanks, I will keep monitoring and report back if I observe it crashes.

@debonte
Copy link
Contributor

debonte commented Sep 1, 2023

Thanks, I will keep monitoring and report back if I observe it crashes.

@jzazo, sorry if I wasn't clear. When the semantic highlighting (colored text) changes to white, which of the following options is true for you? Note that having a notebook "open" does not necessarily mean that it is the active tab that you are typing in. Simply having it open as another tab may be sufficient to cause this issue.

No notebooks are open

If you don't have any notebooks open when you see the semantic highlighting (colored text) change to white, then what you are seeing is unrelated to this issue. File a new issue please.

1+ notebook is open and adding/deleting/reordering cell does not cause this crash

If you do have a notebook open (as an open tab, but not necessarily the active tab) when you see the semantic highlighting (colored text) change to white (in any file), then when that color change occurs, please switch to the open notebook and try adding, deleting, or reordering a cell there. If that doesn't cause the crash I mentioned above, then what you are seeing is unrelated to this issue. File a new issue please.

1+ notebook is open and adding/deleting/reordering cell causes this crash

If you see the coloration disappear with a notebook open, and adding/deleting/reordering a cell causes the crash I mentioned above, and you are using 2023.8.51, then what you're seeing is related to this issue and we'll need more details on your project and what actions you are taking before the problem occurs.

@jzazo
Copy link

jzazo commented Sep 1, 2023

Thanks @debonte. Yeah, I don't have any notebooks open, so it is an unrelated issue. I will keep monitoring, it doesn't happen as frequently as before.

@FlorinAndrei
Copy link

I have upgraded today to the 2023.8.51 pre-release version. I have worked all day on a large notebook (dozens of MB file size, due to lots of graphics). Remote session into a Linux machine via the SSH extension.

Syntax highlighting and autocompletion worked flawlessly all day (if a bit slow due to the huge notebook size). No crashes (that I know of).

With recent previous versions, I used to experience a loss of syntax highlighting and autocompletion after a while, that required closing/reopening the notebook. I have never seen any crashes with previous versions (may have occurred, I just never saw them).

I believe the 2023.8.51 pre-release fixes the problems I had.

Thanks @debonte

@KokollariIlir
Copy link

I am on v2023.11.11 and this issue is still persisting

2023-11-06 10:53:41.635 [info] Error: Debug Failure. Cell path not found for cell vscode-notebook-cell:/c%3A/Users/ilirk/projects/adhoc/movement.ipynb#W6sZmlsZQ%3D%3D
    at _0x5e8922.getNotebookCellPath (c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\server.bundle.js:1:261668)
    at _0x8f195a.decodeTextDocumentUri (c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\server.bundle.js:1:230980)
    at _0x45a7e7.onDidCloseTextDocument (c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\server.bundle.js:1:901599)
    at c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\pyright.bundle.js:1:1144202
    at c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\vendor.bundle.js:2:1234062
    at oe (c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\vendor.bundle.js:2:1234284)
    at c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\vendor.bundle.js:2:1230224
    at Immediate.<anonymous> (c:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist\vendor.bundle.js:2:1230244)
    at processImmediate (node:internal/timers:476:21)

2023-11-06 10:53:41.819 [info] [Error - 10:53:41 AM] Server process exited with code 1.
2023-11-06 10:53:41.826 [info] [Info  - 10:53:41 AM] Connection to server got closed. Server will restart.
2023-11-06 10:53:41.827 [info] true
2023-11-06 10:53:42.959 [info] [Info  - 10:53:42 AM] (11624) Pylance language server 2023.11.11 (pyright 64c9c3ff) starting
2023-11-06 10:53:42.959 [info] [Info  - 10:53:42 AM] (11624) Server root directory: C:\Users\ilirk\.vscode\extensions\ms-python.vscode-pylance-2023.11.11\dist
2023-11-06 10:53:42.960 [info] [Error - 10:53:42 AM] Server initialization failed.
2023-11-06 10:53:42.960 [info]   Message: Request initialize failed with message: You may install and use any number of copies of the software only with Microsoft Visual Studio, Visual Studio for Mac, Visual Studio Code, Azure DevOps, Team Foundation Server, and successor Microsoft products and services (collectively, the “Visual Studio Products and Services”) to develop and test your applications. The software is licensed, not sold. This agreement only gives you some rights to use the software. Microsoft reserves all other rights. You may not: work around any technical limitations in the software that only allow you to use it in certain ways; reverse engineer, decompile or disassemble the software, or otherwise attempt to derive the source code for the software, except and to the extent required by third party licensing terms governing use of certain open source components that may be included in the software; remove, minimize, block, or modify any notices of Microsoft or its suppliers in the software; use the software in any way that is against the law or to create or propagate malware; or share, publish, distribute, or lease the software (except for any distributable code, subject to the terms above), provide the software as a stand-alone offering for others to use, or transfer the software or this agreement to any third party.

----- [29023443aa0953887e4bf9867965fbbfac2b37d3fe3788884a690a80741a1b19]

@NikitiusIvanov
Copy link

The same problem in my jupyter notebook. I used plotly lib to visualization, and after i deleted cell with plot pylance server was crashed

my version: 1.85.0-insider (user setup)
Commit: 9aacac648821b5c9c1a7192ac9d44c50af6fe241
Date: 2023-11-06T05:34:22.485Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045

@rchiodo
Copy link
Contributor

rchiodo commented Nov 6, 2023

The deleting of the cell is actually tracked in a separate issue. This one: #5071. The fix for that should be in the next prerelease version when we ship it. Otherwise I'd recommend switching to stable.

@LicoriceLin
Copy link

This issue happens again for my Pylance in version 2023.8.50

@rchiodo
Copy link
Contributor

rchiodo commented Mar 1, 2024

This issue happens again for my Pylance in version 2023.8.50

@LicoriceLin, If that's your version, you should upgrade. This bug has been fixed since 2023.11.12

@LicoriceLin
Copy link

This issue happens again for my Pylance in version 2023.8.50

@LicoriceLin, If that's your version, you should upgrade. This bug has been fixed since 2023.11.12

Oh thanks!
I just forgot to turn on auto-update in my new dev-environment.

@LicoriceLin
Copy link

This issue happens again for my Pylance in version 2023.8.50

@LicoriceLin, If that's your version, you should upgrade. This bug has been fixed since 2023.11.12

Oh I think it's a new issue as update doesn't fix it. And my error log goes like " Received change text document command for closed file":
image

@LicoriceLin
Copy link

This issue happens again for my Pylance in version 2023.8.50

@LicoriceLin, If that's your version, you should upgrade. This bug has been fixed since 2023.11.12

Oh I think it's a new issue as update doesn't fix it. And my error log goes like " Received change text document command for closed file": image

In my situation any change to jupyter codes, even if it's in the existent blocks, will make pylance crash

@rchiodo
Copy link
Contributor

rchiodo commented Mar 1, 2024

That sounds like this problem then:
#5543

Which looks to be an issue with VS code:
microsoft/vscode#206487

If you downgrade VS code to 1.86.2, the problem should go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests