Files
chandra/docs/reloading.md
T
Claude 99c6c66726
CI / test (push) Failing after 17s
Launcher: Reload session, and Log out moves in from its own module
The Application Launcher's menu now ends in a session row: Reload, Log out, Suspend, Restart,
Power off. Log out, Restart and Power off take a second click on the same button (a status line
says "Click Log out again to confirm"); Reload and Suspend act at once.

- Reload calls the new session.reload, which reaches the shell as the ReloadSession request
  (native stub: request 8 with n 1; host plasmoids.wit: reload-session; host-wasm: Req::ReloadSession)
  and runs DesktopShell::reload_modules(""): every panel module again from disk, in place, with
  its settings. Windows and apps keep running. The compositor redraws the whole frame after it.
- Suspend / Restart / Power off use the power capability, the same calls as Settings > Power.
- The standalone logout module is gone (component, world, components.txt). Saved panels drop
  "logout", or get the launcher in its place when they had none; panel.edn is rewritten without
  it. A stale logout.wasm is hidden from Settings > Panel (retired_modules).
- Tests: lib/launcher session row, shell migrate_panel, host input tests for Log out and Reload,
  host-wasm launcher session row; control_test uses inspector.wasm instead of logout.wasm.
- README and docs/reloading.md describe the session row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjKUnSS3D92ThigvJf
2026-11-25 21:01:17 +00:00

130 lines
6.7 KiB
Markdown

# Picking up a new build in a running session
After `just install-session` the files under `/usr/local` are new, but the running session keeps
what it loaded at startup. What can be swapped without logging out:
| Part | Reload without logout? | How |
|---|---|---|
| Panel modules (`/usr/local/share/chandra/modules/*.wasm`) | yes | Applications → **Reload**, `just reload` / `chandra-ctl reload`, `kill -USR1`, or Settings → Panel (remove, add again) |
| `compositor.wasm` (shell, WM, portal backend) | no | restart the session |
| `chandra-host` (`wasmhost`) | no | restart the session |
| `config/`, themes, assets | not checked | restart the session to be sure |
The control socket and the SIGUSR1 handler are part of the compositor and host, so a session
started before they existed has neither. Log out and back in once after installing a build that
has them; from then on module reloads need no logout. Don't send SIGUSR1 to a session older than
that: without the handler the signal's default action ends the session.
## Reloading panel modules
```
just install-session # or: just modules, with install-session-dev
just reload # reload every panel module from disk
just reload clock-digital # just one
```
`just reload` runs `session/chandra-ctl reload`; `just install-session` also installs it as
`/usr/local/bin/chandra-ctl`:
```
chandra-ctl reload # every loaded module
chandra-ctl reload NAME # modules whose name (clock-digital), slot (w3) or path is NAME
chandra-ctl list # loaded modules in panel order: slot, module, path
chandra-ctl ping # is the compositor answering?
chandra-ctl help
```
It prints one line per module and exits 0 when everything reloaded, 1 when the compositor
reported an error (a module that failed to load, an unknown name), 2 when it could not reach a
compositor:
```
$ chandra-ctl reload
reloaded w10 launcher
...
failed w8 my-widget: Can't load module: not a wasm file
error 1 of 9 failed to reload
```
What a reload does, for each module: load the `.wasm` again from the path it was loaded from
(for an installed session, `/usr/local/share/chandra/modules`), apply its saved settings
(`:module-config` in `~/.config/chandra/state.edn`, the same values a login gives it), put the new
instance in the old one's place in the panel, then drop the old instance. A module that fails to
load is left loaded as it was, and the reply says why. The new instance gets a new slot id
(`w3` becomes `w12`) and starts fresh: an open popup closes. The module catalog is scanned again,
so a module installed since login shows up under Settings → Panel → Add. A notice above the panel
says what happened ("Reloaded 9 modules", or the error).
The reload goes through the same shell code as Settings → Panel (`DesktopShell::reload_modules`
and `replace_slot` in `compositor/shell/widgets.mbt`), so a module that imports no new host
capability needs nothing else. A module that needs a host interface the running host lacks fails
to load and stays as it was: that needs a new session.
### From the launcher
The Application Launcher's menu ends in a session row (Reload, Log out, Suspend, Restart, Power
off). **Reload** does `chandra-ctl reload` from the desktop: the launcher calls `session.reload`
(wit/capabilities.wit), which reaches the shell as the `ReloadSession` request, and
`DesktopShell::process_requests` calls `reload_modules("")`. Same result and notice; windows and
running apps are untouched, and it acts on the first click (Log out, Restart and Power off take a
second one). Its own menu closes, and the launcher itself is reloaded with the rest.
### SIGUSR1
Sending SIGUSR1 to the host process reloads every module, like `chandra-ctl reload`:
```
pkill -USR1 -x chandra-host
```
The result goes to the session log (the host's stderr) and the notice above the panel; there is
nobody to answer. The handler is installed by the host at startup (`sys.take-sigusr1`, which the
compositor polls every pass). The signal interrupts the idle loop's wait, so it is handled
promptly.
## The control socket
The compositor listens on `$XDG_RUNTIME_DIR/chandra/<wayland socket name>.sock`. The login
session's Wayland socket is `wayland-moon-0`, so its control socket is
`/run/user/$UID/chandra/wayland-moon-0.sock`. `$XDG_RUNTIME_DIR` is private to the user (mode
0700), so no other user can connect. Without `XDG_RUNTIME_DIR` there is no control socket (the log
says so). When the path is already answered by another running compositor (a nested `just run`
with the same socket name), the newcomer leaves it alone and has no control socket.
`chandra-ctl` finds the socket from `--socket PATH`, then `$CHANDRA_CONTROL`, then
`$WAYLAND_DISPLAY` (inside the session), and otherwise takes the only socket in
`$XDG_RUNTIME_DIR/chandra` (from a text console or ssh as the same user, with
`XDG_RUNTIME_DIR` set). With several compositors running it lists them and asks for `--socket`.
The protocol is lines of text, so anything that can talk to a unix socket can drive it, for
example `echo reload | socat - UNIX-CONNECT:$XDG_RUNTIME_DIR/chandra/wayland-moon-0.sock`. A client
writes one command per line; each reply is zero or more lines of output and then one line
starting with `ok` or `error`. Several commands may be sent on one connection.
| Command | Reply |
|---|---|
| `ping` | `ok pong` |
| `list` | `<slot> <module> <path>` per module, then `ok <n> modules` |
| `reload [NAME]` | `reloaded <new slot> <module>` or `failed <slot> <module>: <why>` per module, then `ok <n> reloaded` or `error ...` |
| `help` | the commands, then `ok` |
The compositor handles the socket in its main loop (`compositor/host/control.mbt`, from
`ChandraCompositor::step`), and the listening socket and its clients are among the fds the idle
loop waits on, so an idle desktop still sleeps (about 0.4% CPU, unchanged) and wakes for a
command. It is the same code on the MoonBit host, the Rust host and the native build.
## Not reloadable
`chandra-host` and `compositor.wasm` are read once when `chandra-session` starts them. There is no
reload request or file watcher for them. `docs/ARCHITECTURE.md` says so ("no hot reload on file
change"), and the WM hot-swap in `docs/compositor-design.md` (replaying `list<window-state>` into a
new WM component's `sync-windows`) is a design: nothing triggers it yet. Changes to the compositor,
WM, portal backend or host need a new session: log out and back in.
## Status
Tested headless on both hosts (`build/wasmhost` and `host-wasm`) with the modules from
`build/components`: `ping`, `list`, `reload`, `reload NAME`, a module replaced by a broken file
(reported, old instance kept), SIGUSR1, and idle CPU before and after. Tests:
`compositor/host/control_test.mbt`. Not yet run against an installed login session.