fix: explicitly send input_reply via wsclient when stdin_hook is invoked#79
Open
Nwokike wants to merge 1 commit into
Open
fix: explicitly send input_reply via wsclient when stdin_hook is invoked#79Nwokike wants to merge 1 commit into
Nwokike wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When executing non-interactive code with
allow_stdin=Trueand providing a customstdin_hooktoColabRuntime.execute_code, any user input captured by the hook causes the kernel execution to stall indefinitely waiting for aninput_replyWebSocket message.Root Cause
In
wrapped_stdin_hook(src/colab_cli/runtime.py), afteroriginal_stdin_hookreturns the user's input string (res),execute_interactive(jupyter_kernel_client.wsclient) simply loops (continue) without sendinginput_reply. It expects whoever interceptedstdin_requestto send theinput_replyback to the kernel.Previously,
wrapped_stdin_hookdid not explicitly construct and transmitinput_replyoverwsclient.stdin_channel(or attempted to callself.kernel_client.input(res), which fails becauseKernelClientdoes not have an.input()method —.input()and.stdin_channelbelong to_manager.client(KernelWebSocketClient)).Solution
This PR updates
wrapped_stdin_hookso that after obtaining the response fromoriginal_stdin_hook:wsclient = self.kernel_client._manager.client.input_replymessage dictionary and attaches theparent_headerfrom the incomingstdin_requestprompt (prompt["header"]) so the kernel properly correlates the reply to the request.wsclient.stdin_channel.send(reply_msg).self.kernel_client.input(res)if present.This ensures all custom
stdin_hookimplementations (e.g. interactive UI dialogs, custom terminal input bridges) reliably resume remote execution after handlinginput()/getpass()prompts.