From e72c55c87cbcc23f03197297435901b52ca07e68 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 16:45:25 +0000 Subject: [PATCH] fix(appd): tell every client that a session is closing TERMINATE_APP broadcasts the Stopping state, so every system UI marks the entry. A closing taskbar entry is marked once and no longer sends ACTIVATE_APP. The docs describe which stopped sessions are kept. --- crates/weft-appd/src/main.rs | 13 ++++++++++++- docs/architecture.md | 2 +- infra/shell/system-ui.html | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/weft-appd/src/main.rs b/crates/weft-appd/src/main.rs index 277c40a..8cb687d 100644 --- a/crates/weft-appd/src/main.rs +++ b/crates/weft-appd/src/main.rs @@ -567,7 +567,18 @@ pub(crate) async fn dispatch(req: Request, registry: &Registry) -> Response { Response::LaunchAck { session_id, app_id } } Request::TerminateApp { session_id } => { - let found = registry.lock().await.terminate(session_id); + let found = { + let mut reg = registry.lock().await; + let found = reg.terminate(session_id); + if found && matches!(reg.state(session_id), AppStateKind::Stopping) { + // Every client, not only the requester, shows the close. + let _ = reg.broadcast().send(Response::AppState { + session_id, + state: AppStateKind::Stopping, + }); + } + found + }; if found { tracing::info!(session_id, "stop requested"); Response::AppState { diff --git a/docs/architecture.md b/docs/architecture.md index c600cdc..d0448bc 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -20,7 +20,7 @@ Per-application Servo host. Spawned by `weft-appd` after the Wasm runtime signal ### weft-appd -Session supervisor. Listens on a Unix socket (MessagePack protocol) and a WebSocket port (JSON). Before a session exists, appd resolves the package once (see [Package resolution](#package-resolution)) and derives its grants from that package's manifest; the runtime and the app shell receive the resolved component and UI document and do not search the stores themselves. For each session: spawns `weft-runtime` and waits for its READY, spawns `weft-app-shell` (`WEFT_APP_SHELL_BIN` is required) and waits for its READY, and only then reports the session running (`APP_READY`). A child reports readiness by printing `READY ` on stdout, where the token is a random per-session value appd passes in `WEFT_READY_TOKEN`; Wasm guests and pages share those stdout streams but cannot read the token, so their output cannot fake readiness. Each wait times out after 30 seconds. `TERMINATE_APP` on a running session closes it as a user close would: appd replies `stopping`, asks the compositor to close the session's windows, and gives the app shell 5 seconds to exit by itself, for example after saving, before terminating it; the stop reason records which happened (a clean exit, a failure while closing, or the timeout), and `stopped` is broadcast once the session has settled. A repeated `TERMINATE_APP` while the app is closing changes nothing; the timeout is the only forced termination, and a session being closed is not restored at the next start. appd keeps the final state of the 32 most recently stopped sessions. A session still starting is stopped at once, and when appd itself shuts down its sessions are terminated without a close. If either child fails to start, fails to become ready or exits, or the session is terminated, the whole session is stopped: both children, the IPC relay (its task, socket and registered sender), the file portal, the compositor association and any image mount are released. The IPC relay is created with the session in `$XDG_RUNTIME_DIR/weft` (a session cannot start without it); its socket is accessible only to the user and accepts a single connection, which the session's runtime makes before it starts the component. If that connection closes while the session runs, the session is stopped. `IPC_FORWARD` on the Unix socket never waits: it reports an error when the session has no relay or its queue is full. appd applies cgroup resource limits to the runtime via systemd-run when available. +Session supervisor. Listens on a Unix socket (MessagePack protocol) and a WebSocket port (JSON). Before a session exists, appd resolves the package once (see [Package resolution](#package-resolution)) and derives its grants from that package's manifest; the runtime and the app shell receive the resolved component and UI document and do not search the stores themselves. For each session: spawns `weft-runtime` and waits for its READY, spawns `weft-app-shell` (`WEFT_APP_SHELL_BIN` is required) and waits for its READY, and only then reports the session running (`APP_READY`). A child reports readiness by printing `READY ` on stdout, where the token is a random per-session value appd passes in `WEFT_READY_TOKEN`; Wasm guests and pages share those stdout streams but cannot read the token, so their output cannot fake readiness. Each wait times out after 30 seconds. `TERMINATE_APP` on a running session closes it as a user close would: appd replies `stopping`, asks the compositor to close the session's windows, and gives the app shell 5 seconds to exit by itself, for example after saving, before terminating it; the stop reason records which happened (a clean exit, a failure while closing, or the timeout), and `stopped` is broadcast once the session has settled. A repeated `TERMINATE_APP` while the app is closing changes nothing; the timeout is the only forced termination, and a session being closed is not restored at the next start. appd keeps the final state of at most 32 stopped sessions, forgetting those launched earliest. A session still starting is stopped at once, and when appd itself shuts down its sessions are terminated without a close. If either child fails to start, fails to become ready or exits, or the session is terminated, the whole session is stopped: both children, the IPC relay (its task, socket and registered sender), the file portal, the compositor association and any image mount are released. The IPC relay is created with the session in `$XDG_RUNTIME_DIR/weft` (a session cannot start without it); its socket is accessible only to the user and accepts a single connection, which the session's runtime makes before it starts the component. If that connection closes while the session runs, the session is stopped. `IPC_FORWARD` on the Unix socket never waits: it reports an error when the session has no relay or its queue is full. appd applies cgroup resource limits to the runtime via systemd-run when available. ### weft-runtime diff --git a/infra/shell/system-ui.html b/infra/shell/system-ui.html index bf28f85..25c6157 100644 --- a/infra/shell/system-ui.html +++ b/infra/shell/system-ui.html @@ -404,6 +404,7 @@ el.appendChild(close); // Choosing the entry brings the app's window to the front. el.addEventListener('click', function () { + if (el.dataset.closing) { return; } if (ws && ws.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({ type: 'ACTIVATE_APP', session_id: sessionId })); } @@ -417,7 +418,8 @@ // example to save; the entry stays until the session has stopped. function markTaskbarEntryClosing(sessionId) { var el = document.getElementById('task-' + sessionId); - if (!el) { return; } + if (!el || el.dataset.closing) { return; } + el.dataset.closing = '1'; el.style.opacity = '0.5'; el.title += ' (closing)'; var close = el.querySelector('.task-close');