Protocol and kernel host
What a Jupyter server has to get right, component by component: the requirements Ganymede was built against, and how it meets each. This is a design note; Known gaps has what doesn't work today and the Roadmap what is planned. For how the crates are arranged, see Architecture.
Protocol crate
- Message envelope: ZMQ multipart frames:
[identities..., "<IDS|MSG>", hmac, header, parent_header, metadata, content, buffers...]. - HMAC-SHA256 over the four JSON frames, keyed from the connection file. The empty-key case (no signing) must be supported.
- Header:
msg_id,session,username,date(ISO 8601),msg_type,version("5.5"), optionalsubshell_id(5.5). - Typed
content, with unknown fields preserved (serde_json::Valuepassthrough) because kernels add extras. Ganymede types the messages it reads or builds (execute, complete, inspect, is_complete, kernel_info, shutdown, interrupt, the iopub outputs, stdin, comms); the rest (debug, history, subshells) pass through as JSON. - Five channels: shell (DEALER), control (DEALER), iopub (SUB; XPUB on the kernel side as of 5.5), stdin (DEALER), heartbeat (REQ).
- Connection file: JSON with ip, transport (
tcporipc), five ports, key, signature_scheme, kernel_name. Written to the runtime dir askernel-<uuid>.json. - Messages to cover: execute, inspect, complete, history, is_complete, comm_info, kernel_info, shutdown, interrupt, debug (DAP), stream, display_data, update_display_data, execute_input, execute_result, error, status, clear_output, comm_open/msg/close, input_request/reply, and the 5.5 subshell messages (create/delete/list) plus
iopub_welcome. Ganymede carriessubshell_idin the header and passes subshell messages through. It takes a kernel'siopub_welcomeas proof that iopub is live (see Kernel lifecycle) and doesn't pass it on to clients.
ZMQ options: the pure-Rust zeromq crate (used by runtimelib and Deno's built-in kernel) or zmq bindings to libzmq. Pure Rust avoids a C dependency; libzmq is the reference behaviour. Ganymede uses pure Rust, behind the KernelTransport trait so it can be swapped.
The jupyter-protocol, runtimelib, and nbformat crates from the runtimed project cover much of this and are maintained (Zed depends on them). Ganymede implements its own and tests against the Python reference implementations instead.
Kernel host
A long-running process that owns the ZMQ sockets for every kernel and multiplexes clients onto them. Responsibilities:
- Kernelspec discovery:
kernel.jsonunder the Jupyter data dirs (JUPYTER_PATH,~/.local/share/jupyter/kernels,/usr/share/jupyter/kernels, macOS~/Library/Jupyter, Windows%APPDATA%).jupyter_clientalso searches<sys.prefix>/share/jupyter/kernels, the Python environment it runs in. Ganymede has no Python environment, so it doesn't;--kernelspec-rootadds a conda or venv prefix by hand. Fields:argvwith{connection_file}substitution,env,display_name,language,interrupt_mode,metadata. - Port allocation: bind to find free ports, release, pass to kernel. Racy by design;
ipctransport sidesteps it on POSIX. - Launch: subprocess with env, cwd, process group (POSIX) or job object (Windows) so interrupt and kill reach children. On Windows only kill does: there are no signal interrupts, and the Windows build is untested.
- Startup handshake: send
kernel_info_requeston shell and control repeatedly until both reply. This "nudge" exists because PUB/SUB has a slow-joiner problem: iopub messages sent before the subscriber connects are lost, including the initialstartingstatus. Don't skip it. - Heartbeat: REQ/REP ping on an interval; missing replies mean the kernel is hung or dead. Ganymede pings only kernels it attached to (
run --existing,Engine::connect); for a kernel it launched, the process exiting is the signal. - Interrupt:
SIGINTto the process group wheninterrupt_modeissignal;interrupt_requeston control when it ismessage. Windows has no SIGINT for this; ipykernel uses a named event via an env var. - Shutdown:
shutdown_requeston control, wait, then SIGTERM, then SIGKILL. Remove the connection file. - Autorestart: poll the process; restart on unexpected exit, bounded retries, with a
restartingstatus broadcast to clients. Ganymede does this under the same kernel id, up tokernel_restart_limitcrashes in a row (Kernel crashes). - Multi-client: many websocket clients per kernel. iopub is broadcast; shell replies are routed back to the client whose
sessionsent the request.execute_inputon iopub is how other clients see executions. - Execution semantics the host should not hide: the kernel runs shell requests serially; after an error, queued requests come back with
status: aborted;stop_on_error,silent,store_history,allow_stdin,user_expressionsare per-request flags. - Completion detection: a request is done when the shell reply has arrived and an iopub
status: idlewith the matchingparent_header.msg_idhas arrived. The two sockets have no ordering guarantee between them. - stdin channel:
input_requestfrom the kernel means a client must answer withinput_reply; only the requesting client should be prompted.
Server (REST + websocket)
If any existing frontend or tool should connect (JupyterLab, VS Code, nbclient, papermill, Quarto), the REST surface must match jupyter_server:
/api/kernelspecs,/api/kernels(list, start, get, delete, interrupt, restart),/api/sessions(notebook path to kernel mapping),/api/contents(get, put, patch, delete, checkpoints),/api/status,/api/terminals(optional; Ganymede serves them, see Open a terminal)./api/kernels/{id}/channelswebsocket. Two subprotocols: the default (JSON with achannelkey, binary buffers in a separate frame layout) andv1.kernel.websocket.jupyter.org(single binary frame with offset table, channel name, and buffers). Implement v1; the default is for older clients.- Auth: token in header or query, cookie session, XSRF token for non-GET, origin check on websocket upgrade, CORS. The server executes arbitrary code by design, so this is not optional even on localhost.
base_urlprefix support for reverse proxies and JupyterHub.- Static asset serving for the UI. Ganymede serves JupyterLab's bundle from disk, as
ganymede lab installunpacks it, rather than embedding one.
Stack: tokio, axum, tokio-tungstenite, serde, hmac/sha2, uuid, jiff.
Beyond these, Ganymede serves jupyter-lsp's /lsp/status and /lsp/ws/<name> (Language servers), jupyter-collaboration's rooms and jupyter-server-documents' execute endpoint (Live editing and document rooms), jupyter-resource-usage's /api/metrics/v1, a kernel's log at /api/kernels/{id}/log, and, with --mcp, notebook tools for agents at /mcp (Agents over MCP).
Notebook format
- nbformat 4.5:
cells[]withid,cell_type(code, markdown, raw),source(string or array of lines),metadata,outputs[],execution_count,attachmentsfor markdown cells. - Output types:
stream(name, text),display_data,execute_result(plusexecution_count),error(ename, evalue, traceback). MIME bundles are{mime: string | string[] | json};application/jsonand+jsontypes are stored as JSON, not strings. - Round-trip fidelity matters for git diffs:
nbformatwritesindent=1,sort_keys=True, trailing newline. Match it exactly or every save produces a diff. - Validate against the JSON schema; accept v3 and upgrade on load. Ganymede reads leniently and reports schema problems the way
jupyter_serverdoes (messagein the contents model), and upgrades v3 notebooks to 4.5 on read. ganymede-nbformatmatches Python's writer byte for byte.
Document model and collaboration
Jupyter's modern document model is a Yjs document (jupyter_ydoc), and JupyterLab 4 syncs it over y-websocket. Rust has yrs, the official Yjs port, and y-sync for the protocol. This is the one place where Rust makes the server simpler than the Python original: one process can own the CRDT, the file on disk, and the kernel connection.
Retrofitting collaboration onto a non-CRDT model is a rewrite, so the server owns the live notebook as a yrs document, in the schema jupyter_ydoc and JupyterLab's @jupyter/ydoc share. The file stays the source of truth: a room loads it, saves to it, and merges in changes made on disk (the iPad use case says why). Ganymede answers jupyter-collaboration's session and room endpoints and jupyter-server-documents' execute and file id endpoints. Live editing and document rooms describes how to use rooms, the merge rules, and the endpoints.
What is usually missed
The parts a from-scratch server most often gets wrong, and where Ganymede stands on each.
| Area | Why it matters | Ganymede |
|---|---|---|
| Slow-joiner nudge, and completion as reply plus idle | Without either, the first cell hangs now and then | Both, as above |
| Widgets | Comms are cheap; widgets also need the frontend's widget manager and each package's JavaScript | Comms and binary buffers are routed; ganymede lab install adds jupyterlab_widgets and anywidget |
| Binary buffers | Easy to drop in the websocket bridge | Carried in both websocket framings |
| Large and fast output | A busy kernel can flood a slow client | Past 10,000 queued iopub messages a client's output is dropped and it is told, as jupyter_server's rate limit does; replies are never dropped |
| Several clients, reconnects | Laptops sleep and iPads suspend | Kernels outlive connections; a client that reconnects with its session gets what it missed |
| Security | The server runs code; localhost alone doesn't stop DNS rebinding or a malicious notebook | Token, login cookie, XSRF, Host and origin checks, notebook trust; see Security |
| Windows | Interrupts, process groups and paths differ | Built, untested; job object for kill, no signal interrupts (Known gaps) |
Debugger (DAP over debug_request) | ipykernel advertises it | Passed through on control; a conformance test stops at a breakpoint, and JupyterLab's debugger panel is untested |
| Subshells (5.5) | New kernels will use them | subshell_id and subshell messages passed through |
| Headless execution | Useful alone, and the best conformance test | ganymede run and ganymede execute, compared against jupyter execute in CI |
| Ecosystem contracts | Runtime dir, jupyter --paths, base_url, JupyterHub | Jupyter's directories and base_url match; no JupyterHub single-user mode |
| Extensions | JupyterLab's adoption rests on them | Prebuilt frontend extensions; no server extensions, by design |
| nbformat fidelity | Every save otherwise churns git | Byte-identical to Python's writer |
| Language servers, terminals, export | Each depends on something outside the core | Language servers from the config file, terminals over a pseudo-terminal, and script, Markdown, and self-contained HTML export in Rust (no Python-template exports such as PDF, LaTeX, or slides) |