Skip to content

Deprecated kernel_id param in GatewayKernelClient init() - #1603

Open
vincentye38 wants to merge 18 commits into
jupyter-server:mainfrom
vincentye38:main-apple-oss
Open

Deprecated kernel_id param in GatewayKernelClient init()#1603
vincentye38 wants to merge 18 commits into
jupyter-server:mainfrom
vincentye38:main-apple-oss

Conversation

@vincentye38

@vincentye38 vincentye38 commented Feb 19, 2026

Copy link
Copy Markdown
  • Deprecated kernel_id parameter as required parameter from GatewayClient ctor because its supper class's ctor doesn't have this parameter. When a kernel manager try to instantiate an object of it, it doesn't know GatewayClient is the concrete class and It need to pass kernel_id to the ctor. Thus, It fails with the following error message. kernel_id is only for constructing ws_url (gateway websocket url.) Replace kernel_id with ws_url property. So the kernel manager can set ws_url instead of kernel id.
    The kernel_id parameter caused the following exception when the ctor is called by self.kernel_client = self.client(session=self.session) in KernelManager.init
[W 2026-02-18 18:31:50.832 ServerApp] wrote error: "GatewayKernelClient.__init__() missing 1 required positional argument: 'kernel_id'"
    Traceback (most recent call last):
      File "/Users/xiang_ye/github/aiml-jupyter-server/jupyter_server/services/sessions/handlers.py", line 90, in post
        s_model = await sm.create_session(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_server_documents/session_manager.py", line 249, in create_session
        session_model = await super().create_session(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/github/aiml-jupyter-server/jupyter_server/services/sessions/sessionmanager.py", line 286, in create_session
        kernel_id = await self.start_kernel_for_session(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/github/aiml-jupyter-server/jupyter_server/services/sessions/sessionmanager.py", line 359, in start_kernel_for_session
        kernel_id = await self.kernel_manager.start_kernel(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/github/aiml-jupyter-server/jupyter_server/services/kernels/kernelmanager.py", line 233, in _async_start_kernel
        kernel_id = await self.pinned_superclass._async_start_kernel(self, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_client/multikernelmanager.py", line 263, in _async_start_kernel
        km, kernel_name, kernel_id = self.pre_start_kernel(kernel_name, kwargs)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_client/multikernelmanager.py", line 209, in pre_start_kernel
        km = self.kernel_manager_factory(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_client/multikernelmanager.py", line 87, in create_kernel_manager
        km = kernel_manager_ctor(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/nextgen_kernels_api/services/kernels/kernelmanager.py", line 47, in __init__
        self.kernel_client = self.client(session=self.session)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_client/manager.py", line 740, in client
        return super().client(**kwargs)  # type:ignore[return-value]
               ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_client/manager.py", line 277, in client
        return self.client_factory(**kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/jupyter_server_documents/kernel_client.py", line 46, in __init__
        super().__init__(*args, **kwargs)
      File "/Users/xiang_ye/.conda/envs/saturn/lib/python3.11/site-packages/nextgen_kernels_api/services/kernels/client.py", line 87, in __init__
        super().__init__(*args, **kwargs)
    TypeError: GatewayKernelClient.__init__() missing 1 required positional argument: 'kernel_id'
  • Append session_id to the ws_url so the gateway can replay buffered message during the disconnection. The gateway gate the replay messages by session_id.

Comment thread jupyter_server/gateway/managers.py
GatewayClient.instance().kernels_endpoint,
url_escape(self.kernel_id),
"channels",
)

@vincentye38 vincentye38 Feb 19, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note: I proposed to move ws_url initialization to kernel manager, and make ws_url as a property of kernel client. Because kernel manager is responsible to start kernel process, instantiate a kernel client to connect o the process. So it knows information of how to connect to the kernel process.
Kernel manager will set ws_url of kernel client after it creates the kernel client.

@vincentye38 vincentye38 May 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It will be on line 726 instead.

@Zsailer Zsailer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution @vincentye38 ! The reconnect logic is a nice addition. A few things to address before this can merge:

  1. Breaking API change — Removing kernel_id from GatewayKernelClient.__init__() will break downstream consumers. Please keep it as an optional kwarg with a deprecation warning and
    auto-build ws_url from it for backwards compat.
  2. asyncio.run() in _should_reconnect — This will fail inside a running event loop. Needs to be reworked.

Comment thread jupyter_server/gateway/managers.py Outdated
Comment thread jupyter_server/gateway/managers.py Outdated
Comment thread jupyter_server/services/kernels/websocket.py Outdated
@Carreau Carreau added this to the Future milestone May 1, 2026
@Zsailer
Zsailer requested review from kevin-bates and lresende May 12, 2026 16:06
@vincentye38

Copy link
Copy Markdown
Author

@lresende @kevin-bates Any comment and concern for PR?

@vincentye38

vincentye38 commented May 13, 2026

Copy link
Copy Markdown
Author

I am resolving the failed check.

All unit test passed.

Comment thread jupyter_server/services/sessions/handlers.py Outdated
@vincentye38 vincentye38 changed the title Enhance GatewayClient Deprecated kernel_id param in GatewayClient init() May 20, 2026
@vincentye38 vincentye38 changed the title Deprecated kernel_id param in GatewayClient init() Deprecated kernel_id param in GatewayKernelClient init() May 20, 2026
@krassowski

Copy link
Copy Markdown
Collaborator

It looks like there are some conflicts which need to be resolved.

Comment thread jupyter_server/gateway/managers.py Outdated
Comment thread jupyter_server/gateway/managers.py Outdated
Comment thread jupyter_server/gateway/managers.py Outdated
Comment thread jupyter_server/gateway/managers.py Outdated
Comment on lines +733 to +736
@property
def session_id(self):
"""The session id."""
return self.session.session

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the definition of a property necessary? Is that to allow customizing it downstream in subclasses or just for convenience? If the latter, should it be private (prefixed with _)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Subclass can override this property to adapt to what the gateway side uses to key the buffered messages. Currently, Kernel Gateway use session id in the message as key, which is corresponding to self.session.session.

self.response_router: Optional[Thread] = None
self._channels_stopped = False
self._channel_queues = {}
if kernel_id is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The GatewayKernelManager class is still setting this keyword parameter inside of the client method (line 424 in the LHS of the diff).

If it is being deprecated, then we should also update the existing caller in this file to use the new ws_url traitlet instead.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@vincentye38 I suppose the comment above still needs addressing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed in a new commit for GatewayKernelManager in line #425

vincentye38 and others added 2 commits June 3, 2026 09:35
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
…ient

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread jupyter_server/gateway/managers.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants