Skip to content

fix(runtime,exec): wait for cold kernel WebSocket handshake and clean up on prelude failure - #324

Open
aarsaputra wants to merge 1 commit into
googlecolab:mainfrom
aarsaputra:fix/cold-kernel-ws-timeout
Open

aarsaputra wants to merge 1 commit into
googlecolab:mainfrom
aarsaputra:fix/cold-kernel-ws-timeout

Conversation

@aarsaputra

Copy link
Copy Markdown

Fixes #285

Summary

  • Wait for cold kernel WebSocket handshake (ColabRuntime._wait_for_ws_ready): jupyter_kernel_client's start_channels() waits only 10 s (REQUEST_TIMEOUT) on connection_ready and ignores a False return value, causing exec/run on cold runtimes (which routinely take 20–40 s to finish 101 Switching Protocols) to fail immediately with a misleading RuntimeError("Connection was lost.").
    • After start(), ColabRuntime.kernel_client now waits up to 60 s (configurable via COLAB_CLI_KERNEL_CONNECT_TIMEOUT) for connection_ready to become set.
    • If the handshake still times out, the client is cleanly stopped (self.stop() also resets self._kernel_client = None) and a retryable requests.exceptions.ConnectTimeout is raised with a clear message so the existing retry loop handles it.
  • Stop runtime on prelude failure (commands/execution.py): Both exec_command and repl now call runtime.stop() if the initial /content prelude raises, preventing background WebSocket threads from hanging the CLI on exit.

Testing

  • Added 3 unit tests in tests/test_runtime.py:
    • test_colab_runtime_waits_for_slow_cold_ws_handshake
    • test_colab_runtime_ws_handshake_timeout_retries_and_cleans_up
    • test_exec_stops_runtime_when_prelude_fails
  • Verified with:
    • uv run ruff check & uv run ruff format --check (all passed)
    • uv run pytest -q (690 passed, 27 skipped)

@google-cla

google-cla Bot commented Dec 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@aarsaputra

Copy link
Copy Markdown
Author

@googlebot I signed it!

@aarsaputra
aarsaputra force-pushed the fix/cold-kernel-ws-timeout branch from 0392b2f to 5d16dab Compare December 4, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exec/run: slow kernel WebSocket handshake on cold runtimes is reported as "Connection was lost." (10 s timeout ignored)

1 participant