Repository navigation
Conversation
jupyter_kernel_client calls stdin_hook(request) and discards the return value, so the hook must send the input_reply itself. The wrapper returned the typed value without sending anything, which left colab auth waiting forever on its first prompt, and it passed the whole message dict to input(), so the raw dict was printed instead of the prompt. Send the reply through the websocket client, print content.prompt, use getpass for password prompts, and redact those values in session history.
Mirror jupyter_kernel_client's default stdin hook: send an EOF marker on EOF, stay silent on Ctrl-C, and skip the reply when a channel already has a queued message. Send the reply before writing history so a logging failure cannot strand the kernel, tolerate a request without a content mapping, and document the custom stdin_hook contract.
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.
Fixes #269.
Summary
colab authhad two visible symptoms, both from the same hook:{'header': {...}, 'content': {'prompt': 'Go to the following link...'}}.input()never returned, so
/content/.adc/adc.jsonwas never written.The stdin hook now shows the real prompt and sends the
input_replythe kernelis waiting for. On a live CPU runtime,
colab authprints the gcloud URL,accepts the code, and leaves working credentials on the VM.
Why
jupyter_kernel_clientcallsstdin_hook(request)with the wholeinput_requestmessage and ignores the hook's return value. The hook must sendan
input_replyitself. Our wrapper only returned the typed value, so thekernel waited forever; it also passed the whole message to
input(), which iswhy the prompt looked like a dict.
Changes
src/colab_cli/runtime.py: readcontent.prompt/content.password, promptlocally (
getpassfor passwords), and send the value withwsclient.input().Mirror the library's default hook for the edges: EOF sends
"\x04", Ctrl-Csends nothing, an already-queued message skips the reply, and a missing
contentmapping is tolerated.tests/test_runtime_stdin.py: prompt and reply, password +getpass+redaction, EOF, Ctrl-C, stale reply, custom hook returning a value or
None,and a malformed request.
tests/test_runtime.py: the existing stdin logging test now follows the realhook contract.
docs/04_automation_and_utility.md: corrected thecolab authdescription andadded a log entry.
Verification
mainbefore the fix (prompt was the dict, no replysent, password used
input()) and pass with it:uv run pytest tests/test_runtime.py tests/test_runtime_stdin.py -q→19 passed.
uv run ruff check .anduv run ruff format --check .pass.ColabRuntime.execute_code("print('ECHO:' + input('Prompt: '))", allow_stdin=True)withhello-from-stdinon stdin printedECHO:hello-from-stdin.colab authprinted the gcloud URL as normal text, accepted the pastedcode, wrote
/content/.adc/adc.json(831 bytes), andgcloud auth listlisted the account.
colab stop, thencolab sessions→ no active sessions.