Skip to main content

agentmux_srv/server/service/
window_close.rs

1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `window` service handler — `CloseWindow`. Split out of `window.rs`;
5//! see that file's dispatcher for the full method list.
6
7use crate::backend::obj::*;
8use crate::backend::service::{self, WebCallType, WebReturnType};
9
10use super::super::AppState;
11use super::reducer_helpers::{dispatch_to_reducer, publish_events};
12
13// Phase E.5.8 — CloseWindow migrated through the reducer.
14// Sequence:
15//   1. Look up the window's workspace, and where the window is.
16//   2. Dispatch Command::CloseWindowInternal — emits
17//      SrvWindowClosed; subscriber prunes Client.windowids.
18//   3. If no other window points at the same workspace (the window's
19//      contents), keep it (`session_closed::keep_workspace`: its agents
20//      stop, its tabs and panes stay, and the window stays in the open
21//      workspace as a closed window), or delete it when the window was
22//      removed from the workspace.
23// Closing is not deleting: SPEC_WORKSPACES_2026_10_23.md §2, §5.
24pub(crate) async fn handle_close_window(state: &AppState, call: &WebCallType) -> WebReturnType {
25    let store = &state.mstore;
26    let args = &call.args;
27    let window_id: String = match service::get_arg(args, 0) {
28        Ok(v) => v,
29        Err(e) => return WebReturnType::error(e),
30    };
31    // Look up the window's workspace before we close it.
32    // Read SQLite (source of truth during migration).
33    // And its name, appearance and placement, which the session record and
34    // the closed-window list keep: the row is gone by then.
35    let (ws_id, closing): (Option<String>, ClosingWindow) = match store.get::<Window>(&window_id) {
36        Ok(Some(w)) => (
37            Some(w.workspaceid.clone()),
38            ClosingWindow {
39                name: super::session_windows::saved_name(store, &w),
40                appearance: super::session_windows::saved_appearance(store, &w),
41                placement: super::session_closed::placement_of(store, &w),
42            },
43        ),
44        Ok(None) => (None, ClosingWindow::default()),
45        Err(e) => {
46            return WebReturnType::error(format!(
47                "CloseWindow: window lookup failed: {}",
48                e
49            ));
50        }
51    };
52    // Step 1: drop the window mapping in reducer.
53    let close_events = dispatch_to_reducer(
54        state,
55        agentmux_common::ipc::Command::CloseWindowInternal {
56            window_id: window_id.clone(),
57        },
58    )
59    .await;
60    // reagent P1 #622: surface reducer rejection before
61    // applying / publishing. Every other primary dispatch in
62    // this PR follows this pattern; CloseWindow was missing it.
63    if let Some(err_msg) = close_events.iter().find_map(|e| match e {
64        agentmux_common::ipc::Event::Error { message, .. } => Some(message.clone()),
65        _ => None,
66    }) {
67        return WebReturnType::error(err_msg);
68    }
69    // #2051 — the reducer's CloseWindowInternal is an idempotent
70    // silent no-op on unknown ids (no event emitted). The SQLite
71    // prune below only runs off the SrvWindowClosed event, so
72    // without this branch a window the reducer never knew
73    // (bootstrap skipped it, or state/store desync) returns 200
74    // while its `Client.windowids` entry and Window row survive
75    // forever — the leak class that fueled the #2048 window
76    // storm. Prune the durable store directly and warn about the
77    // divergence; a window that is gone from BOTH sides stays a
78    // clean idempotent success.
79    if close_events.is_empty() {
80        let had_row = ws_id.is_some();
81        let had_client_entry = store
82            .get_all::<Client>()
83            .ok()
84            .and_then(|cs| cs.into_iter().next())
85            .map(|c| c.windowids.iter().any(|id| id == &window_id))
86            .unwrap_or(false);
87        if !had_row && !had_client_entry {
88            return WebReturnType::success_empty();
89        }
90        tracing::warn!(
91            window_id = %window_id,
92            had_row,
93            had_client_entry,
94            "CloseWindow: window unknown to the reducer but still present in the \
95             store — pruning defensively (#2051)"
96        );
97        if let Err(e) =
98            crate::persist_subscriber::apply_srv_window_closed(store, &window_id)
99        {
100            return WebReturnType::error(format!(
101                "CloseWindow: divergence prune failed: {}",
102                e
103            ));
104        }
105        // Same guarded cascade as the normal path below, but
106        // judged from the store (the reducer has no record of
107        // this window's workspace peers). The prune above already
108        // deleted this window's own row, so any remaining
109        // reference means the workspace is genuinely shared. On a
110        // read error keep the workspace — losing user tabs is
111        // worse than leaking an empty workspace row.
112        if let Some(ws_id) = ws_id {
113            let any_other_window = store
114                .get_all::<Window>()
115                .map(|ws| ws.iter().any(|w| w.workspaceid == ws_id))
116                .unwrap_or(true);
117            if !any_other_window {
118                close_unshown_workspace(state, &window_id, ws_id, closing).await;
119            }
120        }
121        return WebReturnType::success_empty();
122    }
123    for ev in &close_events {
124        if let Err(e) = crate::persist_subscriber::apply_event_to_mstore(ev, store) {
125            return WebReturnType::error(format!(
126                "CloseWindow: SQLite write failed: {}",
127                e
128            ));
129        }
130    }
131    publish_events(state, &close_events);
132    // Step 2: the workspace, if no other window points at it. The
133    // reducer keeps state.windows updated; check there.
134    if let Some(ws_id) = ws_id {
135        let any_other_window = {
136            let s = state.srv_state.lock().await;
137            s.windows.values().any(|w| w.workspace_id == ws_id)
138        };
139        if !any_other_window {
140            close_unshown_workspace(state, &window_id, ws_id, closing).await;
141        }
142    }
143    // Subscriber's apply_srv_window_closed already pruned
144    // Client.windowids and deleted the Window row; nothing
145    // more for the handler to do.
146    WebReturnType::success_empty()
147}
148
149/// What a session record and the closed windows keep of a closing window,
150/// read before its row is pruned.
151#[derive(Default)]
152struct ClosingWindow {
153    name: Option<String>,
154    appearance: serde_json::Map<String, serde_json::Value>,
155    placement: serde_json::Value,
156}
157
158/// `ws_id` lost its last window (`window_id`, now closed).
159///
160/// The close that empties `Client.windowids` is the end of the session: it
161/// first saves the session record (restore-on-relaunch,
162/// SPEC_SESSION_RESTORE_AND_SAVED_LAYOUTS_2026_08_13 Feature 1), naming the
163/// kept contents, so the next launch reopens them and rebuilds them from the
164/// record only if they are gone. Asked after this close's own prune and read
165/// fresh: of two concurrent closes that end a session, one sees it empty. Not
166/// asked for workspace sharing, which is true of nearly every close.
167///
168/// The contents are then kept (`session_closed::keep_workspace`), as a closed
169/// window unless this close ended the session, or deleted when the window was
170/// removed from the workspace (`DiscardWorkspaceOnClose`), which saves no
171/// record of it.
172async fn close_unshown_workspace(state: &AppState, window_id: &str, ws_id: String, closing: ClosingWindow) {
173    let store = &state.mstore;
174    let discard = super::session_closed::take_discard(window_id);
175    let will_empty_windowids = store
176        .get_all::<Client>()
177        .ok()
178        .and_then(|cs| cs.into_iter().next())
179        .map(|c| c.windowids.is_empty())
180        .unwrap_or(false);
181    // Best-effort: a failure here must never block the close itself.
182    if will_empty_windowids && !discard {
183        super::session_windows::save_on_last_close(store, &ws_id, closing.name.as_deref(), &closing.appearance);
184    }
185    if discard {
186        tracing::info!(workspace_id = %ws_id, "CloseWindow: removed from the workspace; deleting its contents");
187        super::session_closed::forget(store, &ws_id);
188        close_workspace(state, ws_id).await;
189    } else {
190        super::session_closed::keep_workspace(state, ws_id, closing.placement, will_empty_windowids, None).await;
191    }
192}
193
194/// Delete a window's contents no window shows, every agent in it closed
195/// gracefully first (`agent_teardown`, `Policy::close()`): a window removed
196/// from the workspace, open or closed, or one with nothing to keep.
197///
198/// Detached (`agent_teardown::detached`): the host waits only 2 s for
199/// `CloseWindow`, less than a graceful close takes, and when it hangs up
200/// this handler is dropped. The close still finishes, and on app exit srv
201/// waits for it.
202///
203/// A workspace the reducer tracks goes through the `delete_workspace` saga
204/// (reducer and store stay consistent, durable provenance). One it never
205/// knew — the usual case when its window diverged too (#2051) — would make
206/// the saga's reducer dispatch error out, so its agents are closed here, the
207/// store cascades directly, and each block's close is finished as the saga
208/// would (`close_pane::finish_close`).
209pub(crate) async fn close_workspace(state: &AppState, ws_id: String) {
210    super::session_slots::forget(&state.mstore, &ws_id);
211    let st = state.clone();
212    let done = crate::sagas::agent_teardown::detached(async move {
213        let reducer_knows_ws = st.srv_state.lock().await.workspaces.contains_key(&ws_id);
214        let result = if reducer_knows_ws {
215            crate::sagas::delete_workspace::run(&st, ws_id.clone()).await.map(|_| ())
216        } else {
217            let block_ids = store_block_ids(&st.mstore, &ws_id);
218            crate::sagas::agent_teardown::run_many(&st, &block_ids, crate::sagas::agent_teardown::Policy::close())
219                .await;
220            let deleted = crate::backend::wcore::delete_workspace(&st.mstore, &ws_id).map_err(|e| e.to_string());
221            for block_id in &block_ids {
222                crate::sagas::close_pane::finish_close(&st, block_id).await;
223            }
224            deleted
225        };
226        if let Err(e) = result {
227            tracing::warn!(workspace_id = %ws_id, reducer_knows_ws, "CloseWindow: workspace delete failed: {}", e);
228        }
229    })
230    .await;
231    if done.is_none() {
232        tracing::warn!("CloseWindow: the workspace close task panicked");
233    }
234}
235
236/// A workspace switch closes window `window_id` (`user_workspace_switch`):
237/// the window's row goes, as `CloseWindow` drops it, and its contents stay
238/// for the caller to keep. The host closes the OS window afterwards; that
239/// close then finds nothing left to do. Returns the contents when no other
240/// window shows them.
241pub(crate) async fn detach_window(state: &AppState, window_id: &str) -> Result<Option<String>, String> {
242    let store = &state.mstore;
243    let Some(ws_id) = store.get::<Window>(window_id).map_err(|e| e.to_string())?.map(|w| w.workspaceid) else {
244        return Ok(None);
245    };
246    let events = dispatch_to_reducer(
247        state,
248        agentmux_common::ipc::Command::CloseWindowInternal { window_id: window_id.to_string() },
249    )
250    .await;
251    if let Some(err) = events.iter().find_map(|e| match e {
252        agentmux_common::ipc::Event::Error { message, .. } => Some(message.clone()),
253        _ => None,
254    }) {
255        return Err(err);
256    }
257    if events.is_empty() {
258        // A window the reducer never knew (#2051): prune the store directly.
259        crate::persist_subscriber::apply_srv_window_closed(store, window_id).map_err(|e| e.to_string())?;
260    }
261    for ev in &events {
262        crate::persist_subscriber::apply_event_to_mstore(ev, store).map_err(|e| e.to_string())?;
263    }
264    publish_events(state, &events);
265    let shown = store.get_all::<Window>().map(|ws| ws.iter().any(|w| w.workspaceid == ws_id)).unwrap_or(true);
266    Ok((!shown).then_some(ws_id))
267}
268
269/// Every block in a workspace's tabs (regular and pinned), read from the store.
270pub(crate) fn store_block_ids(store: &crate::backend::storage::store::Store, ws_id: &str) -> Vec<String> {
271    let Ok(Some(ws)) = store.get::<Workspace>(ws_id) else { return Vec::new() };
272    ws.tabids
273        .iter()
274        .chain(ws.pinnedtabids.iter())
275        .filter_map(|tid| store.get::<Tab>(tid).ok().flatten())
276        .flat_map(|t| t.blockids)
277        .collect()
278}
279
280/// #2051 — `CloseWindow` divergence-path tests: the reducer's
281/// `CloseWindowInternal` silently no-ops on ids it never knew, and the
282/// SQLite prune normally rides the `SrvWindowClosed` event — so a window
283/// present only in the store used to survive a "successful" CloseWindow
284/// forever (the leak class behind the #2048 window storm). These pin the
285/// handler's direct-prune fallback.
286#[cfg(test)]
287mod close_window_divergence_tests {
288    use super::super::window::handle_window_service;
289    use crate::backend::obj::{Client, Window, Workspace};
290    use crate::backend::service::WebCallType;
291    use crate::backend::wcore;
292    use crate::server::tests::test_state;
293
294    fn close_call(window_id: &str) -> WebCallType {
295        WebCallType {
296            service: "window".to_string(),
297            method: "CloseWindow".to_string(),
298            uicontext: None,
299            args: vec![serde_json::Value::String(window_id.to_string())],
300        }
301    }
302
303    fn client_has_window(state: &crate::server::AppState, window_id: &str) -> bool {
304        state
305            .mstore
306            .get_all::<Client>()
307            .unwrap()
308            .into_iter()
309            .next()
310            .map(|c| c.windowids.iter().any(|id| id == window_id))
311            .unwrap_or(false)
312    }
313
314    /// A window written straight to the store (`wcore::create_window`
315    /// bypasses the reducer — exactly how bootstrap-skipped rows and
316    /// pre-reducer desyncs look) must still be fully pruned by
317    /// CloseWindow: success, row gone, `Client.windowids` entry gone,
318    /// and its now-orphaned workspace cascade-deleted.
319    #[tokio::test]
320    async fn store_only_window_is_pruned_and_workspace_cascades() {
321        let state = test_state();
322        let win = wcore::create_window_full(&state.mstore, "").unwrap();
323        assert!(client_has_window(&state, &win.oid), "precondition: windowids entry");
324        assert!(
325            !state.srv_state.lock().await.windows.contains_key(&win.oid),
326            "precondition: reducer must NOT know this window"
327        );
328
329        let ret = handle_window_service(&state, &close_call(&win.oid)).await;
330        assert!(ret.success, "divergent CloseWindow failed: {:?}", ret.error);
331
332        assert!(
333            state.mstore.get::<Window>(&win.oid).unwrap().is_none(),
334            "Window row must be deleted"
335        );
336        assert!(
337            !client_has_window(&state, &win.oid),
338            "Client.windowids entry must be pruned"
339        );
340        assert!(
341            state.mstore.get::<Workspace>(&win.workspaceid).unwrap().is_none(),
342            "orphaned workspace must cascade-delete"
343        );
344    }
345
346    /// A workspace still referenced by another window must survive the
347    /// divergence-path cascade guard.
348    #[tokio::test]
349    async fn shared_workspace_survives_divergent_close() {
350        let state = test_state();
351        let first = wcore::create_window_full(&state.mstore, "").unwrap();
352        let second =
353            wcore::create_window_full(&state.mstore, &first.workspaceid).unwrap();
354
355        let ret = handle_window_service(&state, &close_call(&first.oid)).await;
356        assert!(ret.success, "divergent CloseWindow failed: {:?}", ret.error);
357
358        assert!(
359            state.mstore.get::<Workspace>(&first.workspaceid).unwrap().is_some(),
360            "workspace referenced by another window must survive"
361        );
362        assert!(
363            state.mstore.get::<Window>(&second.oid).unwrap().is_some(),
364            "the other window must be untouched"
365        );
366    }
367
368    /// A window gone from BOTH the reducer and the store stays a clean
369    /// idempotent success — no error, no phantom prune.
370    #[tokio::test]
371    async fn truly_missing_window_is_an_idempotent_success() {
372        let state = test_state();
373        let ret = handle_window_service(&state, &close_call("no-such-window")).await;
374        assert!(ret.success, "idempotent CloseWindow failed: {:?}", ret.error);
375    }
376}
377
378/// Restore-on-relaunch snapshot-timing regression tests
379/// (SPEC_SESSION_RESTORE_AND_SAVED_LAYOUTS_2026_08_13.md Feature 1).
380/// Reviewer-caught bug (reagentx P1 on PR #2560): the original
381/// implementation snapshotted unconditionally on every window close, so
382/// closing a second, independent window AFTER the real session's window
383/// would silently overwrite the correct snapshot with the second window's
384/// (typically much smaller) content — since each window normally owns its
385/// own 1:1 workspace, "does this close destroy its own workspace" was true
386/// for nearly every close, not a useful filter. These pin the fix: the
387/// snapshot now only fires on the close that actually empties
388/// `Client.windowids` — the same condition the read side already requires.
389#[cfg(test)]
390mod snapshot_timing_tests {
391    use super::super::window::handle_window_service;
392    use super::super::window_create::handle_create_window;
393    use crate::backend::obj::{Client, Tab, Window, Workspace};
394    use crate::backend::service::WebCallType;
395    use crate::server::tests::test_state;
396
397    fn close_call(window_id: &str) -> WebCallType {
398        WebCallType {
399            service: "window".to_string(),
400            method: "CloseWindow".to_string(),
401            uicontext: None,
402            args: vec![serde_json::Value::String(window_id.to_string())],
403        }
404    }
405
406    async fn create_window(state: &crate::server::AppState) -> Window {
407        let call = WebCallType {
408            service: "window".to_string(),
409            method: "CreateWindow".to_string(),
410            uicontext: None,
411            args: vec![serde_json::Value::Null, serde_json::Value::String(String::new())],
412        };
413        let resp = handle_create_window(state, &call).await;
414        assert!(resp.success, "CreateWindow failed: {:?}", resp.error);
415        serde_json::from_value(resp.data.unwrap()).unwrap()
416    }
417
418    fn rename_first_tab(state: &crate::server::AppState, workspace_id: &str, name: &str) {
419        let ws = state.mstore.get::<Workspace>(workspace_id).unwrap().unwrap();
420        let mut tab = state.mstore.get::<Tab>(&ws.tabids[0]).unwrap().unwrap();
421        tab.name = name.to_string();
422        state.mstore.update(&mut tab).unwrap();
423    }
424
425    fn last_session_snapshot_tab_name(state: &crate::server::AppState) -> Option<String> {
426        let client = state.mstore.get_all::<Client>().unwrap().into_iter().next()?;
427        let snapshot = client.meta.get("session:last_topology")?;
428        snapshot["tabs"][0]["name"].as_str().map(|s| s.to_string())
429    }
430
431    /// `test_state()` seeds a "Starter workspace" bootstrap window
432    /// (`wcore::ensure_initial_data`) before any test code runs — without
433    /// closing it first, `Client.windowids` always has that extra entry, so
434    /// `will_empty_windowids` never actually goes true in these tests no
435    /// matter how many test-created windows get closed. Close it before
436    /// setting up a test's own "N independent windows" scenario.
437    async fn close_bootstrap_window(state: &crate::server::AppState) {
438        let bootstrap_id = state
439            .mstore
440            .get_all::<Client>()
441            .unwrap()
442            .into_iter()
443            .next()
444            .unwrap()
445            .windowids[0]
446            .clone();
447        let ret = handle_window_service(state, &close_call(&bootstrap_id)).await;
448        assert!(ret.success, "closing bootstrap window failed: {:?}", ret.error);
449    }
450
451    /// The core fix: with two independent windows open, closing the FIRST
452    /// one (the other is still open — `Client.windowids` does NOT empty)
453    /// must not touch the snapshot at all. Only closing the SECOND (last)
454    /// window may write one. Under the pre-fix code (unconditional
455    /// snapshot-on-every-close) this test fails at the first assertion —
456    /// the first close already wrote a snapshot.
457    #[tokio::test]
458    async fn closing_one_of_two_open_windows_does_not_touch_the_snapshot() {
459        let state = test_state();
460        // Closing the lone bootstrap window IS a genuine terminal close (it
461        // empties `Client.windowids` on its own), so it legitimately writes
462        // a snapshot of its own — capture that as the baseline rather than
463        // assuming "no snapshot yet".
464        close_bootstrap_window(&state).await;
465        let snapshot_after_bootstrap_close = last_session_snapshot_tab_name(&state);
466
467        let first = create_window(&state).await;
468        rename_first_tab(&state, &first.workspaceid, "first-window-tab");
469        let second = create_window(&state).await;
470        rename_first_tab(&state, &second.workspaceid, "second-window-tab");
471
472        // Close the FIRST window while the second is still open.
473        let ret = handle_window_service(&state, &close_call(&first.oid)).await;
474        assert!(ret.success, "CloseWindow failed: {:?}", ret.error);
475
476        assert_eq!(
477            last_session_snapshot_tab_name(&state),
478            snapshot_after_bootstrap_close,
479            "closing one of two open windows must not write a snapshot — \
480             the session hasn't actually ended yet"
481        );
482
483        // Now close the SECOND (last) window — this is the real end of the
484        // session, and must snapshot the second window's own content.
485        let ret = handle_window_service(&state, &close_call(&second.oid)).await;
486        assert!(ret.success, "CloseWindow failed: {:?}", ret.error);
487
488        assert_eq!(
489            last_session_snapshot_tab_name(&state).as_deref(),
490            Some("second-window-tab"),
491            "the terminal close must snapshot ITS OWN (last) window's content"
492        );
493    }
494
495    /// Direct regression for the reviewer's exact scenario: close the
496    /// window with the "real" session first, then a smaller second window
497    /// — the smaller window's close (being the one that actually empties
498    /// `Client.windowids`) legitimately becomes the final snapshot, but the
499    /// key guarantee is that this reflects a real, coherent design decision
500    /// (snapshot = "whatever was open at the moment of full quit") rather
501    /// than an arbitrary race between two unconditional writes.
502    #[tokio::test]
503    async fn snapshot_reflects_whichever_close_actually_empties_windowids() {
504        let state = test_state();
505        // See `closing_one_of_two_open_windows_does_not_touch_the_snapshot`:
506        // closing the lone bootstrap window is itself a terminal close, so
507        // it writes a snapshot — capture that as the baseline.
508        close_bootstrap_window(&state).await;
509        let snapshot_after_bootstrap_close = last_session_snapshot_tab_name(&state);
510
511        let main = create_window(&state).await;
512        rename_first_tab(&state, &main.workspaceid, "main-session");
513        let tearoff = create_window(&state).await;
514        rename_first_tab(&state, &tearoff.workspaceid, "tiny-tearoff");
515
516        // Close "main" first — does NOT empty windowids (tearoff still open).
517        let ret = handle_window_service(&state, &close_call(&main.oid)).await;
518        assert!(ret.success);
519        assert_eq!(
520            last_session_snapshot_tab_name(&state),
521            snapshot_after_bootstrap_close,
522            "closing main first must not snapshot — it isn't the terminal close"
523        );
524
525        // Close "tearoff" last — THIS empties windowids, so it (correctly,
526        // by definition of "what was open at full quit") is what's saved.
527        let ret = handle_window_service(&state, &close_call(&tearoff.oid)).await;
528        assert!(ret.success);
529        assert_eq!(
530            last_session_snapshot_tab_name(&state).as_deref(),
531            Some("tiny-tearoff")
532        );
533    }
534
535    /// reagentx P1 on PR #2560 (re-review): `will_empty_windowids` used to
536    /// be computed once at function entry, off a snapshot of
537    /// `Client.windowids` taken BEFORE this call's own dispatch mutated
538    /// anything. Under genuine concurrent overlap (two `CloseWindow` calls
539    /// as part of one multi-window quit), each could read "the other
540    /// window is still there" and both conclude `will_empty_windowids =
541    /// false` — losing the snapshot entirely even though the user closed
542    /// everything. Reading fresh, after each call's own prune has already
543    /// landed, closes that gap: whichever close actually observes an empty
544    /// `Client.windowids` afterward saves a snapshot, so at least one of
545    /// two concurrent terminal closes always does.
546    #[tokio::test]
547    async fn concurrent_close_of_the_last_two_windows_still_saves_a_snapshot() {
548        let state = test_state();
549        close_bootstrap_window(&state).await;
550
551        let first = create_window(&state).await;
552        rename_first_tab(&state, &first.workspaceid, "first-window-tab");
553        let second = create_window(&state).await;
554        rename_first_tab(&state, &second.workspaceid, "second-window-tab");
555
556        let first_call = close_call(&first.oid);
557        let second_call = close_call(&second.oid);
558        let (ret1, ret2) = tokio::join!(
559            handle_window_service(&state, &first_call),
560            handle_window_service(&state, &second_call),
561        );
562        assert!(ret1.success, "first concurrent close failed: {:?}", ret1.error);
563        assert!(ret2.success, "second concurrent close failed: {:?}", ret2.error);
564
565        assert!(
566            last_session_snapshot_tab_name(&state).is_some(),
567            "closing the last two windows concurrently must still save SOME \
568             snapshot, not lose it entirely"
569        );
570    }
571}