Skip to content

Conversation

@knaresh
Copy link
Collaborator

@knaresh knaresh commented May 14, 2025

I have been trying to fix issues that I was encountering when I am integrating kernel manager with new YRoom. These are not correct fixes but shared a draft to discuss

  • As mentioned above, roomid is not in expected format. YRoom expects it to be of format "room_id := "{file_type}:{file_format}:{file_id}" eg: json:notebeook:d8ae4475-cd89-484a-a044-2f6b56a0bf8b
  • kernel manager needs last_activity without which kernel starts fail. I did not see this before
  • After I fix all above, I am running into issue where "TypeError: argument 'chunk': 'NotebookNode' object cannot be converted to 'PyString'"

Copy link
Collaborator

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knaresh Thank you for working on these fixes! Left some comments below.

self._ydoc = pycrdt.Doc()
self._awareness = pycrdt.Awareness(ydoc=self._ydoc)
_, file_type, _ = self.room_id.split(":")
file_type, _, _ = self.room_id.split(":")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The room ID takes the format {file_format}:{file_type}:{file_id}, so the existing code here is correct. This confusion is my fault; the docstring on the room_id attribute is incorrect.

Here's the reference code in jupyter_collaboration: https://github.com/jupyterlab/jupyter-collaboration/blob/b9ccca66f30fbc4d5cd10eeec32ab5ca83f25f91/packages/docprovider/src/yprovider.ts#L107

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, the docstring in yroom.py that reads:

"room_id := "{file_type}:{file_format}:{file_id}"

should be rewritten as:

"room_id := "{file_format}:{file_type}:{file_id}"

# formats & file types.
room_id: str
file_format: Literal["text", "base64"]
file_format: Literal["text", "base64", "json"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of available file formats is determined by the ContentsManager. I don't think json is an accepted file format, based on the docstring here: https://github.com/jupyter-server/jupyter_server/blob/4ee6e1ddc058f87b2c5699cd6b9caf780a013044/jupyter_server/services/contents/filemanager.py#L421-L426

@Zsailer can you help confirm?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, Naresh's changes here look correct. Here is the room ID I get when I try to open a notebook:

Initializing room 'json:notebook:c3367595-c0ad-4946-a89b-abe0419cc4fa'.

Based on this, it seems format can also be 'json'.

try:
assert self.jupyter_ydoc
path = self.get_path()
self.log.info(f"Saving content for room ID '{self.room_id}'. {path}. {self.file_format} {self.file_type}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will log every single time a save is processed. I recommend removing this / changing it to a debug log to prevent a flood of log messages by default.

Comment on lines +46 to +49
def build_notebook_room_id(self, file_id, file_type) -> str:
# TOOD: extract/how to construct file format?
return f"{file_type}:notebook:{file_id}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The notebook itself is the file type. The first component should be the file format, which should be json for notebooks. It seems the variables should be renamed accordingly:

Suggested change
def build_notebook_room_id(self, file_id, file_type) -> str:
# TOOD: extract/how to construct file format?
return f"{file_type}:notebook:{file_id}"
def build_notebook_room_id(self, file_id, file_format: str | None = 'json') -> str:
# TOOD: extract/how to construct file format?
return f"{file_format}:notebook:{file_id}"

@dlqqq
Copy link
Collaborator

dlqqq commented May 22, 2025

@Zsailer @knaresh Can this PR be closed? I think we fixed these issues.

@knaresh knaresh closed this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants