Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
httpx-ws seems unable to talk to Jupyter labs. Connecting to a wss URL returns a 400 error and connecting to an https URL returns a timeout error, both without any error messages on the server side that I can find. Switch to the websockets library instead, which was already successfully in use by noteburst.
websockets unfortunately doesn't use the underlying httpx AsyncClient, so requires copying some headers from an AsyncClient request to get the authentication information.
Move the creation of the lab session into the JupyterLabSession context manager so that the calling convention is less awkward (no extra await in the middle of the context manager invocation). This code uses an explicit context manager because when using one generated with asynccontextmanager the WebSocket wasn't closed until garbage collection, at which point the AsyncClient was already closed and the lab session couldn't be deleted. This approach allows tighter control over exactly when the lab session is deleted.