WEFT_OS/docs/architecture.md

152 lines
16 KiB
Markdown
Raw Normal View History

# WEFT OS Architecture
## Overview
WEFT OS is a Wayland compositor and application runtime where every app is a WebAssembly component served via a Servo-rendered WebView. The system has no ambient authority: capabilities are declared in `wapp.toml`, verified at install time, and enforced at runtime.
## Components
### weft-compositor
Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Supports DRM/KMS and winit (software/dev) backends.
### weft-servo-shell
System UI host. Renders one WebView pointing at `system-ui.html` using the embedded Servo engine (feature-gated behind `servo-embed`). Connects to the compositor as window type `panel`. Dispatches the `zweft_shell_manager_v1` event queue each frame. Forwards navigation gestures received from the compositor to `weft-appd` over WebSocket. Reads the appd WebSocket port and system token from `$XDG_RUNTIME_DIR/weft/` and hands both to the page through `window.weftAppdEndpoint(port, token)`; the shell hands the token only to the system UI document and denies top-level navigation away from it, and the launcher shows package names as text, never markup.
### weft-app-shell
Per-application Servo host. Spawned by `weft-appd` after the Wasm runtime signals READY. Takes `<app_id>`, `<session_id>` and `--ui <path>`, the UI document weft-appd resolved from the package; it never looks for the package itself. Injects the `weftIpc` WebSocket bridge into the page. The bridge authenticates with the per-session token from `WEFT_BRIDGE_TOKEN` and can only exchange messages with its own session. It is installed only in top-level documents inside the application's UI directory, and top-level navigation outside that directory is denied; framed documents never receive the bridge. Every resource the page loads (subresources, `fetch()`, XHR, workers and WebSocket handshakes) is checked by the shell: the page may load files inside its UI directory, also after symbolic links are resolved, inline `data:` and `blob:` resources, `about:blank` and the session bridge; any other local file or network destination, and every redirect, fails with a network error. Loads Servo does not attribute to the webview, such as `navigator.sendBeacon()`, are all refused. Network access belongs to the Wasm component, under its fetch grants. Servo's privileged `navigator.servo` interface, which can change engine preferences, is not exposed to `about:blank` or `about:srcdoc` documents (a fork patch; see `crates/weft-servo-shell/SERVO_PIN.md`). Registers with the compositor as window type `application`. Exits when the appd session ends.
### weft-appd
Session supervisor. Listens on a Unix socket (MessagePack protocol) and a WebSocket port (JSON). Before a session exists, appd resolves the package once (see [Package resolution](#package-resolution)) and derives its grants from that package's manifest; the runtime and the app shell receive the resolved component and UI document and do not search the stores themselves. For each session: spawns `weft-runtime` and waits for its READY, spawns `weft-app-shell` (`WEFT_APP_SHELL_BIN` is required) and waits for its READY, and only then reports the session running (`APP_READY`). A child reports readiness by printing `READY <token>` on stdout, where the token is a random per-session value appd passes in `WEFT_READY_TOKEN`; Wasm guests and pages share those stdout streams but cannot read the token, so their output cannot fake readiness. Each wait times out after 30 seconds. If either child fails to start, fails to become ready or exits, or the session is terminated, the whole session is stopped: both children, the IPC relay (its task, socket and registered sender), the file portal, the compositor association and any image mount are released. The IPC relay is created with the session in `$XDG_RUNTIME_DIR/weft` (a session cannot start without it); its socket is accessible only to the user and accepts a single connection, which the session's runtime makes before it starts the component. If that connection closes while the session runs, the session is stopped. `IPC_FORWARD` on the Unix socket never waits: it reports an error when the session has no relay or its queue is full. appd applies cgroup resource limits to the runtime via systemd-run when available.
### weft-runtime
WASI Preview 2 + Component Model execution host (Wasmtime 30). Runs the component weft-appd passes with `--module <path>`, the package's `[runtime].module`. Provides host imports for `weft:app/notify`, `weft:app/ipc`, `weft:app/fetch`, `weft:app/notifications`, and `weft:app/clipboard`. Preopens filesystem paths according to capabilities declared in `wapp.toml`.
### weft-pack
Package management CLI. Subcommands: `check` (validate wapp.toml + wasm module), `sign` (Ed25519 signature), `verify` (verify signature), `generate-key`, `install`, `uninstall`, `list`, `build-image` (EROFS dm-verity), `info`.
### weft-file-portal
fix(runtime): close fetch and preopen gaps in grant enforcement A component with a host-specific fetch grant could reach another origin by setting its own Host header, and could inject request lines through the method string, which ureq writes unvalidated. Fetch now accepts only standard methods and refuses Host, framing and hop-by-hop headers. Fetch grants accept canonical DNS names and dotted IPv4 addresses only, so a grant can never be written in a form that silently never matches. --preopen split host and guest at the first `::`, so a host path containing `::` widened the preopened directory; it now splits from the right, and appd refuses host paths that are not UTF-8 or contain `::`. appd validated capabilities one at a time, creating the data directory before a later capability was refused, and required HOME even for packages without filesystem capabilities. It now checks every capability first, resolves host directories only when needed, validates the app ID with the rule weft-pack uses (now shared in weft_ipc_types::package), and reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is read as a shell would: the last assignment wins, $HOME must be followed by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is not used. The grants probe now also overwrites, renames, removes and creates directories in read-only data, and sends a forged Host header, an injected method and a file: URL; it fails when directory permissions of a read-only preopen are widened or the header check is removed. A new CI job builds the runtime with its engine and fetch support and runs the check. The mount test that sets WEFT_APP_STORE now holds the env lock. Package images are still located separately from directory installs; deriving grants from the verified image is part of resolving one package descriptor.
2026-10-09 08:25:40 +00:00
Per-session file proxy. Runs as a separate process with a path allowlist derived from the session's directory grants; read-only grants (`--allow-read`) refuse writes. Paths are checked lexically, so `..` is blocked but symbolic links are followed. Accepts JSON-lines requests over a Unix socket. Components cannot currently reach that socket, because the runtime grants them no socket access.
### weft-mount-helper
Setuid helper binary. Calls `veritysetup` and mounts EROFS images for dm-verity-protected packages. Its device-mapper device is named after the mountpoint, which weft-appd names with a random token in `$XDG_RUNTIME_DIR/weft/mnt`. The helper does not yet restrict its callers or the images and mountpoints they pass, so it is not part of a supported installation.
## Process Topology
```
systemd
├── weft-compositor (user)
├── weft-servo-shell (user, after compositor)
└── weft-appd (user, after compositor + servo-shell)
└── per-session:
├── weft-runtime <app_id> <session_id> --ipc-socket <path> --module <path> [--preopen HOST::GUEST::ro|rw]... [--grant CAP]... [--max-memory-mib N]
├── weft-app-shell <app_id> <session_id> --ui <path>
fix(runtime): enforce effective capability grants per session Every host import was registered and callable whatever the package declared, read-only directory capabilities were preopened read-write, and appd launched packages whose capabilities it could not satisfy. The fetch import also could not be linked: the host returned a tuple where the WIT declares the response record, so any component importing weft:app/fetch failed to instantiate. One capability vocabulary now lives in weft_ipc_types::capability and is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a session's grants once, before the session exists, and refuses the launch with error 403 when a capability is unknown, unsupported (hw:gpu:*) or unsatisfiable (documents without an XDG documents directory). The documents directory now comes from user-dirs.dirs instead of a guessed ~/Documents. The runtime receives grants explicitly (--grant CAP, --preopen HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks the grant on every notifications, clipboard and fetch call. Fetch accepts only http and https to granted hosts, returns redirects and HTTP error statuses as responses instead of following or failing them, and bounds connect time, total time and response size. The file portal takes read-only directories with --allow-read and refuses writes there. tests/runtime/check_grants.py runs the real runtime on a probe component under each kind of grant and checks the outcome of every operation; it fails when read-only data is writable or an import ignores its grant. The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock shared with the tests that set it.
2026-10-09 08:08:58 +00:00
└── weft-file-portal <socket> [--allow ...] [--allow-read ...]
```
## IPC
| Channel | Protocol | Purpose |
|---|---|---|
| weft-appd Unix socket | MessagePack | appd ↔ other system daemons |
| weft-appd WebSocket (:7410) | JSON | system-ui.html and servo-shell ↔ appd (system role: gestures, app lifecycle); app pages ↔ their session (app role) |
| per-session IPC socket | newline-delimited JSON | weft-runtime ↔ weft-app-shell (weft:app/ipc) |
| weft-file-portal socket | JSON-lines | weft-runtime ↔ file proxy |
### WebSocket roles
Every WebSocket connection must complete the upgrade and send `HELLO` as its first message within 5 seconds, or appd closes it; a first message that is not a valid `HELLO` is answered with an error (code 401) before the connection is closed. Messages are limited to 1 MiB.
- `{"type":"HELLO","role":"system","token":"<hex>"}` — the token is the content of `$XDG_RUNTIME_DIR/weft/appd.systoken` (mode 0600), regenerated each time appd starts. A system client may launch, terminate and query sessions. It receives lifecycle broadcasts but never application messages, and cannot inject them (`IPC_FORWARD` is refused with code 403).
- `{"type":"HELLO","role":"app","session_id":<n>,"token":"<hex>"}` — the token is the session's bridge token, passed to `weft-app-shell` in `WEFT_BRIDGE_TOKEN` and distinct from its readiness token. An app client may only send `{"type":"APP_MESSAGE","payload":"<string>"}` (at most 64 KiB, no newlines); the payload goes to its own session's Wasm component. It receives only its own session's replies, as `APP_MESSAGE`, and is disconnected when the session stops.
## Capability Enforcement
fix(runtime): enforce effective capability grants per session Every host import was registered and callable whatever the package declared, read-only directory capabilities were preopened read-write, and appd launched packages whose capabilities it could not satisfy. The fetch import also could not be linked: the host returned a tuple where the WIT declares the response record, so any component importing weft:app/fetch failed to instantiate. One capability vocabulary now lives in weft_ipc_types::capability and is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a session's grants once, before the session exists, and refuses the launch with error 403 when a capability is unknown, unsupported (hw:gpu:*) or unsatisfiable (documents without an XDG documents directory). The documents directory now comes from user-dirs.dirs instead of a guessed ~/Documents. The runtime receives grants explicitly (--grant CAP, --preopen HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks the grant on every notifications, clipboard and fetch call. Fetch accepts only http and https to granted hosts, returns redirects and HTTP error statuses as responses instead of following or failing them, and bounds connect time, total time and response size. The file portal takes read-only directories with --allow-read and refuses writes there. tests/runtime/check_grants.py runs the real runtime on a probe component under each kind of grant and checks the outcome of every operation; it fails when read-only data is writable or an import ignores its grant. The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock shared with the tests that set it.
2026-10-09 08:08:58 +00:00
Capabilities are declared in `wapp.toml` under `[package] capabilities`. One vocabulary (`weft_ipc_types::capability`) is used by `weft-pack check`, which rejects unknown strings, by `weft-appd`, which derives the session's effective grants, and by `weft-runtime`, which enforces them.
`weft-appd` derives grants once, before a session exists. `LAUNCH_APP` is answered with an error and nothing starts when the app ID is malformed (code 400), the package is not installed (404), a declared capability is unknown, unsupported on this host or cannot be satisfied (403), app data exists in both the current and the earlier location (409), or the host cannot provide the resources (500, for example without `HOME`). All capabilities are checked before the app's data directory is created. Without `WEFT_RUNTIME_BIN`, appd starts no processes and derives no grants. The runtime does not read the manifest; it receives the grants as arguments:
fix(runtime): enforce effective capability grants per session Every host import was registered and callable whatever the package declared, read-only directory capabilities were preopened read-write, and appd launched packages whose capabilities it could not satisfy. The fetch import also could not be linked: the host returned a tuple where the WIT declares the response record, so any component importing weft:app/fetch failed to instantiate. One capability vocabulary now lives in weft_ipc_types::capability and is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a session's grants once, before the session exists, and refuses the launch with error 403 when a capability is unknown, unsupported (hw:gpu:*) or unsatisfiable (documents without an XDG documents directory). The documents directory now comes from user-dirs.dirs instead of a guessed ~/Documents. The runtime receives grants explicitly (--grant CAP, --preopen HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks the grant on every notifications, clipboard and fetch call. Fetch accepts only http and https to granted hosts, returns redirects and HTTP error statuses as responses instead of following or failing them, and bounds connect time, total time and response size. The file portal takes read-only directories with --allow-read and refuses writes there. tests/runtime/check_grants.py runs the real runtime on a probe component under each kind of grant and checks the outcome of every operation; it fails when read-only data is writable or an import ignores its grant. The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock shared with the tests that set it.
2026-10-09 08:08:58 +00:00
- `--preopen HOST::GUEST::ro|rw` for each directory, with the access mode the capability names;
- `--grant <capability>` for each host-import capability.
fix(runtime): close fetch and preopen gaps in grant enforcement A component with a host-specific fetch grant could reach another origin by setting its own Host header, and could inject request lines through the method string, which ureq writes unvalidated. Fetch now accepts only standard methods and refuses Host, framing and hop-by-hop headers. Fetch grants accept canonical DNS names and dotted IPv4 addresses only, so a grant can never be written in a form that silently never matches. --preopen split host and guest at the first `::`, so a host path containing `::` widened the preopened directory; it now splits from the right, and appd refuses host paths that are not UTF-8 or contain `::`. appd validated capabilities one at a time, creating the data directory before a later capability was refused, and required HOME even for packages without filesystem capabilities. It now checks every capability first, resolves host directories only when needed, validates the app ID with the rule weft-pack uses (now shared in weft_ipc_types::package), and reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is read as a shell would: the last assignment wins, $HOME must be followed by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is not used. The grants probe now also overwrites, renames, removes and creates directories in read-only data, and sends a forged Host header, an injected method and a file: URL; it fails when directory permissions of a read-only preopen are widened or the header check is removed. A new CI job builds the runtime with its engine and fetch support and runs the check. The mount test that sets WEFT_APP_STORE now holds the env lock. Package images are still located separately from directory installs; deriving grants from the verified image is part of resolving one package descriptor.
2026-10-09 08:25:40 +00:00
Each capability-controlled host import (fetch, notifications, clipboard) checks its grant on every call and returns an error naming the missing capability when it is not granted. `notify` and `ipc` need no capability.
| Capability | Effect |
|---|---|
| `fs:read:app-data` / `fs:rw:app-data` | Preopen the app's data directory (see *App data*) as `/data`, read-only or read-write |
fix(runtime): enforce effective capability grants per session Every host import was registered and callable whatever the package declared, read-only directory capabilities were preopened read-write, and appd launched packages whose capabilities it could not satisfy. The fetch import also could not be linked: the host returned a tuple where the WIT declares the response record, so any component importing weft:app/fetch failed to instantiate. One capability vocabulary now lives in weft_ipc_types::capability and is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a session's grants once, before the session exists, and refuses the launch with error 403 when a capability is unknown, unsupported (hw:gpu:*) or unsatisfiable (documents without an XDG documents directory). The documents directory now comes from user-dirs.dirs instead of a guessed ~/Documents. The runtime receives grants explicitly (--grant CAP, --preopen HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks the grant on every notifications, clipboard and fetch call. Fetch accepts only http and https to granted hosts, returns redirects and HTTP error statuses as responses instead of following or failing them, and bounds connect time, total time and response size. The file portal takes read-only directories with --allow-read and refuses writes there. tests/runtime/check_grants.py runs the real runtime on a probe component under each kind of grant and checks the outcome of every operation; it fails when read-only data is writable or an import ignores its grant. The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock shared with the tests that set it.
2026-10-09 08:08:58 +00:00
| `fs:read:xdg-documents` / `fs:rw:xdg-documents` | Preopen the documents directory from the XDG user-dirs configuration (`XDG_DOCUMENTS_DIR`) as `/xdg/documents`; the launch fails when none is configured |
fix(runtime): close fetch and preopen gaps in grant enforcement A component with a host-specific fetch grant could reach another origin by setting its own Host header, and could inject request lines through the method string, which ureq writes unvalidated. Fetch now accepts only standard methods and refuses Host, framing and hop-by-hop headers. Fetch grants accept canonical DNS names and dotted IPv4 addresses only, so a grant can never be written in a form that silently never matches. --preopen split host and guest at the first `::`, so a host path containing `::` widened the preopened directory; it now splits from the right, and appd refuses host paths that are not UTF-8 or contain `::`. appd validated capabilities one at a time, creating the data directory before a later capability was refused, and required HOME even for packages without filesystem capabilities. It now checks every capability first, resolves host directories only when needed, validates the app ID with the rule weft-pack uses (now shared in weft_ipc_types::package), and reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is read as a shell would: the last assignment wins, $HOME must be followed by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is not used. The grants probe now also overwrites, renames, removes and creates directories in read-only data, and sends a forged Host header, an injected method and a file: URL; it fails when directory permissions of a read-only preopen are widened or the header check is removed. A new CI job builds the runtime with its engine and fetch support and runs the check. The mount test that sets WEFT_APP_STORE now holds the env lock. Package images are still located separately from directory installs; deriving grants from the verified image is part of resolving one package descriptor.
2026-10-09 08:25:40 +00:00
| `net:fetch:<host>` | `weft:app/fetch` to that exact host (a lowercase DNS name or dotted IPv4 address) over HTTP or HTTPS, on any port |
fix(runtime): enforce effective capability grants per session Every host import was registered and callable whatever the package declared, read-only directory capabilities were preopened read-write, and appd launched packages whose capabilities it could not satisfy. The fetch import also could not be linked: the host returned a tuple where the WIT declares the response record, so any component importing weft:app/fetch failed to instantiate. One capability vocabulary now lives in weft_ipc_types::capability and is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a session's grants once, before the session exists, and refuses the launch with error 403 when a capability is unknown, unsupported (hw:gpu:*) or unsatisfiable (documents without an XDG documents directory). The documents directory now comes from user-dirs.dirs instead of a guessed ~/Documents. The runtime receives grants explicitly (--grant CAP, --preopen HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks the grant on every notifications, clipboard and fetch call. Fetch accepts only http and https to granted hosts, returns redirects and HTTP error statuses as responses instead of following or failing them, and bounds connect time, total time and response size. The file portal takes read-only directories with --allow-read and refuses writes there. tests/runtime/check_grants.py runs the real runtime on a probe component under each kind of grant and checks the outcome of every operation; it fails when read-only data is writable or an import ignores its grant. The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock shared with the tests that set it.
2026-10-09 08:08:58 +00:00
| `net:fetch:*` | `weft:app/fetch` to any host |
| `sys:notifications` | `weft:app/notifications` |
| `sys:clipboard:read` / `sys:clipboard:write` | `weft:app/clipboard#read` / `#write` |
| `hw:gpu:compute` / `hw:gpu:render` | Not supported; the launch fails |
fix(runtime): close fetch and preopen gaps in grant enforcement A component with a host-specific fetch grant could reach another origin by setting its own Host header, and could inject request lines through the method string, which ureq writes unvalidated. Fetch now accepts only standard methods and refuses Host, framing and hop-by-hop headers. Fetch grants accept canonical DNS names and dotted IPv4 addresses only, so a grant can never be written in a form that silently never matches. --preopen split host and guest at the first `::`, so a host path containing `::` widened the preopened directory; it now splits from the right, and appd refuses host paths that are not UTF-8 or contain `::`. appd validated capabilities one at a time, creating the data directory before a later capability was refused, and required HOME even for packages without filesystem capabilities. It now checks every capability first, resolves host directories only when needed, validates the app ID with the rule weft-pack uses (now shared in weft_ipc_types::package), and reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is read as a shell would: the last assignment wins, $HOME must be followed by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is not used. The grants probe now also overwrites, renames, removes and creates directories in read-only data, and sends a forged Host header, an injected method and a file: URL; it fails when directory permissions of a read-only preopen are widened or the header check is removed. A new CI job builds the runtime with its engine and fetch support and runs the check. The mount test that sets WEFT_APP_STORE now holds the env lock. Package images are still located separately from directory installs; deriving grants from the verified image is part of resolving one package descriptor.
2026-10-09 08:25:40 +00:00
Fetch does not follow redirects: a redirect is returned to the component as a response, so every destination it requests is checked against its grants. HTTP error statuses are responses too; only policy and transport failures are errors. Only the methods GET, HEAD, POST, PUT, PATCH, DELETE and OPTIONS are accepted, and a component cannot set `Host`, `Content-Length`, `Transfer-Encoding` or other hop-by-hop headers. Connecting times out after 10 seconds and the whole request after 30 seconds, not counting DNS resolution; response bodies are limited to 16 MiB. Fetch requires a runtime built with the `net-fetch` feature.
Fetch grants name hosts, not addresses: ports are not restricted, and a host that resolves to a loopback or private address (or `net:fetch:*`) can reach local services. IPv6 literals cannot be granted.
fix(runtime): enforce effective capability grants per session Every host import was registered and callable whatever the package declared, read-only directory capabilities were preopened read-write, and appd launched packages whose capabilities it could not satisfy. The fetch import also could not be linked: the host returned a tuple where the WIT declares the response record, so any component importing weft:app/fetch failed to instantiate. One capability vocabulary now lives in weft_ipc_types::capability and is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a session's grants once, before the session exists, and refuses the launch with error 403 when a capability is unknown, unsupported (hw:gpu:*) or unsatisfiable (documents without an XDG documents directory). The documents directory now comes from user-dirs.dirs instead of a guessed ~/Documents. The runtime receives grants explicitly (--grant CAP, --preopen HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks the grant on every notifications, clipboard and fetch call. Fetch accepts only http and https to granted hosts, returns redirects and HTTP error statuses as responses instead of following or failing them, and bounds connect time, total time and response size. The file portal takes read-only directories with --allow-read and refuses writes there. tests/runtime/check_grants.py runs the real runtime on a probe component under each kind of grant and checks the outcome of every operation; it fails when read-only data is writable or an import ignores its grant. The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock shared with the tests that set it.
2026-10-09 08:08:58 +00:00
`tests/runtime/check_grants.py` runs the real runtime on a probe component (`tests/components/grants-probe`) under each kind of grant.
## Package Format
```
<app_id>/
wapp.toml — manifest (id, name, version, capabilities, runtime.module, ui.entry)
app.wasm — WASI Component Model binary
ui/
index.html — entry point served by weft-app-shell
signature.sig — Ed25519 signature over SHA-256 of (wapp.toml + app.wasm)
```
Package store roots (in priority order):
1. `$WEFT_APP_STORE` (if set)
2. `~/.local/share/weft/apps/`
3. `/usr/share/weft/apps/`
### Package resolution
`weft-appd` resolves a launch once. A verified image in any store root takes precedence over a directory install in any root, so a user's directory cannot shadow a system image; otherwise the first root with a directory install is used:
- **Verified image:** `<root>/<id>.app.img` with its dm-verity hash tree `<id>.app.hash` and root hash `<id>.app.roothash`, the names `weft-pack build-image` and `build-verity` produce. When any of the three exists, the image must mount through `weft-mount-helper`; a missing companion, a malformed root hash, a missing helper or a failed mount refuses the launch, and appd never falls back to a directory install. The root hash is read from the store next to the image and is not yet authenticated, so dm-verity detects corruption but not a store whose image, hash tree and root hash were replaced together. The mount belongs to the session and is released when the session stops.
- **Directory install:** `<root>/<id>/wapp.toml`.
The package root must be a directory and its manifest a regular file, neither a symbolic link, and the manifest must declare the requested ID. `[runtime].module` and `[ui].entry` must be relative paths of plain components, without symbolic links, naming regular files inside that root. The component, the UI document and the capabilities all come from that one manifest. A refused launch reports 400 (invalid ID), 404 (not installed), 403 (invalid package, image or image metadata) or 500 (the host cannot read the package or mount the image).
A directory install can still be changed by its owner while a session runs, and nothing verifies its content at launch.
## App data
Each app's private data lives in `$XDG_DATA_HOME/weft/app-data/<id>` (`~/.local/share/weft/app-data/<id>` by default), apart from installed packages. Installing, updating or uninstalling a package never removes it. `weft-appd` creates the directory when a session with an app-data capability starts and makes it accessible only to the user (mode 0700); a symbolic link in its place is refused rather than followed. `weft-appd` and `weft-pack` must run with the same `HOME` and `XDG_DATA_HOME` to agree on this location; the systemd unit allows `weft-appd` to write under `~/.local/share/weft`.
Earlier versions kept app data inside the user package store, in `~/.local/share/weft/apps/<id>/data`, for apps declaring an app-data capability. That directory is moved to the new location in a single rename, which never replaces an existing directory:
- by `weft-appd`, on the first launch with an app-data capability;
- by `weft-pack uninstall` and `weft-pack install`, before they touch a package directory in the user store (however its path is spelled). `uninstall` moves it when the package declares an app-data capability or its manifest cannot be read, and otherwise stops without removing anything; a `data` directory is never deleted with a package.
A package directory left empty by the move is removed. Nothing is moved, and `weft-pack` stops or the launch is refused, when the new location already exists, even empty (error 409), when the old one is not a plain directory, or when the two are on different filesystems (error 500); the message names both locations so the user can keep one copy and remove the other. The system UI shows such refusals. Packages cannot contain a top-level `data` entry, so package content is never taken for app data. `tests/frame/check_app_data.py` checks that existing Notes data arrives byte for byte, that the Notes session then reads and saves it, and that a conflict is refused.
## Environment Variables
| Variable | Default | Description |
|---|---|---|
| `WEFT_RUNTIME_BIN` | — | Path to `weft-runtime` binary |
fix(appd): report sessions running only after the UI host is ready weft-appd marked a session Running and broadcast APP_READY as soon as the runtime printed READY, then started weft-app-shell with its output discarded and never watched it. A session with no UI, a UI host that failed to start, or one that crashed was still reported running. Early failure paths skipped parts of the cleanup: the image mount was not unmounted, the compositor association was not released, and the abort sender leaked on spawn failure. Readiness was any stdout line equal to READY, which a Wasm guest (inherited stdout) or a page (window.alert writes to the app shell's stdout) could print. Now a session becomes Running only after the runtime and then the app shell report readiness, each within 30 s; WEFT_APP_SHELL_BIN is required and checked before anything starts. After that, the runtime exiting, the app shell exiting or a terminate request ends the session. Every exit path goes through one teardown that kills both children, releases the compositor association, unmounts the image, stops the file portal and broadcasts Stopped. Readiness uses a per-session random token passed to both children in WEFT_READY_TOKEN. weft-runtime and weft-app-shell print READY <token>, and appd accepts only a line ending with it; guests receive only the variables the runtime names and pages cannot read the host environment. Child output is read in bounded, lossily decoded lines, so invalid UTF-8 or long lines no longer stop the readers. Compositor notifications use try_send so a disconnected compositor cannot stall teardown, and all children are killed if the supervisor is dropped. The IPC relay is not yet owned by the session, and children are killed without a graceful period. Validation: - cargo test -p weft-appd (43 passed); new tests cover: not ready until the app shell is ready, runtime exit before that, no app shell configured (runtime never starts), app shell exit ending a running session with the runtime process gone, and READY lines without the token; they fail against the previous supervisor - end to end with weft-compositor (nested), weft-appd, weft-runtime (wasmtime-runtime) and weft-app-shell: the Counter demo reaches APP_READY and is on screen; a page that prints a READY line through alert and never loads is stopped after 30 s without APP_READY; terminate leaves no child processes - clippy -D warnings and fmt --check for weft-appd and weft-runtime
2026-10-09 01:41:09 +00:00
| `WEFT_APP_SHELL_BIN` | — | Path to `weft-app-shell` binary; required to launch apps |
| `WEFT_READY_TOKEN` | set by appd | Per-session readiness token passed to `weft-runtime` and `weft-app-shell` |
| `WEFT_BRIDGE_TOKEN` | set by appd | Per-session token `weft-app-shell` uses to join its session on the appd WebSocket |
| `WEFT_FILE_PORTAL_BIN` | — | Path to `weft-file-portal` binary |
| `WEFT_MOUNT_HELPER` | — | Path to `weft-mount-helper` binary |
| `WEFT_APP_STORE` | — | Override package store root |
| `WEFT_APPD_SOCKET` | — | Unix socket path for weft-appd |
| `WEFT_APPD_WS_PORT` | `7410` | WebSocket port for weft-appd |
| `WEFT_EGL_RENDERING` | — | Set to `1` to use EGL rendering in Servo shell |
| `WEFT_DISABLE_CGROUP` | — | Set to disable systemd-run cgroup wrapping |
| `WEFT_FILE_PORTAL_SOCKET` | — | Path forwarded to app runtime for file portal |
| `XDG_RUNTIME_DIR` | — | Standard XDG runtime dir (sockets written here) |