Expand description
The open workspace: a named set of windows, saved as it changes
(docs/specs/SPEC_WORKSPACES_2026_10_23.md §2, §4, §8). Not the srv
Workspace object, which is one window’s contents.
- Which one is open:
Client.meta["workspace:current"](its id) andClient.meta["workspace:name"](its name, for the status bar panel). A start with no workspace makes Default Workspace; a new version’s first start copies the previous version’s instead (prepare_at_startup). - Saving: every write to a window, a window’s contents, a tab, a layout
or a block counts as a change (
LayoutWrites, bumped by the store). The saver (spawn_saver) writes the whole session (session_windows::snapshot_session) as the workspace’srecord1 s after the last change, and at least every 15 s while changes keep coming. A quit, an OS shutdown and the last window’s close write it at once (write_record_now), and so does a window losing focus (workspace.Flush). A write that would store what is already there is skipped; one with no window open is never made. Each window in the record has astate:open, orclosedfor the windows the user closed (session_closed), which a cold start keeps closed. - Loading: a cold start restores the newer of the session record and the
workspace’s record, then falls back to the last record that loaded
cleanly (
previous) and the copy made before an upgrade (pre_upgrade) (restore_at_launch). Only a clean load replacesprevious.
The session record (session:last_topology) is still written as before:
the version after this one reads it if it has no workspace yet.
Structs§
- Pending 🔒
- A change not yet saved: when the first came, and the last, and whether any changed the arrangement (not only blocks’ settings).
- Restored 🔒
- What a launch restored: the window being created’s workspace and events
(as
restore_last_sessionreturns them), the record and where it came from.
Enums§
- Loaded
From 🔒 - Which copy a launch loaded.
- Saved 🔒
- What a save did.
Constants§
- CEILING_
MS 🔒 - …and no later than this after the first one not yet saved.
- CURRENT_
META_ 🔒KEY - The open workspace’s id.
- DEBOUNCE_
MS 🔒 - A change is saved this long after the last one…
- DEFAULT_
NAME 🔒 - The workspace everyone starts in.
- NAME_
MAX_ 🔒CHARS - The longest name kept, in characters (a window’s name has the same cap).
- NAME_
META_ 🔒KEY - The open workspace’s name.
- RESTORED_
FROM_ 🔒META_ KEY - Set when a launch had to load an older copy of the workspace:
previousorpre_upgrade. The window says so once and clears it. - SETTINGS_
ONLY_ 🔒MS - A change to blocks’ settings alone (an agent pane writes them as it works) waits this long instead; a close, a quit or focus loss saves it at once.
- TICK 🔒
- How often the saver looks for changes.
Statics§
- WRITE_
LOCK 🔒 - One save at a time: the saver, a flush and a boundary write never interleave their read-compare-write.
Functions§
- adopt_
current 🔒 - After
ensure_initial_data: opendecided(fromprepare_at_startup), or keep the one the client names, or the most recently opened. Writes its id and name onto the client, and when it was opened onto its row. - after_
clean_ 🔒load - A restore finished cleanly (
window_create’s final read-back): keep what loaded as the workspace’sprevious, and when it was an older copy, leave the window a note to say so. - clean_
name 🔒 nametrimmed and capped, orNonewhen nothing is left.- client 🔒
- copy_
from_ 🔒previous_ version - A new version’s first start (spec §4.2 “Upgrades”): copy every workspace
the channel’s most recently written other version has, once, reading its
database only. Ids and names are kept; each record is also kept as the
row’s
pre_upgrade. Returns the one to open: the one that version had open.Nonewhen there is nothing to copy. - create_
client_ 🔒only - The client row alone, as
ensure_initial_datamakes it (insert, then the temp id), with no window:ensure_initial_datathen sees a store that is set up and seeds nothing. - current_
id 🔒 - The open workspace’s id, if one is set.
- handle_
flush 🔒 workspace.Flush: save the open workspace now if anything changed since its last save. The window calls it when it loses focus. Returns{ saved }.- handle_
rename 🔒 workspace.RenameUserWorkspace(workspaceId, name): rename a workspace (""is the open one). The row and, for the open one, the client’sworkspace:namechange in one transaction; the client goes back as an object update so every window’s status bar panel shows the new name.- launch_
candidates 🔒 - The records a cold start tries, in order: the newer of the session record
and the workspace’s record (the session record on a tie: a quit writes
both), then the other, then
previous, thenpre_upgrade. A copy that doesn’t parse is left out. - new_row 🔒
- parse_
copy 🔒 - prepare_
at_ 🔒startup - Before the store’s first window is made (
wcore::ensure_initial_data): make sure there is a workspace. With none, copy the previous version’s (copy_from_previous_version), else make Default Workspace. Returns the workspace this start opens when it decided one, foradopt_current. - quit_
holds_ 🔒saves - Whether a quit is under way: its record is the session record and was
saved within the last two minutes (
session_windows::is_recent_quit_record). - read_
other_ 🔒workspaces - The workspaces in the database at
path, read-only, with the id its client names as open.Ok(None)for a database without workspaces (an older version’s has no table). - record_
has_ 🔒tabs - Whether any window in
recordhas a tab to restore. - restore_
at_ 🔒launch - A cold start’s restore: each of
launch_candidatesin turn until one brings a window back.Ok(None)when none had anything; the default seed follows. - same_
windows 🔒 - Whether two records hold the same windows: equal but for
saved_at_ms. - save_
now 🔒 - Save the open workspace from the live windows now.
- saved_
at 🔒 - spawn_
saver 🔒 - Save the open workspace as it changes, for as long as srv runs. The state it starts with is saved too (§8: the windows open at the first start with this become Default Workspace at once).
- write_
record 🔒 - Store
record(the open windows) as the open workspace’s windows, with its closed windows (session_closed::with_closed), unless that is what is stored already. Takes no lock; callers holdWRITE_LOCK. - write_
record_ 🔒now - Write
record(a session record a boundary just built: a quit’s, an OS shutdown’s, the last close’s) as the open workspace’s windows.