Skip to main content

Module session_windows

Module session_windows 

Source
Expand description

Every window comes back after a quit, an upgrade’s included (docs/specs/SPEC_UPGRADE_FOR_USERS_AND_AGENTS_2026_10_15.md §6.1).

The session record (session_restore, Client.meta["session:last_topology"]) held one workspace: the last window’s, saved by the close that emptied Client.windowids. A quit closes the windows one by one and each close deletes its workspace, so with several windows open only the last came back.

Now:

  • a quit asks srv for the whole session before any window closes (SaveSessionSnapshot with for_quit, from the host’s quit_app), and so does the OS-shutdown flush: one entry per window in windows, the main window first, each the shape snapshot_workspace makes plus the window’s position and size under window;
  • the close that then empties Client.windowids keeps a quit’s record instead of replacing it with its own workspace (save_on_last_close);
  • restore rebuilds the first entry into the window being created, as before, and every other entry into a workspace of its own, which the main window then opens each where it was (TakeRestoredWindows, then the host’s open_restored_window).

Names come back too: each window’s own (window:displayname, under window.name) and its workspace’s (name). The restore names each workspace as it creates it.

So does each window’s appearance: its own theme and opacity (window:theme, window:opacity, INHERITED_KEYS), under window.meta. They live only on the Window row, and a quit deletes the row, so without this every quit and relaunch put them back to the defaults (RCA_UPGRADE_0_59_30_TO_0_59_34_ISSUES_2026_10_19.md §2). window:transparent is not among them: it is a setting of the whole app, in settings.json.

A window’s name and appearance wait in the client’s meta (session:restored_window_names, by workspace) for the window that opens onto that workspace, which CreateWindow writes onto its row (restored_window_meta), and is forgotten only once that is written (forget_restored_window_meta). The value is the window’s meta patch; the bare name an earlier version left still reads.

The record keeps the main window’s tabs at its top level too, the shape it always had, so an older AgentMux reading it still restores that window. A record without windows reads as one window.

Constants§

NAMES_META_KEY 🔒
Restored windows’ names and appearance, by workspace, waiting for their windows. (Named for what it first held: a name.)
NAME_KEY 🔒
The Window meta key of the name the user gave the window.
OPENING_META_KEY 🔒
Restored workspaces the main window took (TakeRestoredWindows) and is opening: kept for saves until a window shows each, so a save in between doesn’t drop one that opens slowly or not at all (#5358).
QUIT_RECORD_KEPT_FOR_MS 🔒
How long a quit’s record outranks the last close’s: a quit closes every window within seconds, and one that stalls longer than this was abandoned.
RESTORE_LIST_KEYS 🔒
The client meta keys of the restored windows’ queues.
WAITING_META_KEY 🔒
Restored workspaces waiting for the main window to open them.

Functions§

forget_restore_lists 🔒
Forget the restored windows waiting to open, those opening, and their names: they belong to the workspace that was open, which a switch closes (user_workspace_switch).
forget_restored_window_meta 🔒
ws_id’s window has its meta: forget it, once. Read, remove and write back in one transaction: restored windows open together, and two of these must not each write back the entry the other removed.
forget_windows_left_by_quit 🔒
At startup, before anything reads the windows: when the last run ended in a quit that saved every window (the record is a quit’s), a window still listed is one whose close didn’t reach srv before it stopped. The host closes windows concurrently and srv can exit first; seen in a simulated upgrade, where the second window’s row survived and the main window then took it instead of restoring the session. The record holds that window, so forget its row: the first window then restores every window as designed. Its workspace stays when the record names it (the restore reopens it), and goes with its tabs and panes when it doesn’t (a record an older build wrote, which rebuilds it instead). Only the windows the quit saved (its window_ids) are forgotten: a record left from an older quit never costs a later run its windows. Returns how many it forgot.
handle_take_restored_windows 🔒
window.TakeRestoredWindows: the workspaces a restore rebuilt beside the main window’s, each with its saved placement (workspaceid, x, y, width, height), for the main window to open. Handed out once; one whose workspace is gone since is left out.
has_live_window 🔒
Whether any live window has a workspace to capture.
is_recent_quit_record 🔒
Whether record is a quit’s, saved within the last two minutes: the closes of that quit are still arriving.
live_windows 🔒
The live full windows, the main one first, each with its workspace. Subwindows belong to their parent’s window; a window whose workspace is gone, or an id with no window row, is skipped.
open_workspace_ids 🔒
The workspaces some open window shows, a subwindow’s included: a pane in one of them is on screen.
patch_of 🔒
The meta patch a record entry’s window section gives its restored window: the name, and the appearance that is a theme (a string) and an opacity (a number). Nothing else a record says reaches a row.
queue_restored_windows 🔒
Add restored workspaces for the main window to open beside it (entries: placement plus workspaceid, as restore_all queues them) and their windows’ meta patches, keeping any already waiting.
restore_all 🔒
Restore every window in record: the first that comes back is the one being created (returned, as restore_last_session always did); each other one gets a workspace of its own, published and left for handle_take_restored_windows. A workspace record’s closed windows ("state": "closed") stay closed (session_closed::restore_closed), once a window came back.
restored_window_meta 🔒
The name and appearance a restored window had, as the meta patch for the window now opening onto its workspace ws_id (CreateWindow). It stays until forget_restored_window_meta: a window whose meta couldn’t be written (srv stopped in between, a failed write) gets it on its next try.
restored_window_name 🔒
The name a restored window had, for the window now opening onto ws_id.
restored_window_opened 🔒
A window now shows restored workspace ws_id: saves take it from the live windows from here on.
reusable_workspace 🔒
The workspace a record entry names, when it is still there to reopen as it was: the reducer and the store have it, it holds a pane, no window shows it, and no earlier entry of this restore took it. None means rebuild the entry from the record.
save_on_last_close 🔒
The close that empties Client.windowids, before ws_id is kept or deleted: saves that workspace as the session, with the closing window’s name and appearance (read before its row was pruned), unless this close is one of a quit’s that already saved every window.
saved_appearance 🔒
The appearance a session record keeps for window w: its own theme and opacity, or those a restore still holds for it, whose write to the window failed (the next save keeps them, as it keeps a name).
saved_name 🔒
The name window w goes by in a session record: the user’s, or one a restore still holds for it, whose write to the window failed: the next save keeps it, so the restore after names it.
set_client_meta 🔒
Set (or, with None, remove) one of the client’s meta keys.
snapshot_session 🔒
The whole session: every live window’s workspace and placement, the main window’s tabs also at the top level. None when no window has anything to capture. for_quit marks it as a quit’s, which the closes that follow keep.
waiting_patch 🔒
What waits for one workspace, as a patch: an object of meta, or the bare name an earlier version left.
waiting_windows 🔒
The restored windows still waiting for the main window to open them (restore_all), as record entries: their workspaces exist, but no window shows them yet, so a snapshot of the live windows alone would drop them (#5358).
waiting_workspaces 🔒
The contents of the restored windows still waiting for the main window to open them.
window_name 🔒
The name the user gave window w, if any.
windows_of 🔒
The windows a record holds: its windows, or the record itself for one saved before records held several.