2026-03-11 14:20:51 +00:00
|
|
|
use std::path::PathBuf;
|
2026-03-11 08:17:20 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
2026-10-09 19:39:01 +00:00
|
|
|
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter};
|
2026-03-11 13:40:55 +00:00
|
|
|
use weft_ipc_types::AppdToCompositor;
|
2026-03-11 08:17:20 +00:00
|
|
|
|
|
|
|
|
use crate::Registry;
|
2026-03-11 13:40:55 +00:00
|
|
|
use crate::compositor_client::CompositorSender;
|
2026-10-09 10:18:36 +00:00
|
|
|
use crate::ipc::{AppStateKind, Response};
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
use crate::launch::LaunchPackage;
|
|
|
|
|
use crate::mount::Mount;
|
2026-03-11 08:17:20 +00:00
|
|
|
|
2026-10-09 09:11:35 +00:00
|
|
|
/// The per-session relay between the component's IPC socket and the app
|
|
|
|
|
/// bridge. It belongs to the session: closing it stops the relay task and
|
|
|
|
|
/// removes the socket, whether or not the component ever connected.
|
|
|
|
|
pub(crate) struct IpcRelay {
|
|
|
|
|
task: tokio::task::JoinHandle<()>,
|
|
|
|
|
socket_path: PathBuf,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl IpcRelay {
|
2026-10-09 09:18:39 +00:00
|
|
|
/// Completes when the relay stops: the component closed its connection
|
|
|
|
|
/// or the listener failed.
|
|
|
|
|
async fn ended(&mut self) {
|
|
|
|
|
let _ = (&mut self.task).await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drop for IpcRelay {
|
|
|
|
|
fn drop(&mut self) {
|
2026-10-09 09:11:35 +00:00
|
|
|
self.task.abort();
|
|
|
|
|
let _ = std::fs::remove_file(&self.socket_path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 19:39:01 +00:00
|
|
|
/// The longest message from a component, its line break included: the
|
|
|
|
|
/// runtime refuses longer ones, so a longer line ends the relay.
|
2026-10-09 19:43:20 +00:00
|
|
|
#[cfg(unix)]
|
2026-10-09 19:39:01 +00:00
|
|
|
const MAX_RELAY_FRAME: usize = 64 * 1024 + 2;
|
|
|
|
|
|
2026-10-09 09:11:35 +00:00
|
|
|
/// Listens on `socket_path` for the session's component and relays
|
|
|
|
|
/// newline-delimited messages between it and the returned sender (towards
|
|
|
|
|
/// the component) and the broadcast channel (from the component).
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(unix)]
|
2026-10-09 09:11:35 +00:00
|
|
|
pub(crate) fn spawn_ipc_relay(
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
session_id: u64,
|
|
|
|
|
socket_path: PathBuf,
|
|
|
|
|
broadcast: tokio::sync::broadcast::Sender<Response>,
|
2026-10-09 09:11:35 +00:00
|
|
|
) -> std::io::Result<(tokio::sync::mpsc::Sender<String>, IpcRelay)> {
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let _ = std::fs::remove_file(&socket_path);
|
2026-10-09 09:11:35 +00:00
|
|
|
let listener = tokio::net::UnixListener::bind(&socket_path)?;
|
2026-10-09 09:18:39 +00:00
|
|
|
{
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
2026-10-09 09:24:49 +00:00
|
|
|
if let Err(e) =
|
|
|
|
|
std::fs::set_permissions(&socket_path, std::fs::Permissions::from_mode(0o600))
|
|
|
|
|
{
|
|
|
|
|
let _ = std::fs::remove_file(&socket_path);
|
|
|
|
|
return Err(e);
|
|
|
|
|
}
|
2026-10-09 09:18:39 +00:00
|
|
|
}
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let (html_to_wasm_tx, mut html_to_wasm_rx) = tokio::sync::mpsc::channel::<String>(64);
|
2026-10-09 09:11:35 +00:00
|
|
|
let task = tokio::spawn(async move {
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let Ok((stream, _)) = listener.accept().await else {
|
|
|
|
|
tracing::warn!(session_id, "IPC relay: failed to accept connection");
|
|
|
|
|
return;
|
|
|
|
|
};
|
2026-10-09 09:11:35 +00:00
|
|
|
// One component per session: no further connections are accepted.
|
|
|
|
|
drop(listener);
|
2026-10-09 07:45:49 +00:00
|
|
|
tracing::debug!(session_id, "IPC relay: component connected");
|
fix(runtime): end the runtime when its session's IPC connection closes
A runtime outlived the weft-appd that started it. Runtimes run in their
own systemd scopes, outside weft-appd's service, and a component that
waits for messages, as the Counter and Notes demos do, keeps polling a
closed connection forever. Each time weft-appd stopped or restarted and
restored the previous session, the earlier runtimes stayed behind.
The connection is the session: a thread waits for it to hang up, without
reading from it, and the runtime then exits whatever the component is
doing. That covers weft-appd closing the connection, weft-appd ending,
and the runtime ending the connection itself after a failed send or an
overlong message. A runtime given an IPC socket it cannot connect to now
fails instead of running unreachable. weft-appd's relay notes that it
must not shut down half of the connection, which would now end the
session.
tests/runtime/check_grants.py runs the real runtime on the Counter
component over a Unix socket: it answers an increment, and once the test
closes its end the runtime exits with status 0 within 10 seconds; with
the watcher removed it keeps running and the check fails. A unit test
checks that the wait sees a hangup but neither wakes on nor consumes
pending data; CI's runtime-grants job now runs the runtime's unit tests
with its features. The nested desktop Counter and Notes checks pass with
this runtime.
2026-10-09 21:06:58 +00:00
|
|
|
// The runtime ends when its side of this connection is shut down,
|
|
|
|
|
// even only for writing, so the connection stays whole until the
|
|
|
|
|
// session ends: tokio::io::split does not shut down a dropped half,
|
|
|
|
|
// as UnixStream::into_split would.
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let (reader, writer) = tokio::io::split(stream);
|
|
|
|
|
let mut reader = BufReader::new(reader);
|
|
|
|
|
let mut writer = BufWriter::new(writer);
|
2026-10-09 19:39:01 +00:00
|
|
|
// The frame being read lives outside the loop: `read_until` keeps
|
|
|
|
|
// what it has read when the other branch wins, so a message from the
|
|
|
|
|
// page never splits a message from the component.
|
|
|
|
|
let mut frame = Vec::new();
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
loop {
|
2026-10-09 19:39:01 +00:00
|
|
|
let mut limited = (&mut reader).take((MAX_RELAY_FRAME + 1 - frame.len()) as u64);
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
tokio::select! {
|
2026-10-09 19:39:01 +00:00
|
|
|
n = limited.read_until(b'\n', &mut frame) => {
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
match n {
|
|
|
|
|
Ok(0) | Err(_) => break,
|
2026-10-09 19:43:20 +00:00
|
|
|
Ok(_) if frame.len() > MAX_RELAY_FRAME => {
|
|
|
|
|
tracing::warn!(session_id, "IPC relay: message over the size limit");
|
|
|
|
|
break;
|
2026-10-09 19:39:01 +00:00
|
|
|
}
|
2026-10-09 19:43:20 +00:00
|
|
|
// The rest of the message is still to come.
|
|
|
|
|
Ok(_) if !frame.ends_with(b"\n") => {}
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
Ok(_) => {
|
2026-10-09 19:39:01 +00:00
|
|
|
let line = std::mem::take(&mut frame);
|
2026-10-09 19:43:20 +00:00
|
|
|
let Ok(text) = String::from_utf8(line) else {
|
|
|
|
|
tracing::warn!(session_id, "IPC relay: message is not UTF-8");
|
|
|
|
|
break;
|
|
|
|
|
};
|
2026-10-09 19:39:01 +00:00
|
|
|
let payload = text.trim_end_matches(['\n', '\r']).to_owned();
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let _ = broadcast.send(Response::IpcMessage { session_id, payload });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
msg = html_to_wasm_rx.recv() => {
|
|
|
|
|
match msg {
|
|
|
|
|
Some(payload) => {
|
|
|
|
|
let mut data = payload;
|
|
|
|
|
data.push('\n');
|
|
|
|
|
if writer.write_all(data.as_bytes()).await.is_err()
|
|
|
|
|
|| writer.flush().await.is_err()
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None => break,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-10-09 09:11:35 +00:00
|
|
|
Ok((html_to_wasm_tx, IpcRelay { task, socket_path }))
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 12:44:44 +00:00
|
|
|
#[cfg(not(unix))]
|
2026-10-09 09:11:35 +00:00
|
|
|
pub(crate) fn spawn_ipc_relay(
|
2026-03-13 12:44:44 +00:00
|
|
|
_session_id: u64,
|
|
|
|
|
_socket_path: PathBuf,
|
|
|
|
|
_broadcast: tokio::sync::broadcast::Sender<Response>,
|
2026-10-09 09:11:35 +00:00
|
|
|
) -> std::io::Result<(tokio::sync::mpsc::Sender<String>, IpcRelay)> {
|
|
|
|
|
Err(std::io::ErrorKind::Unsupported.into())
|
2026-03-13 12:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:17:20 +00:00
|
|
|
const READY_TIMEOUT: Duration = Duration::from_secs(30);
|
|
|
|
|
|
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
|
|
|
/// Environment variable carrying a session's readiness token to its children.
|
|
|
|
|
///
|
|
|
|
|
/// A child reports readiness by printing `READY <token>` on its own stdout.
|
|
|
|
|
/// Application code shares that stdout (Wasm guests through inherited stdio,
|
|
|
|
|
/// pages through `window.alert`) but cannot read the token, because the
|
|
|
|
|
/// runtime passes the guest only the variables it names and pages cannot read
|
|
|
|
|
/// the host process environment.
|
|
|
|
|
const READY_TOKEN_ENV: &str = "WEFT_READY_TOKEN";
|
2026-10-09 17:00:08 +00:00
|
|
|
/// The application's close policy, `immediate` or `ask`, for the app shell.
|
|
|
|
|
const CLOSE_POLICY_ENV: &str = "WEFT_APP_CLOSE";
|
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
|
|
|
|
2026-10-09 07:45:49 +00:00
|
|
|
/// Environment variable carrying the session's application bridge credential
|
|
|
|
|
/// to weft-app-shell.
|
|
|
|
|
const BRIDGE_TOKEN_ENV: &str = "WEFT_BRIDGE_TOKEN";
|
|
|
|
|
|
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
|
|
|
/// Longest line read from a child's output; longer lines are split.
|
|
|
|
|
const MAX_LINE: u64 = 64 * 1024;
|
|
|
|
|
|
2026-10-09 07:45:49 +00:00
|
|
|
/// A random 128-bit credential as 32 hex characters.
|
|
|
|
|
pub(crate) fn random_token() -> std::io::Result<String> {
|
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
|
|
|
use std::io::Read;
|
|
|
|
|
let mut bytes = [0u8; 16];
|
|
|
|
|
std::fs::File::open("/dev/urandom")?.read_exact(&mut bytes)?;
|
|
|
|
|
Ok(bytes.iter().map(|b| format!("{b:02x}")).collect())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Reads one line of at most MAX_LINE bytes, decoded lossily. Returns None at
|
|
|
|
|
/// end of output.
|
|
|
|
|
async fn read_child_line<R: tokio::io::AsyncBufRead + Unpin>(
|
|
|
|
|
reader: &mut R,
|
|
|
|
|
) -> std::io::Result<Option<String>> {
|
|
|
|
|
use tokio::io::AsyncReadExt;
|
|
|
|
|
let mut line = Vec::new();
|
|
|
|
|
let n = (&mut *reader)
|
|
|
|
|
.take(MAX_LINE)
|
|
|
|
|
.read_until(b'\n', &mut line)
|
|
|
|
|
.await?;
|
|
|
|
|
if n == 0 {
|
|
|
|
|
return Ok(None);
|
|
|
|
|
}
|
|
|
|
|
Ok(Some(String::from_utf8_lossy(&line).trim_end().to_owned()))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 00:43:35 +00:00
|
|
|
/// `systemd-run` options that place the runtime in a transient user scope.
|
|
|
|
|
///
|
|
|
|
|
/// A scope runs the command in the foreground as systemd-run's own process,
|
|
|
|
|
/// so its stdout and exit status reach appd directly. `--wait` only applies
|
|
|
|
|
/// to service units; systemd rejects it together with `--scope`.
|
|
|
|
|
const SYSTEMD_SCOPE_ARGS: &[&str] = &[
|
|
|
|
|
"--user",
|
|
|
|
|
"--scope",
|
|
|
|
|
"--collect",
|
|
|
|
|
"--slice=weft-apps.slice",
|
|
|
|
|
"-p",
|
|
|
|
|
"CPUQuota=200%",
|
|
|
|
|
"-p",
|
|
|
|
|
"MemoryMax=512M",
|
2026-10-09 18:23:07 +00:00
|
|
|
"-p",
|
2026-10-09 18:39:05 +00:00
|
|
|
"TasksMax=512",
|
2026-10-09 00:43:35 +00:00
|
|
|
];
|
|
|
|
|
|
2026-03-11 14:25:04 +00:00
|
|
|
fn systemd_cgroup_available() -> bool {
|
|
|
|
|
if std::env::var("WEFT_DISABLE_CGROUP").is_ok() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let Ok(runtime_dir) = std::env::var("XDG_RUNTIME_DIR") else {
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
std::path::Path::new(&runtime_dir)
|
|
|
|
|
.join("systemd/private")
|
|
|
|
|
.exists()
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:20:16 +00:00
|
|
|
async fn kill_portal(portal: Option<(PathBuf, tokio::process::Child)>) {
|
|
|
|
|
if let Some((sock, mut child)) = portal {
|
|
|
|
|
let _ = child.kill().await;
|
|
|
|
|
let _ = child.wait().await;
|
|
|
|
|
let _ = std::fs::remove_file(&sock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
fn spawn_app_shell(
|
|
|
|
|
bin: &str,
|
|
|
|
|
session_id: u64,
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
package: &LaunchPackage,
|
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
|
|
|
token: &str,
|
2026-10-09 07:45:49 +00:00
|
|
|
bridge_token: Option<String>,
|
2026-10-09 15:07:33 +00:00
|
|
|
wayland: Option<std::os::unix::net::UnixStream>,
|
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
|
|
|
) -> std::io::Result<tokio::process::Child> {
|
2026-10-09 07:45:49 +00:00
|
|
|
let mut command = tokio::process::Command::new(bin);
|
2026-10-09 15:07:33 +00:00
|
|
|
match wayland {
|
|
|
|
|
// The app shell's only Wayland connection is the one created for its
|
|
|
|
|
// session, handed over as its standard input: WAYLAND_SOCKET names
|
|
|
|
|
// that descriptor, and no display socket is offered to connect
|
|
|
|
|
// anywhere else. Only this child receives the descriptor.
|
|
|
|
|
Some(stream) => {
|
|
|
|
|
command
|
|
|
|
|
.stdin(std::process::Stdio::from(std::os::fd::OwnedFd::from(
|
|
|
|
|
stream,
|
|
|
|
|
)))
|
|
|
|
|
.env("WAYLAND_SOCKET", "0")
|
|
|
|
|
.env_remove("WAYLAND_DISPLAY");
|
|
|
|
|
}
|
|
|
|
|
None => {
|
|
|
|
|
command.stdin(std::process::Stdio::null());
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-09 07:45:49 +00:00
|
|
|
if let Some(bridge_token) = bridge_token {
|
|
|
|
|
// The page holds this credential; it must differ from the readiness
|
|
|
|
|
// token, which page output could otherwise use to fake readiness.
|
|
|
|
|
command.env(BRIDGE_TOKEN_ENV, bridge_token);
|
|
|
|
|
}
|
|
|
|
|
let child = command
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
.arg(&package.app_id)
|
2026-03-12 09:58:45 +00:00
|
|
|
.arg(session_id.to_string())
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
.arg("--ui")
|
|
|
|
|
.arg(&package.ui_entry)
|
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
|
|
|
.env(READY_TOKEN_ENV, token)
|
2026-10-09 17:00:08 +00:00
|
|
|
.env(CLOSE_POLICY_ENV, package.close.as_str())
|
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
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
|
.kill_on_drop(true)
|
|
|
|
|
.spawn()?;
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
tracing::info!(session_id, app_id = %package.app_id, bin, "app shell spawned");
|
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
|
|
|
Ok(child)
|
2026-03-12 09:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:09:38 +00:00
|
|
|
fn portal_socket_path(session_id: u64) -> Option<PathBuf> {
|
|
|
|
|
let runtime_dir = std::env::var("XDG_RUNTIME_DIR").ok()?;
|
|
|
|
|
let dir = PathBuf::from(runtime_dir).join("weft");
|
2026-10-09 09:27:28 +00:00
|
|
|
crate::private_dir(&dir).ok()?;
|
2026-03-11 17:09:38 +00:00
|
|
|
Some(dir.join(format!("portal-{session_id}.sock")))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn spawn_file_portal(
|
|
|
|
|
session_id: u64,
|
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
|
|
|
dirs: &[crate::grants::GrantedDir],
|
2026-03-11 17:09:38 +00:00
|
|
|
) -> Option<(PathBuf, tokio::process::Child)> {
|
|
|
|
|
let bin = std::env::var("WEFT_FILE_PORTAL_BIN").ok()?;
|
|
|
|
|
let socket = portal_socket_path(session_id)?;
|
|
|
|
|
let mut cmd = tokio::process::Command::new(&bin);
|
|
|
|
|
cmd.arg(&socket)
|
|
|
|
|
.stdin(std::process::Stdio::null())
|
|
|
|
|
.stdout(std::process::Stdio::null())
|
|
|
|
|
.stderr(std::process::Stdio::null());
|
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
|
|
|
for dir in dirs {
|
|
|
|
|
let flag = match dir.access {
|
|
|
|
|
weft_ipc_types::capability::Access::Read => "--allow-read",
|
|
|
|
|
weft_ipc_types::capability::Access::ReadWrite => "--allow",
|
|
|
|
|
};
|
|
|
|
|
cmd.arg(flag).arg(&dir.host);
|
2026-03-11 17:09:38 +00:00
|
|
|
}
|
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
|
|
|
let child = cmd.kill_on_drop(true).spawn().ok()?;
|
2026-03-11 17:09:38 +00:00
|
|
|
tracing::info!(session_id, socket = %socket.display(), "file portal spawned");
|
|
|
|
|
Some((socket, child))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 17:10:15 +00:00
|
|
|
/// A request to end a session, from `TERMINATE_APP`.
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
|
pub(crate) enum Stop {
|
|
|
|
|
/// Close as a user close would; the application may decline.
|
|
|
|
|
Close,
|
|
|
|
|
/// Terminate without asking.
|
|
|
|
|
Force,
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 17:16:42 +00:00
|
|
|
/// Repeated requests carry nothing new, so a few queued ones are enough.
|
|
|
|
|
pub(crate) const STOP_QUEUE: usize = 2;
|
|
|
|
|
pub(crate) type StopSender = tokio::sync::mpsc::Sender<Stop>;
|
2026-10-09 17:10:15 +00:00
|
|
|
/// Ends when appd shuts down and drops the sender.
|
2026-10-09 17:16:42 +00:00
|
|
|
pub(crate) type StopReceiver = tokio::sync::mpsc::Receiver<Stop>;
|
2026-10-09 17:10:15 +00:00
|
|
|
|
2026-03-11 08:17:20 +00:00
|
|
|
pub(crate) async fn supervise(
|
|
|
|
|
session_id: u64,
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
mut package: LaunchPackage,
|
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
|
|
|
grants: crate::grants::SessionGrants,
|
2026-03-11 08:17:20 +00:00
|
|
|
registry: Registry,
|
2026-10-09 17:10:15 +00:00
|
|
|
abort_rx: StopReceiver,
|
2026-03-11 13:40:55 +00:00
|
|
|
compositor_tx: Option<CompositorSender>,
|
2026-03-11 08:17:20 +00:00
|
|
|
) -> anyhow::Result<()> {
|
2026-03-11 11:30:21 +00:00
|
|
|
let mut abort_rx = abort_rx;
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
let app_id = package.app_id.clone();
|
|
|
|
|
let app_id = app_id.as_str();
|
|
|
|
|
let image = package.image.take();
|
2026-03-11 08:17:20 +00:00
|
|
|
let bin = match std::env::var("WEFT_RUNTIME_BIN") {
|
|
|
|
|
Ok(b) => b,
|
|
|
|
|
Err(_) => {
|
|
|
|
|
tracing::debug!(session_id, %app_id, "WEFT_RUNTIME_BIN not set; skipping process spawn");
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
return stop_unstarted(®istry, session_id, image).await;
|
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
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let Ok(shell_bin) = std::env::var("WEFT_APP_SHELL_BIN") else {
|
|
|
|
|
tracing::warn!(session_id, %app_id, "WEFT_APP_SHELL_BIN not set; no UI host to start");
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
return stop_unstarted(®istry, session_id, image).await;
|
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
|
|
|
};
|
2026-10-09 07:45:49 +00:00
|
|
|
let token = match random_token() {
|
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
|
|
|
Ok(token) => token,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::error!(session_id, %app_id, error = %e, "cannot create readiness token");
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
return stop_unstarted(®istry, session_id, image).await;
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-09 09:11:35 +00:00
|
|
|
let Some(ipc_socket_path) = crate::session_ipc_socket_path(session_id) else {
|
|
|
|
|
tracing::warn!(session_id, %app_id, "no runtime directory for the IPC socket");
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
return stop_unstarted(®istry, session_id, image).await;
|
2026-10-09 09:11:35 +00:00
|
|
|
};
|
|
|
|
|
let broadcast = registry.lock().await.broadcast().clone();
|
|
|
|
|
let relay = match spawn_ipc_relay(session_id, ipc_socket_path.clone(), broadcast) {
|
|
|
|
|
Ok((tx, relay)) => {
|
|
|
|
|
registry.lock().await.register_ipc_sender(session_id, tx);
|
|
|
|
|
relay
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::warn!(session_id, %app_id, error = %e, "cannot open the IPC socket");
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
return stop_unstarted(®istry, session_id, image).await;
|
2026-10-09 09:11:35 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
let portal = spawn_file_portal(session_id, &grants.dirs);
|
2026-03-11 17:09:38 +00:00
|
|
|
|
2026-03-11 14:25:04 +00:00
|
|
|
let mut cmd = if systemd_cgroup_available() {
|
|
|
|
|
let mut c = tokio::process::Command::new("systemd-run");
|
2026-10-09 00:43:35 +00:00
|
|
|
c.args(SYSTEMD_SCOPE_ARGS).arg("--").arg(&bin);
|
2026-03-11 14:25:04 +00:00
|
|
|
c
|
|
|
|
|
} else {
|
|
|
|
|
tokio::process::Command::new(&bin)
|
|
|
|
|
};
|
2026-03-11 14:10:11 +00:00
|
|
|
cmd.arg(app_id)
|
2026-03-11 08:17:20 +00:00
|
|
|
.arg(session_id.to_string())
|
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
|
.stderr(std::process::Stdio::piped())
|
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
|
|
|
.stdin(std::process::Stdio::null())
|
|
|
|
|
.env(READY_TOKEN_ENV, &token)
|
|
|
|
|
.kill_on_drop(true);
|
2026-03-11 14:10:11 +00:00
|
|
|
|
2026-10-09 09:11:35 +00:00
|
|
|
cmd.arg("--ipc-socket").arg(&ipc_socket_path);
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
cmd.arg("--module").arg(&package.module);
|
2026-03-11 14:47:23 +00:00
|
|
|
|
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
|
|
|
for dir in &grants.dirs {
|
|
|
|
|
cmd.arg("--preopen").arg(dir.preopen_arg());
|
|
|
|
|
}
|
|
|
|
|
for capability in &grants.imports {
|
|
|
|
|
cmd.arg("--grant").arg(capability.to_string());
|
2026-03-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
let mut session = OwnedSession {
|
|
|
|
|
session_id,
|
|
|
|
|
runtime: None,
|
|
|
|
|
app_shell: None,
|
|
|
|
|
portal,
|
2026-10-09 09:11:35 +00:00
|
|
|
relay: Some(relay),
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
image,
|
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
|
|
|
compositor_tx,
|
2026-10-09 15:07:33 +00:00
|
|
|
client_attached: false,
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut runtime = match cmd.spawn() {
|
2026-03-11 10:45:17 +00:00
|
|
|
Ok(c) => c,
|
|
|
|
|
Err(e) => {
|
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
|
|
|
return session
|
|
|
|
|
.settle(®istry, &format!("failed to spawn runtime: {e}"))
|
|
|
|
|
.await;
|
2026-03-11 10:45:17 +00:00
|
|
|
}
|
|
|
|
|
};
|
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
|
|
|
let runtime_stdout = runtime.stdout.take().expect("stdout piped");
|
|
|
|
|
tokio::spawn(drain_stderr(
|
|
|
|
|
runtime.stderr.take().expect("stderr piped"),
|
|
|
|
|
session_id,
|
|
|
|
|
"runtime",
|
|
|
|
|
));
|
|
|
|
|
session.runtime = Some(runtime);
|
|
|
|
|
|
|
|
|
|
// The component must initialize before the UI host starts.
|
|
|
|
|
let runtime_stdout = match wait_for_child_ready(runtime_stdout, &token, &mut abort_rx).await {
|
|
|
|
|
Ok(reader) => reader,
|
|
|
|
|
Err(reason) => {
|
|
|
|
|
return session
|
|
|
|
|
.settle(®istry, &format!("runtime {reason}"))
|
|
|
|
|
.await;
|
|
|
|
|
}
|
2026-03-11 11:30:21 +00:00
|
|
|
};
|
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
|
|
|
tokio::spawn(drain_stdout(runtime_stdout, session_id));
|
2026-03-11 08:17:20 +00:00
|
|
|
|
2026-10-09 15:07:33 +00:00
|
|
|
// With a compositor, the app shell connects only through a connection
|
|
|
|
|
// the compositor received for this session, so every surface it creates
|
|
|
|
|
// is bound to the session.
|
|
|
|
|
let wayland = match &session.compositor_tx {
|
|
|
|
|
None => None,
|
|
|
|
|
Some(tx) => match attach_client(tx, session_id, app_id) {
|
|
|
|
|
Ok(stream) => {
|
|
|
|
|
session.client_attached = true;
|
|
|
|
|
Some(stream)
|
2026-10-09 10:18:36 +00:00
|
|
|
}
|
2026-10-09 15:07:33 +00:00
|
|
|
Err(reason) => return session.settle(®istry, &reason).await,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
let bridge_token = registry.lock().await.bridge_token(session_id);
|
|
|
|
|
let mut app_shell = match spawn_app_shell(
|
|
|
|
|
&shell_bin,
|
|
|
|
|
session_id,
|
|
|
|
|
&package,
|
|
|
|
|
&token,
|
|
|
|
|
bridge_token,
|
|
|
|
|
wayland,
|
|
|
|
|
) {
|
|
|
|
|
Ok(child) => child,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
return session
|
|
|
|
|
.settle(®istry, &format!("failed to spawn app shell: {e}"))
|
|
|
|
|
.await;
|
|
|
|
|
}
|
|
|
|
|
};
|
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
|
|
|
let shell_stdout = app_shell.stdout.take().expect("stdout piped");
|
|
|
|
|
tokio::spawn(drain_stderr(
|
|
|
|
|
app_shell.stderr.take().expect("stderr piped"),
|
|
|
|
|
session_id,
|
|
|
|
|
"app shell",
|
|
|
|
|
));
|
|
|
|
|
session.app_shell = Some(app_shell);
|
|
|
|
|
|
|
|
|
|
// Running requires the UI host to have presented the loaded document.
|
|
|
|
|
let shell_stdout = tokio::select! {
|
|
|
|
|
r = wait_for_child_ready(shell_stdout, &token, &mut abort_rx) => {
|
|
|
|
|
r.map_err(|reason| format!("app shell {reason}"))
|
2026-03-11 11:30:21 +00:00
|
|
|
}
|
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
|
|
|
status = session.runtime.as_mut().expect("runtime spawned").wait() => {
|
|
|
|
|
Err(format!("runtime exited before the app shell was ready ({status:?})"))
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
2026-10-09 09:24:49 +00:00
|
|
|
_ = session.relay.as_mut().expect("relay opened").ended() => {
|
|
|
|
|
Err("component closed its IPC connection before the session was ready".to_owned())
|
|
|
|
|
}
|
2026-03-13 13:05:31 +00:00
|
|
|
};
|
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
|
|
|
let shell_stdout = match shell_stdout {
|
|
|
|
|
Ok(reader) => reader,
|
|
|
|
|
Err(reason) => return session.settle(®istry, &reason).await,
|
|
|
|
|
};
|
2026-10-09 17:00:08 +00:00
|
|
|
let (cancel_tx, mut cancelled) = tokio::sync::mpsc::channel(1);
|
|
|
|
|
tokio::spawn(watch_app_shell_stdout(
|
|
|
|
|
shell_stdout,
|
|
|
|
|
session_id,
|
|
|
|
|
token.clone(),
|
|
|
|
|
cancel_tx,
|
|
|
|
|
));
|
2026-03-11 08:17:20 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
|
let mut reg = registry.lock().await;
|
2026-10-09 17:16:42 +00:00
|
|
|
// A stop requested while starting can still be queued here, or lose
|
|
|
|
|
// the race with READY; the session is then stopped, not shown.
|
|
|
|
|
if matches!(reg.state(session_id), AppStateKind::Stopping) || abort_rx.try_recv().is_ok() {
|
|
|
|
|
drop(reg);
|
|
|
|
|
return session.settle(®istry, "startup aborted").await;
|
|
|
|
|
}
|
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
|
|
|
reg.set_state(session_id, AppStateKind::Running);
|
|
|
|
|
let _ = reg.broadcast().send(Response::AppReady {
|
|
|
|
|
session_id,
|
|
|
|
|
app_id: app_id.to_owned(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
tracing::info!(session_id, %app_id, "app ready");
|
2026-03-11 08:17:20 +00:00
|
|
|
|
2026-10-09 17:10:15 +00:00
|
|
|
// Whether the user asked the application to close, so that a clean exit
|
|
|
|
|
// afterwards, also one the application makes after declining, is a
|
|
|
|
|
// close on request.
|
|
|
|
|
let mut close_asked = false;
|
2026-10-09 17:00:08 +00:00
|
|
|
let reason = loop {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
status = session.runtime.as_mut().expect("runtime spawned").wait() => {
|
|
|
|
|
break format!("runtime exited ({status:?})");
|
|
|
|
|
}
|
|
|
|
|
status = session.app_shell.as_mut().expect("app shell spawned").wait() => {
|
2026-10-09 17:10:15 +00:00
|
|
|
break match status {
|
|
|
|
|
Ok(status) if close_asked && status.success() => {
|
|
|
|
|
format!("closed on request; app shell exited ({status:?})")
|
|
|
|
|
}
|
|
|
|
|
status => format!("app shell exited ({status:?})"),
|
|
|
|
|
};
|
2026-10-09 17:00:08 +00:00
|
|
|
}
|
2026-10-09 17:10:15 +00:00
|
|
|
stop = abort_rx.recv() => match stop {
|
|
|
|
|
Some(Stop::Force) => break "terminated by force".to_owned(),
|
|
|
|
|
Some(Stop::Close) => {
|
|
|
|
|
close_asked = true;
|
|
|
|
|
match session.close(session_id, &mut cancelled, &mut abort_rx).await {
|
|
|
|
|
Close::Settle(reason) => break reason,
|
|
|
|
|
// The application keeps running, as its close
|
|
|
|
|
// policy allows; its window comes to the front so
|
|
|
|
|
// the user sees why. A later request asks again.
|
|
|
|
|
Close::Cancelled => {
|
|
|
|
|
tracing::info!(session_id, "the application declined the close");
|
|
|
|
|
session.focus(session_id);
|
|
|
|
|
}
|
2026-10-09 17:00:08 +00:00
|
|
|
}
|
2026-10-09 17:10:15 +00:00
|
|
|
}
|
|
|
|
|
// The senders are dropped only when appd shuts down.
|
|
|
|
|
None => break "appd is shutting down".to_owned(),
|
2026-10-09 17:00:08 +00:00
|
|
|
},
|
|
|
|
|
_ = session.relay.as_mut().expect("relay opened").ended() => {
|
|
|
|
|
break "component closed its IPC connection".to_owned();
|
|
|
|
|
}
|
2026-10-09 09:18:39 +00:00
|
|
|
}
|
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
|
|
|
};
|
|
|
|
|
session.settle(®istry, &reason).await
|
|
|
|
|
}
|
2026-03-11 13:40:55 +00:00
|
|
|
|
2026-10-09 17:00:08 +00:00
|
|
|
/// How a close request ended.
|
|
|
|
|
enum Close {
|
|
|
|
|
/// The session ends, for this reason.
|
|
|
|
|
Settle(String),
|
|
|
|
|
/// The application declined the close and keeps running.
|
|
|
|
|
Cancelled,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The app shell's report that its page declined a close, followed by the
|
|
|
|
|
/// session's readiness token so page output cannot fake it.
|
|
|
|
|
const CLOSE_CANCELLED: &str = "CLOSE_CANCELLED";
|
|
|
|
|
|
|
|
|
|
/// Passes the app shell's close reports on to the supervisor and logs
|
|
|
|
|
/// everything else it prints.
|
|
|
|
|
async fn watch_app_shell_stdout(
|
|
|
|
|
mut reader: BufReader<tokio::process::ChildStdout>,
|
|
|
|
|
session_id: u64,
|
|
|
|
|
token: String,
|
|
|
|
|
cancelled: tokio::sync::mpsc::Sender<()>,
|
|
|
|
|
) {
|
|
|
|
|
while let Ok(Some(line)) = read_child_line(&mut reader).await {
|
2026-10-09 17:10:15 +00:00
|
|
|
// Earlier output without a trailing newline can precede the
|
|
|
|
|
// report, as it can precede READY; the token alone establishes it.
|
|
|
|
|
if line.rsplit_once(' ').is_some_and(|(head, t)| {
|
|
|
|
|
head.ends_with(CLOSE_CANCELLED) && crate::ws::tokens_match(&token, t)
|
|
|
|
|
}) {
|
2026-10-09 17:00:08 +00:00
|
|
|
// One pending report is enough; the supervisor drops stale ones
|
|
|
|
|
// before it asks again.
|
|
|
|
|
let _ = cancelled.try_send(());
|
|
|
|
|
} else {
|
|
|
|
|
tracing::debug!(session_id, stdout = %line, "child stdout");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 16:36:29 +00:00
|
|
|
/// How long an application may take to close after being asked, for
|
|
|
|
|
/// example to save, before its processes are terminated.
|
|
|
|
|
pub(crate) const CLOSE_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(5);
|
|
|
|
|
|
2026-10-09 15:07:33 +00:00
|
|
|
/// Creates the session's Wayland connection and queues the compositor's end
|
|
|
|
|
/// for the compositor, returning the app shell's end.
|
|
|
|
|
fn attach_client(
|
|
|
|
|
tx: &CompositorSender,
|
|
|
|
|
session_id: u64,
|
|
|
|
|
app_id: &str,
|
|
|
|
|
) -> Result<std::os::unix::net::UnixStream, String> {
|
fix(compositor): keep shell-level interfaces from sessions and harden the appd connection
Session clients could still create layer-shell surfaces, including
full-screen overlays with exclusive keyboard input, and bind the input
method, which bypassed the refusal of shell roles. Both globals are now
hidden from clients bound to a session.
The compositor IPC connection is tracked by its read source, so a write
error can no longer let a second peer feed the same buffers; a failed
write shuts the connection down. An undecodable or oversized frame ends
the connection, since descriptors could otherwise pair with the wrong
messages, and the descriptor limit counts only descriptors no message
claims, so a burst of launches is not taken for abuse. When appd's
connection ends, the compositor closes the clients of the sessions it
attached.
weft-appd notices when the compositor closes the connection, resends a
message whose write failed after reconnecting, and refuses a launch
while the compositor is not connected instead of starting an app shell
that can never connect.
2026-10-09 15:15:01 +00:00
|
|
|
if !tx.is_connected() {
|
|
|
|
|
return Err("weft-compositor is not connected, so the app cannot show a window".to_owned());
|
|
|
|
|
}
|
2026-10-09 15:07:33 +00:00
|
|
|
let (shell, compositor) = std::os::unix::net::UnixStream::pair()
|
|
|
|
|
.map_err(|e| format!("cannot create the app's Wayland connection: {e}"))?;
|
|
|
|
|
tx.try_send(crate::compositor_client::Outbound {
|
|
|
|
|
msg: AppdToCompositor::AttachClient {
|
|
|
|
|
session_id,
|
|
|
|
|
app_id: app_id.to_owned(),
|
|
|
|
|
},
|
|
|
|
|
fd: Some(compositor.into()),
|
|
|
|
|
})
|
|
|
|
|
.map_err(|_| "the compositor connection is not available".to_owned())?;
|
|
|
|
|
Ok(shell)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/// Marks a session that never started any process as stopped.
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
async fn stop_unstarted(
|
|
|
|
|
registry: &Registry,
|
|
|
|
|
session_id: u64,
|
|
|
|
|
image: Option<Mount>,
|
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
|
release_image(image).await;
|
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
|
|
|
let mut reg = registry.lock().await;
|
|
|
|
|
reg.set_state(session_id, AppStateKind::Stopped);
|
|
|
|
|
reg.remove_abort_sender(session_id);
|
|
|
|
|
let _ = reg.broadcast().send(Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: AppStateKind::Stopped,
|
|
|
|
|
});
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2026-03-11 14:47:23 +00:00
|
|
|
|
2026-10-09 09:11:35 +00:00
|
|
|
/// The processes, IPC relay, portal, compositor association and image mount
|
|
|
|
|
/// a session owns. `settle` releases all of them on every exit path: spawn
|
|
|
|
|
/// failure, readiness failure, timeout, abort and child exit.
|
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
|
|
|
struct OwnedSession {
|
|
|
|
|
session_id: u64,
|
|
|
|
|
runtime: Option<tokio::process::Child>,
|
|
|
|
|
app_shell: Option<tokio::process::Child>,
|
|
|
|
|
portal: Option<(PathBuf, tokio::process::Child)>,
|
2026-10-09 09:11:35 +00:00
|
|
|
relay: Option<IpcRelay>,
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
/// The mounted package image, released after both children have exited.
|
|
|
|
|
image: Option<Mount>,
|
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
|
|
|
compositor_tx: Option<CompositorSender>,
|
2026-10-09 15:07:33 +00:00
|
|
|
/// Whether the compositor was given this session's client connection.
|
|
|
|
|
client_attached: bool,
|
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
|
|
|
}
|
2026-03-11 17:09:38 +00:00
|
|
|
|
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
|
|
|
impl OwnedSession {
|
2026-10-09 16:36:29 +00:00
|
|
|
/// Closes a running session as a user close would: the compositor asks
|
|
|
|
|
/// its windows to close and the app shell gets `CLOSE_TIMEOUT` to exit by
|
|
|
|
|
/// itself. Returns the terminal reason; settling terminates whatever is
|
|
|
|
|
/// still running.
|
2026-10-09 17:00:08 +00:00
|
|
|
async fn close(
|
|
|
|
|
&mut self,
|
|
|
|
|
session_id: u64,
|
|
|
|
|
cancelled: &mut tokio::sync::mpsc::Receiver<()>,
|
2026-10-09 17:10:15 +00:00
|
|
|
stops: &mut StopReceiver,
|
2026-10-09 17:00:08 +00:00
|
|
|
) -> Close {
|
2026-10-09 17:10:15 +00:00
|
|
|
// A report already read from an earlier close, for example one the
|
|
|
|
|
// user started in the compositor, does not answer this one. One
|
|
|
|
|
// still in the pipe can: the session then reads as declined while
|
|
|
|
|
// the app shell is still asking, and the app shell's own answer
|
|
|
|
|
// timeout still closes a page that does not answer.
|
2026-10-09 17:00:08 +00:00
|
|
|
while cancelled.try_recv().is_ok() {}
|
2026-10-09 16:36:29 +00:00
|
|
|
let asked = self.client_attached
|
|
|
|
|
&& self.compositor_tx.as_ref().is_some_and(|tx| {
|
|
|
|
|
tx.is_connected()
|
|
|
|
|
&& tx
|
|
|
|
|
.try_send(AppdToCompositor::AppCloseRequest { session_id }.into())
|
|
|
|
|
.is_ok()
|
|
|
|
|
});
|
|
|
|
|
if !asked {
|
2026-10-09 17:00:08 +00:00
|
|
|
return Close::Settle(
|
|
|
|
|
"terminate requested; the compositor could not ask the app to close".to_owned(),
|
|
|
|
|
);
|
2026-10-09 16:36:29 +00:00
|
|
|
}
|
2026-10-09 16:41:30 +00:00
|
|
|
let (Some(app_shell), Some(runtime), Some(relay)) = (
|
|
|
|
|
self.app_shell.as_mut(),
|
|
|
|
|
self.runtime.as_mut(),
|
|
|
|
|
self.relay.as_mut(),
|
|
|
|
|
) else {
|
2026-10-09 17:00:08 +00:00
|
|
|
return Close::Settle("terminate requested".to_owned());
|
2026-10-09 16:36:29 +00:00
|
|
|
};
|
2026-10-09 16:41:30 +00:00
|
|
|
let wait = async {
|
2026-10-09 17:10:15 +00:00
|
|
|
loop {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
status = app_shell.wait() => break Close::Settle(match status {
|
|
|
|
|
Ok(status) if status.success() => {
|
|
|
|
|
format!("closed on request; app shell exited ({status:?})")
|
|
|
|
|
}
|
|
|
|
|
status => format!("app shell failed while closing ({status:?})"),
|
|
|
|
|
}),
|
|
|
|
|
status = runtime.wait() => {
|
|
|
|
|
break Close::Settle(format!("runtime exited while closing ({status:?})"));
|
2026-10-09 16:41:30 +00:00
|
|
|
}
|
2026-10-09 17:10:15 +00:00
|
|
|
_ = relay.ended() => break Close::Settle(
|
|
|
|
|
"component closed its IPC connection while closing".to_owned(),
|
|
|
|
|
),
|
|
|
|
|
Some(()) = cancelled.recv() => break Close::Cancelled,
|
|
|
|
|
stop = stops.recv() => match stop {
|
|
|
|
|
// Asking again while the application answers changes
|
|
|
|
|
// nothing.
|
|
|
|
|
Some(Stop::Close) => {}
|
|
|
|
|
Some(Stop::Force) => {
|
|
|
|
|
break Close::Settle("terminated by force while closing".to_owned());
|
|
|
|
|
}
|
|
|
|
|
None => break Close::Settle("appd is shutting down".to_owned()),
|
|
|
|
|
},
|
2026-10-09 17:00:08 +00:00
|
|
|
}
|
2026-10-09 16:41:30 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
tokio::time::timeout(CLOSE_TIMEOUT, wait)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap_or_else(|_| {
|
2026-10-09 17:00:08 +00:00
|
|
|
Close::Settle(format!(
|
2026-10-09 16:41:30 +00:00
|
|
|
"close requested; the app shell did not exit within {} s and was terminated",
|
|
|
|
|
CLOSE_TIMEOUT.as_secs()
|
2026-10-09 17:00:08 +00:00
|
|
|
))
|
2026-10-09 16:41:30 +00:00
|
|
|
})
|
2026-10-09 16:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-09 17:10:15 +00:00
|
|
|
/// Brings the session's window to the front with keyboard focus.
|
|
|
|
|
fn focus(&self, session_id: u64) {
|
|
|
|
|
if self.client_attached
|
|
|
|
|
&& let Some(tx) = &self.compositor_tx
|
|
|
|
|
{
|
|
|
|
|
let _ = tx.try_send(AppdToCompositor::AppFocusRequest { session_id }.into());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
async fn settle(self, registry: &Registry, reason: &str) -> anyhow::Result<()> {
|
|
|
|
|
let session_id = self.session_id;
|
|
|
|
|
tracing::info!(session_id, reason, "stopping session");
|
2026-10-09 17:10:15 +00:00
|
|
|
{
|
|
|
|
|
let mut reg = registry.lock().await;
|
|
|
|
|
if !matches!(reg.state(session_id), AppStateKind::Stopping) {
|
|
|
|
|
reg.set_state(session_id, AppStateKind::Stopping);
|
|
|
|
|
let _ = reg.broadcast().send(Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: AppStateKind::Stopping,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
kill_child(self.app_shell).await;
|
|
|
|
|
kill_child(self.runtime).await;
|
2026-10-09 15:07:33 +00:00
|
|
|
if self.client_attached
|
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
|
|
|
&& let Some(tx) = &self.compositor_tx
|
|
|
|
|
&& tx
|
2026-10-09 15:07:33 +00:00
|
|
|
.try_send(AppdToCompositor::AppSurfaceDestroyed { session_id }.into())
|
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
|
|
|
.is_err()
|
|
|
|
|
{
|
|
|
|
|
tracing::warn!(
|
|
|
|
|
session_id,
|
|
|
|
|
"compositor queue unavailable; surface not released"
|
|
|
|
|
);
|
|
|
|
|
}
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
release_image(self.image).await;
|
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
|
|
|
kill_portal(self.portal).await;
|
2026-10-09 09:18:39 +00:00
|
|
|
drop(self.relay);
|
2026-03-11 10:16:28 +00:00
|
|
|
let mut reg = registry.lock().await;
|
2026-10-09 09:11:35 +00:00
|
|
|
reg.remove_ipc_sender(session_id);
|
2026-03-11 10:16:28 +00:00
|
|
|
reg.set_state(session_id, AppStateKind::Stopped);
|
2026-03-11 17:38:35 +00:00
|
|
|
reg.remove_abort_sender(session_id);
|
2026-03-11 10:16:28 +00:00
|
|
|
let _ = reg.broadcast().send(Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: AppStateKind::Stopped,
|
|
|
|
|
});
|
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
|
|
|
Ok(())
|
2026-03-11 10:16:28 +00:00
|
|
|
}
|
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
|
|
|
}
|
2026-03-11 08:17:20 +00:00
|
|
|
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
/// Unmounts a package image without blocking the async workers.
|
|
|
|
|
async fn release_image(image: Option<Mount>) {
|
|
|
|
|
if let Some(image) = image {
|
|
|
|
|
let _ = tokio::task::spawn_blocking(move || drop(image)).await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
async fn kill_child(child: Option<tokio::process::Child>) {
|
|
|
|
|
if let Some(mut child) = child {
|
|
|
|
|
let _ = child.kill().await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Waits for a child to print `READY <token>`, for at most READY_TIMEOUT.
|
|
|
|
|
/// Returns why it did not become ready otherwise.
|
|
|
|
|
async fn wait_for_child_ready(
|
|
|
|
|
stdout: tokio::process::ChildStdout,
|
|
|
|
|
token: &str,
|
2026-10-09 17:10:15 +00:00
|
|
|
abort_rx: &mut StopReceiver,
|
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
|
|
|
) -> Result<BufReader<tokio::process::ChildStdout>, String> {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
r = tokio::time::timeout(READY_TIMEOUT, wait_for_ready(stdout, token)) => match r {
|
|
|
|
|
Ok(Ok(reader)) => Ok(reader),
|
|
|
|
|
Ok(Err(e)) => Err(format!("did not become ready: {e}")),
|
|
|
|
|
Err(_) => Err(format!("not ready after {}s", READY_TIMEOUT.as_secs())),
|
|
|
|
|
},
|
2026-10-09 17:10:15 +00:00
|
|
|
// Any stop request, or appd shutting down, ends a startup.
|
|
|
|
|
_ = abort_rx.recv() => Err("startup aborted".to_owned()),
|
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
|
|
|
}
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 10:14:18 +00:00
|
|
|
async fn wait_for_ready(
|
|
|
|
|
stdout: tokio::process::ChildStdout,
|
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
|
|
|
token: &str,
|
2026-03-11 10:14:18 +00:00
|
|
|
) -> anyhow::Result<BufReader<tokio::process::ChildStdout>> {
|
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
|
|
|
let expected = format!("READY {token}");
|
2026-03-11 10:14:18 +00:00
|
|
|
let mut reader = BufReader::new(stdout);
|
|
|
|
|
loop {
|
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
|
|
|
match read_child_line(&mut reader).await? {
|
|
|
|
|
None => return Err(anyhow::anyhow!("stdout closed without READY signal")),
|
|
|
|
|
// Earlier output without a trailing newline can precede the
|
|
|
|
|
// readiness line; the secret token alone establishes it.
|
|
|
|
|
Some(line) if line.ends_with(&expected) => return Ok(reader),
|
|
|
|
|
Some(_) => {}
|
2026-03-11 10:14:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn drain_stdout(mut reader: BufReader<tokio::process::ChildStdout>, session_id: u64) {
|
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
|
|
|
while let Ok(Some(line)) = read_child_line(&mut reader).await {
|
|
|
|
|
tracing::debug!(session_id, stdout = %line, "child stdout");
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
async fn drain_stderr(stderr: tokio::process::ChildStderr, session_id: u64, process: &str) {
|
|
|
|
|
let mut reader = BufReader::new(stderr);
|
|
|
|
|
while let Ok(Some(line)) = read_child_line(&mut reader).await {
|
|
|
|
|
tracing::info!(session_id, process, stderr = %line, "child stderr");
|
2026-03-11 08:17:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-10-09 00:43:35 +00:00
|
|
|
|
|
|
|
|
#[cfg(all(test, target_os = "linux"))]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::SYSTEMD_SCOPE_ARGS;
|
|
|
|
|
|
2026-10-09 19:39:01 +00:00
|
|
|
fn relay_socket(name: &str) -> std::path::PathBuf {
|
|
|
|
|
std::env::temp_dir().join(format!("weft-relay-{name}-{}.sock", std::process::id()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn a_message_from_the_page_does_not_split_one_from_the_component() {
|
|
|
|
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
|
|
|
let path = relay_socket("split");
|
|
|
|
|
let (broadcast, mut messages) = tokio::sync::broadcast::channel(16);
|
|
|
|
|
let (to_component, mut relay) = super::spawn_ipc_relay(7, path.clone(), broadcast).unwrap();
|
|
|
|
|
let mut component = tokio::net::UnixStream::connect(&path).await.unwrap();
|
|
|
|
|
component.write_all(b"{\"half\":").await.unwrap();
|
|
|
|
|
// The relay starts reading the component's message, then the page's
|
|
|
|
|
// message wins the select.
|
|
|
|
|
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
|
|
|
|
to_component.send("from the page".to_owned()).await.unwrap();
|
|
|
|
|
let mut received = vec![0; 14];
|
|
|
|
|
component.read_exact(&mut received).await.unwrap();
|
|
|
|
|
assert_eq!(received, b"from the page\n");
|
|
|
|
|
component.write_all(b"\"whole\"}\n").await.unwrap();
|
|
|
|
|
let message = tokio::time::timeout(std::time::Duration::from_secs(5), messages.recv())
|
|
|
|
|
.await
|
|
|
|
|
.unwrap()
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(
|
|
|
|
|
matches!(&message, crate::ipc::Response::IpcMessage { session_id: 7, payload } if payload == "{\"half\":\"whole\"}"),
|
|
|
|
|
"{message:?}"
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-09 19:43:20 +00:00
|
|
|
// A message at the limit, ending in a carriage return and line
|
|
|
|
|
// feed, arrives whole.
|
|
|
|
|
let mut at_limit = vec![b'y'; super::MAX_RELAY_FRAME - 2];
|
|
|
|
|
at_limit.extend_from_slice(b"\r\n");
|
|
|
|
|
component.write_all(&at_limit).await.unwrap();
|
|
|
|
|
let message = tokio::time::timeout(std::time::Duration::from_secs(5), messages.recv())
|
2026-10-09 19:39:01 +00:00
|
|
|
.await
|
2026-10-09 19:43:20 +00:00
|
|
|
.unwrap()
|
2026-10-09 19:39:01 +00:00
|
|
|
.unwrap();
|
2026-10-09 19:43:20 +00:00
|
|
|
assert!(
|
|
|
|
|
matches!(&message, crate::ipc::Response::IpcMessage { payload, .. } if payload.len() == super::MAX_RELAY_FRAME - 2),
|
|
|
|
|
"a message at the limit did not arrive whole"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// A line longer than any message ends the relay, even when its line
|
|
|
|
|
// break comes in the same read.
|
|
|
|
|
let mut over = vec![b'x'; super::MAX_RELAY_FRAME];
|
|
|
|
|
over.push(b'\n');
|
|
|
|
|
component.write_all(&over).await.unwrap();
|
2026-10-09 19:39:01 +00:00
|
|
|
tokio::time::timeout(std::time::Duration::from_secs(5), relay.ended())
|
|
|
|
|
.await
|
|
|
|
|
.expect("the relay did not end on an overlong line");
|
|
|
|
|
assert!(messages.try_recv().is_err());
|
|
|
|
|
drop(relay);
|
|
|
|
|
assert!(!path.exists());
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 00:43:35 +00:00
|
|
|
/// systemd-run checks its options and their combinations before it
|
|
|
|
|
/// connects to the service manager. Run against an empty runtime
|
|
|
|
|
/// directory and bus address, it must get as far as the connection
|
|
|
|
|
/// attempt; any option error ends earlier with a different message. This
|
|
|
|
|
/// does not validate the `-p` property values, which only the manager
|
|
|
|
|
/// checks, and never starts a real scope.
|
|
|
|
|
#[test]
|
|
|
|
|
fn systemd_run_accepts_scope_options() {
|
|
|
|
|
let empty = std::env::temp_dir().join(format!("weft-scope-test-{}", std::process::id()));
|
|
|
|
|
std::fs::create_dir_all(&empty).unwrap();
|
|
|
|
|
let output = std::process::Command::new("systemd-run")
|
|
|
|
|
.args(SYSTEMD_SCOPE_ARGS)
|
|
|
|
|
.args(["--", "true"])
|
|
|
|
|
.env_clear()
|
|
|
|
|
.env("PATH", std::env::var_os("PATH").unwrap_or_default())
|
|
|
|
|
.env("LC_ALL", "C")
|
|
|
|
|
.env("XDG_RUNTIME_DIR", &empty)
|
|
|
|
|
.env(
|
|
|
|
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
|
|
|
format!("unix:path={}/bus", empty.display()),
|
|
|
|
|
)
|
|
|
|
|
.output();
|
|
|
|
|
std::fs::remove_dir_all(&empty).unwrap();
|
|
|
|
|
let output = output.expect("systemd-run is required to check the scope options");
|
|
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
|
|
|
// systemd 255 says "Failed to connect to bus"; later releases name the
|
|
|
|
|
// transport, e.g. "Failed to connect to user scope bus via local transport".
|
|
|
|
|
assert!(
|
|
|
|
|
stderr.starts_with("Failed to connect to"),
|
|
|
|
|
"systemd-run did not reach the manager connection: {stderr}"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|