-
Notifications
You must be signed in to change notification settings - Fork 134
Description
I am encountering a persistent issue where the Jupyter Kernel Gateway appears to send input_request
messages with a session
ID that is different from the session
ID used in the initial execute_request
. This inconsistency prevents the client from correctly replying to the input prompt, leading the kernel to hang in a "busy" state indefinitely.
Steps to Reproduce:
- Client Setup: A web-based IDE (HTML/JavaScript) establishes a WebSocket connection to Jupyter Kernel Gateway.
- The client successfully creates a new kernel via
POST /api/kernels
and receives akernelId
(e.g.,8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
). - The client connects to the kernel's channels WebSocket using this
kernelId
.
- The client successfully creates a new kernel via
- Code Execution: The client sends an
execute_request
message with itsheader.session
set to the establishedkernelId
(e.g.,8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
).- Example Code Executed:
print("Part 1: This output works.") my_input = input("Enter something: ") print(f"Part 2: You entered: {my_input}") 2 + 2
- Example Code Executed:
- Inconsistent
input_request
(Server-side issue):- The Kernel Gateway processes the
execute_request
associated withsession: 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
. - However, when the
input()
function is encountered, the Kernel Gateway sends aninput_request
message (and other subsequent messages likestatus
,stream
) to the client with a DIFFERENTheader.session
ID (e.g.,c06b037c-7f03eeb634ab6e033f8bb7d0
).
- The Kernel Gateway processes the
- Client Reply Attempt:
- The client correctly receives this
input_request
and stores itsheader
asparent_header
. - To reply, the client crafts an
input_reply
message:header.session
is forced to be the client's originalkernelId
(e.g.,8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
) in an attempt to work around the inconsistency.parent_header
is set to theheader
of the receivedinput_request
(thus,parent_header.session
isc06b037c-7f03eeb634ab6e033f8bb7d0
).
- The client correctly receives this
- Kernel Hangs: Despite the
input_reply
being sent, the kernel remains in abusy
state, and the execution does not proceed past theinput()
call. This indicates that Kernel Gateway is not correctly associating theinput_reply
with the pendinginput_request
.
Expected Behavior:
The session
ID in messages sent by Kernel Gateway (e.g., input_request
, status
, stream
) should consistently match the session
ID of the execute_request
that initiated the execution, or the kernelId
of the WebSocket connection. The input_reply
should then be processed correctly, allowing the kernel execution to complete.
Observed Behavior (with relevant log snippets):
Kernel Gateway Logs:
[19:08:06] [KernelGatewayApp] WARNING: No channel specified, assuming shell: {'header': {'msg_id': '0c3f0539-b9f4-4bf4-92f2-93d94e162abd', 'session': '8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e', 'date': '2025-07-31T19:08:06.673Z', 'msg_type': 'execute_request', 'version': '5.3'}, 'parent_header': {}, 'metadata': {}, 'content': {'code': 'print("Part 1: This output works.")\nmy_input = input("Enter something: ")\nprint(f"Part 2: You entered: {my_input}")\n2 + 2', 'silent': False, 'store_history': True, 'user_expressions': {}, 'allow_stdin': True, 'stop_on_error': True}, 'buffers': []}
[19:08:06] [KernelGatewayApp] DEBUG: activity on 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e: status (busy)
# ... (other messages from KG, e.g., stream, input_request, all with header.session: c06b037c-7f03eeb634ab6e033f8bb7d0) ...
[19:08:09] [KernelGatewayApp] WARNING: No channel specified, assuming shell: {'header': {'msg_id': '7d9b49dd-74bc-4c0d-a551-ab6f64b74d61', 'session': '8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e', 'date': '2025-07-31T19:08:09.388Z', 'msg_type': 'input_reply', 'version': '5.3'}, 'parent_header': {'msg_id': 'c06b037c-7f03eeb634ab6e033f8bb7d0_3367_13', 'msg_type': 'input_request', 'username': 'username', 'session': 'c06b037c-7f03eeb634ab6e033f8bb7d0', 'date': '2025-07-31T19:08:06.947924Z', 'version': '5.3'}, 'metadata': {}, 'content': {'value': 'Python', 'status': 'ok'}, 'buffers': []}
Client-side Browser Console Logs:
Ядро создано. Новый kernelId: 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
python-4.html:796 Веб-сокет подключен к ядру: 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
python-4.html:1052 Отправлено сообщение execute_request: 0c3f0539-b9f4-4bf4-92f2-93d94e162abd для session: 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
python-4.html:803 [WS_MESSAGE] Type: status, Session: c06b037c-7f03eeb634ab6e033f8bb7d0, KernelId (client's): 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
python-4.html:803 [WS_MESSAGE] Type: input_request, Session: c06b037c-7f03eeb634ab6e033f8bb7d0, KernelId (client's): 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
python-4.html:904 Получен input_request. currentParentHeader установлен: {msg_id: 'c06b037c-7f03eeb634ab6e033f8bb7d0_3367_13', msg_type: 'input_request', username: 'username', session: 'c06b037c-7f03eeb634ab6e033f8bb7d0', date: '2025-07-31T19:08:06.947924Z', …}
python-4.html:733 Отправлено сообщение input_reply: 7d9b49dd-74bc-4c0d-a551-ab6f64b74d61 для session (принудительно): 8ccfcfaa-fb1e-4690-a7ac-2a6e5a17ea9e
Environment:
- Jupyter Kernel Gateway Version: (Please specify your Kernel Gateway version, e.g., output of
jupyter kernelgateway --version
) - Client: Custom HTML/JavaScript based IDE using WebSocket for Jupyter Protocol communication.
- Operating System: (e.g., Linux, Windows, macOS)
- Python Version: (e.g., Python 3.9)
Additional Context:
This issue makes interactive input (input()
) unusable with Jupyter Kernel Gateway, as the kernel consistently gets stuck. The client-side code has been modified to attempt to force the header.session
of the input_reply
to match the client's kernelId
, but this workaround is ineffective due to the server's internal session ID mismatch.