Colab #
The Colab extension
depends on remote. It provides account login and the kernel's colab binding.
See the kernel for execution context.
Account access #
The extension's colab.account route calls accounts.signed_in and returns an
access token and email to the kernel. The kernel does not need to read
creds.json, but it does receive the token.
accounts.gleam owns
account selection and token handling.
Assignment validation #
The Python plugin validates each assignment
payload with private Pydantic v2 models before it builds a ColabInstance. It
builds those models lazily on the first assignment parse, so loading the plugin
at kernel startup does not pay for Pydantic's import or model build. Keep the
models behind that first parse: a kernel that never uses Colab must not carry
them. Valid server fields keep their current names and aliases. endpoint wins
over its id alias, and an empty endpoint falls back to id. machineShape
aliases shape and takes precedence when both are present. Integer enum values
from Colab's assignment API normalize to strings: variant maps 0 to CPU,
1 to GPU, and 2 to TPU, and machineShape/shape maps 0 to
standard and 1 to highmem. Missing variant, shape, and status keep
their defaults of GPU, standard, and active. runtimeProxyInfo supplies
url, token, and tokenExpiresInSeconds. Unknown fields are ignored by the
models and kept only in ColabInstance.raw, which holds the original payload.
Callers should treat a malformed payload as a failed request, not as an empty
listing. instances accepts an object with an assignments list or a bare
list, and launch accepts an assignment object or one nested under
assignment. A wrong type, a non-object runtimeProxyInfo, a missing
endpoint and id, or a non-list assignments value raises ColabError. The
message names the field path, such as
assignments[0].runtimeProxyInfo.tokenExpiresInSeconds. It does not include
submitted values, so a proxy token in the payload does not leak through the
error. Do not log the raw payload to work around this.
Plugin tests cover the valid shapes, the
field paths, and the token check.
Runtimes and connections #
The Python plugin provides instances,
status, launch, stop, and connect. connect fetches a current runtime
listing, finds an SSH public key, registers an alias, and calls
remote.connect. Its websocket proxy URL and public key reach the bridge
through environment variables. The alias disables SSH host key checking for that
connection.
A failed connection can raise ColabSshSessionError after a probe identifies an
occupied SSH session. stop sends an unassign request and removes the alias. It
is a runtime-management operation, not a connection retry. Recover needed files
before requesting it.
Outbound routing #
The colab outbound route covers control and runtime HTTP calls,
downloads, session probes, and the SSH websocket bridge. Each operation asks the
daemon for the route; an SSH alias keeps the one connect saw. The proxy must
be reachable from the kernel's machine, which for a remote kernel is not the
daemon's.
HTTP file access #
The same plugin provides runtime_status, contents, read, and pull
independently of SSH. Paths are relative to the Jupyter root. pull can resume
a partial download. Resume assumes the remote content has not changed. Use
resume=False for mutable content.
Plugin tests exercise the client with a
fake HTTP layer.