Error in user YAML: (<unknown>): mapping values are not allowed in this context at line 4 column 167
---
log:
2026-11-27: Fixed `colab exec` exiting 1 after `sys.exit()` / `sys.exit(None)` / `sys.exit(0)`. A leftover `any(output_type == "error")` check after `_exit_code_from_outputs` re-flagged the `SystemExit` error output as a failure, overriding the CPython mapping; `_exit_code_from_outputs` already returns 1 for every non-`SystemExit` error, so the check was removed. `test_cli_exec_systemexit_zero_exits_zero_silently` now passes.
2026-11-23: Shared `colab run`'s CPython `SystemExit` handling (`_exit_code_from_outputs`, `_make_script_output_hook`) with `colab exec` and muted IPython's `"To exit: use ..."` warning during `exec` setup. Because a persistent IPython kernel catches `SystemExit` and emits it as `output_type == "error"` to avoid killing the kernel process, treating every kernel error output as exit 1 wrongly failed scripts that call `sys.exit(0)` (e.g. `argparse --help`, `unittest.main()`) and collapsed `sys.exit(N)` codes into 1.
2026-11-23: `colab exec` now exits 1 when executed code produces a kernel `error` output (after recording history and saving `*_output.ipynb` for notebooks, stopping further notebook cells) (#250).
2026-05-07: Fixed `colab console` piped-stdin handling. Previously a piped invocation (e.g. `echo 'cmd' | colab console -s s`) sent the command and then hung indefinitely because the previous EOF handler emitted a bare `\x04` (Ctrl-D), which the remote `tmux`-wrapped bash treats as a literal character rather than a session terminator. The new handler sends `exit\n` (which bash actually exits on) and then closes the websocket from the client side after a short grace period (`PIPED_EOF_GRACE_SECONDS = 0.5s`) so any tail output (bash `logout`, tmux `[exited]`) makes it back to the user. TTY mode is unchanged: real-terminal EOF is left to the remote shell. Verified live: `echo 'echo HELLO' | colab console -s s` now exits in ~1.2s instead of hanging.
2026-05-07: Fixed `print_kitty` (used by `colab exec --output-image` and any image-producing exec) to no-op when `sys.stdout.isatty()` is false. The Kitty Graphics Protocol escape sequence is meaningless when stdout is a file or pipe and was visually corrupting captured output (a multi-KB base64 PNG blob would land in log files, grep targets, or showboat captures). Image bytes are still saved to disk via `handle_image`'s file-write path; only the inline-render attempt is suppressed.
2026-06-04: Bumped the default `--timeout` for `colab exec` from 10s to 30s (and the matching `colab run` default) so brief silent tasks are less likely to hit a premature `TimeoutError`. Explicit `--timeout` overrides are unaffected.
2026-10-24: `--timeout` for `colab exec` (and `colab run`) is now an idle limit: execution fails only after that many seconds without output, so code that keeps printing is never cut off, and `--timeout 0` means no limit. On 0.8.0/0.9.0 the old deadline was never enforced, so code that is silent for longer than `--timeout` now fails where it used to complete. `colab repl` and `colab install`, which pass no timeout, wait until execution finishes, or until the kernel dies or restarts. None of them busy-loop while waiting. `colab auth` and `colab drivemount` are unchanged. See #183.
2026-10-29: Removed the `colab console` subcommand and its `/colab/tty` transport (`console.py`, its tests, and `integration/repro_piped_console/`). Use `colab ssh -s NAME` for an interactive shell and `colab ssh -s NAME -- CMD` for one-shot commands, or pipe `!`-prefixed shell commands to `colab exec` where ssh can't work.
---
Execution involves sending Python code (or shell commands) to the Jupyter kernel running on the Colab VM and processing the stream of output messages.
- Transport: WebSockets (using
websocketslibrary if allowed, or a customhttp.clientbased long-polling implementation if we're strictly stdlib). - Communication: Jupyter Kernel Messaging Protocol.
execute_request: Send code string.execute_reply: Get status.iopub.stream: Capturestdoutandstderr.
- Interactive Mode: Standard Python
cmd.Cmdorcode.InteractiveConsolefor local input/output. - Piping Support: Detect
sys.stdin.isatty(). If not a TTY, read all input and send as a single execution request.
- File Handling:
- If file path is local: Read content, send as code.
- If file path is remote: Execute
!python <path>.
- Multi-Modal Output: Handle
display_datamessages (e.g.,image/png,text/html). For the CLI, we'll save images to temporary files and print their paths, or if the terminal supports it (e.g., iTerm2), inline them. - Timeout Configuration: Exposes a
--timeoutflag (default 30s): the longest silence allowed before execution fails. Raise it so long-running silent tasks (like model compilation or data downloading) are not prematurely killed;0means no limit. - Error &
SystemExitSemantics:- Any uncaught exception (
ValueError,SyntaxError, etc.) causescolab execto exit with status1 - Any executed code block that returns an
output_type == "error"causes colab to exit with status `11 - Any exit code stops remaining cells in a
.ipynbnotebook while still writing*_output.ipynb. - Why
SystemExitis handled specially: Unlike CPython—wheresys.exit(...)terminates the process directly—an IPython/Jupyter kernel must stay alive across executions, so it catchesSystemExitand reports it asoutput_type == "error"(ename == "SystemExit"), accompanied by an interactive"An exception has occurred, use %tb..."banner and"To exit: use 'exit', 'quit', or Ctrl-D."UserWarning. TreatingSystemExitlike an uncaught exception breaks well-formed scripts passed tocolab exec -f script.py(such asargparse --help,unittest.main(), or early-exit guards callingsys.exit(0)) and loses custom integer exit codes (sys.exit(N)).colab exectherefore sharescolab run's CPython mapping:sys.exit()/sys.exit(None)/sys.exit(0)exit0silently,sys.exit(N)exitsNsilently, andsys.exit("msg")printsmsgtostderrand exits1.
- Any uncaught exception (
- Kernel Management:
ColabRuntime(fromcolab-agent) already handles message signing and message types. - Output Streaming: Continuous polling or asynchronous message handling to provide real-time output.
- Piping Example:
cat script.py | colab exec -s my-session.
TDD is mandatory for all execution features.
- Test Case: Verify
ColabRuntimecorrectly sends anexecute_requestmessage over the websocket. - Test Case: Verify
iopub.streammessages are correctly handled and printed tostdoutin real-time. - Test Case: Verify
display_data(specificallyimage/png) triggers the correct local handling (saving or display). - Test Case: Verify
colab execexits with status 1 when the kernel emits anerroroutput, and halts multi-cell.ipynbexecution at the failing cell while still saving*_output.ipynb. - Test Case: Verify
colab execapplies CPythonSystemExitsemantics (sys.exit(0)/None→0silently,sys.exit(N)→N,sys.exit("msg")→ printsmsgtostderrand exits1) without IPython%tbor exit-warning noise.
- Test Case: Mock
sys.stdin.isatty()to verifycolab replcorrectly switches between interactive mode and one-shot piped execution. - Test Case: Verify large piped inputs are handled without buffer overflow or truncation.
- Test Case:
print_kittyis a no-op whensys.stdout.isatty()is false (regression: previously emitted ANSI/base64 into pipes and files).