docs: the tab threads, the kept-state keys and the review's tests

architecture.md says how a tab owns its threads and what is kept under
what key; testing.md lists the tests, how each fix was shown to matter,
and why the sidenav window sizes were not restored (15 and 11 points
short at 519).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 19:03:26 -07:00
1 parent ec436cfc02
commit d3d5effafc
2 files changed
+129 -4

No files matched your search

+32 -4
View File
@@ -142,8 +142,9 @@ window, so the smallest window the viewer allows is the 400 points below
the bar plus the bar. A tab is the company's badge and name, as wide as
that between a least and a greatest width; the "+" follows the last tab
and stays at the right edge, the tabs scrolling, when they overflow. The
app remembers each company's name when its books load (`company.<id>.name`
in its kept state), for a tab's title before the books load and for the
app remembers each company's name when its books load (`company.<root>.<id>.name`
in its kept state, `<root>` being a hash of the data root's canonical path),
for a tab's title before the books load and for the
"+" list, which never reads a journal for a name. A view owns
everything that is one company's: its loader thread (its watcher and its
viewer presence on the books), the books it last loaded, where it is
@@ -152,13 +153,40 @@ its palette, its dock (and so the agent process in it) and its handle to
the `Owner`. Nothing is shared between views: every egui id a view makes is
scoped by its own id (the app draws a view inside `push_id`), so egui's
memory (scroll offsets, remembered widths) never carries from one tab into
another; closing a tab drops its view and with it all of that. A view that
another (a panel's id is not scoped by `push_id`, so the view's panels are
given ids made from its own; what the tabs share on purpose is the app's and
says so: the assistant dock's panel, whose height is one layout in every
tab, the tab bar, and the color scheme's palette); closing a tab drops its
view and with it all of that.
Every thread a view starts is counted in one registry of the view
(`jobs.rs`): its loader, its receipts' workers, an export, an owner's job,
the dock's start and the thread that reaps the dock's agent. Dropping the
view tells them all to stop, and the registry says when the last has ended
(`CompanyView::jobs_watch`). What each does on being told: the loader ends
(and the viewer's presence on the books is let go in the drop itself, not
when a refresh in flight is over), the receipts' workers end and write no
thumbnail, an export stops at its phase boundaries and saves nothing, a
read-only owner job (a backup, the check of a backup to restore) is not
begun or has its answer dropped, the dock's agent is hung up on and, if it
has not gone within two seconds, killed and reaped. One kind of job is never
abandoned: an owner's job that changes something (restore, the format
upgrade, new books, connect, close the books, update). While one runs, its
tab's close control is off and says what is running, and the window's close
is cancelled with a dialog that offers only to wait (`app.rs` INVARIANT 7;
`owner.rs` INVARIANT 6). A view that
is not in front still reads its loader every frame (so showing it later is
current at once) and takes the agent's `books.show` for its own page only.
`wanderbooks gui BOOK` opens that company as the only tab; with none named,
the companies that were open when the window last closed come back, in
their order, the same one in front, each with its page and its report's
period (`app.rs` INVARIANT 4). The `Owner` the program installs
period (`app.rs` INVARIANT 4). What is kept is filed under the data root
(a hash of its canonical path) and the company's id, with the books'
identity (the SHA-256 of the journal's first line) once they load: another
root's company of the same id, or the same id made again as other books,
inherits nothing, and a stored state whose identity is not the loaded
books' is discarded. A start that names a company never writes the list of
open companies, so one such start doesn't replace a set of tabs. The `Owner` the program installs
(`owner::set_owner`) is the program's, one per process; each view takes a
handle to it when it is made and a test can give a view another.
+97
View File
@@ -4460,6 +4460,103 @@ test above kills its removal); `Dock::closed_with` (a new tab's dock opens
closed); `route_from_key` and the period codes in `CompanyView::restore`
(a start after the end is never restored).
## P15 A3a, the review's faults: threads, kept state, the dock (2026-11-20)
An independent review of the tab work confirmed the viewer writes nothing
and no figure crosses tabs, and found six faults. Each is fixed and each
fix has a test that was seen to fail with the fix switched off (the
mutation column says what was switched off).
1. **Jobs outlived their tab** (`jobs.rs`, `menu.rs`, `owner.rs`,
`dock.rs`, `receipts.rs`, `data.rs`). Every thread a tab starts is one
of a per-view registry that the view's drop tells to stop and that says,
on a condition, when the last has ended.
2. **Kept state was filed under the id alone** (`app.rs`, `company.rs`).
It is filed under the data root's hash and the id, with the books'
identity (the SHA-256 of the journal's first line).
3. **A named start erased the remembered tabs** (`app.rs`).
4. **The dock's height** is the app's one layout, said and tested; every
other id egui keys by a raw name was found and ruled on.
5. **Prompt release on close** (`data.rs`, `receipts.rs`).
6. **The sidebar tests' window sizes**: see below.
`crates/ledger-gui/tests/tabs.rs` (sections 14 to 17), `format_upgrade.rs`,
`exports.rs`, `live.rs` and unit tests in `jobs.rs` and `receipts.rs`:
- `closing_a_tab_releases_its_lock_its_threads_and_its_agent` (changed): the
tab's registry counts the loader, the receipts' and thumbnails' workers
and the dock's agent; after the close the test waits on the registry
(`Watch::wait_ended`, its limit a failure guard, 120 s, never what the
test relies on) and then asserts the viewer lock is free, the loader's
thread has ended and the agent's process is gone. It no longer polls.
- `a_restore_under_way_holds_its_tab_and_the_window_open`,
`an_upgrade_under_way_holds_its_tab_and_the_window_open`
(`format_upgrade.rs`): the owner's call is held in the test; while it
runs the tab's close control is disabled to assistive technology, a
click and `App::close` leave the tab, the window's close request is
cancelled and the dialog names the company and what runs and offers only
to wait; with nothing running the same request goes through; when the
call ends the dialog goes and the result is in the tab.
- `a_backup_only_reads_so_its_tab_closes_and_its_thread_ends`: a read-only
owner job holds nothing, its tab closes, its thread ends when the
owner's call does.
- `an_export_is_stopped_when_its_tab_closes` (the job is told) and
`a_stopped_export_leaves_no_file_whenever_it_is_told` (`exports.rs`: a
signal given after 0, 1, 2 and 3 looks, each leaving no file, the fifth
look none, which saves).
- `a_tab_closed_while_its_agent_is_starting_leaves_no_child_and_no_thread`
and `a_tab_closed_with_its_agent_running_ends_the_child_even_if_it_ignores_the_hangup`
(Unix): the start is one of the tab's threads and its answer, arriving
after the close, starts nothing; an agent that ignores the hang-up is
killed after `AGENT_GRACE` and reaped, and the registry says so.
- `another_data_root_with_a_company_of_the_same_id_inherits_nothing`,
`books_made_again_under_an_id_start_fresh_and_a_restart_of_the_same_books_does_not`,
`books_outside_any_data_root_are_kept_under_their_folder`,
`preferences_written_before_the_keys_had_a_root_are_read_and_not_used`:
the kept-state keys. (A set of books' identity says when it was made to
the second, so a test that makes other books under an id waits for the
clock's next second first.)
- `a_start_with_a_named_company_never_writes_the_list_of_open_companies`.
- `the_docks_height_and_layout_are_the_apps_one_for_every_tab`,
`no_panel_but_the_apps_own_is_keyed_by_an_id_every_tab_shares`,
`the_color_scheme_is_the_windows_one_for_every_tab`: what the tabs share
on purpose, and that nothing else is.
- `live.rs`: `a_loader_whose_books_cant_be_read_tries_no_more_once_it_is_dropped`
(counts `Snapshot::load` tries), `a_dropped_loader_lets_go_of_its_presence_at_once`
(no waiting for the thread).
- `receipts.rs`: `a_thumbnail_is_not_written_for_a_tab_that_has_closed`.
- `jobs.rs`: the registry itself (a count lives until the thread ends,
also on a panic; a kept job is what a tab is held for).
**Each fix was switched off to see its test fail** (a temporary
`WB_MUT=<name>` switch at each fix, removed again): the held owner jobs (two
switches: the hold, and the cancel of the window's close; the tab's off
control and `App::close`'s guard each), the stop signal, the thumbnail
write, the export's checks, the dock start's registration, the kill of an
agent that ignores its hang-up, the dock's raw panel id (scoped, the test
fails), the viewer presence's release in `Loader::drop`, the loader's gone
check and wake before a retry, the books' identity check, the root in the
key, the named start's write of the list, the panel ids of the sidebar,
and the receipts' workers' registration: each of the tests above that
covers it failed, and passed with the fix in. Not switchable and so not
shown to fail: `preferences_written_before_the_keys_had_a_root_are_read_and_not_used`
(it passes before and after: no migration is the rule) and
`books_outside_any_data_root_are_kept_under_their_folder`, whose second
folder is also told apart by its books' identity.
**The sidebar tests' window sizes were not restored.** With the `+ BAR_H`
taken off the four `sidenav.rs` sites the sidebar has 36 points less than
the owner's 519 gave it before the bar, and three of the four fail at the
original size: `at_1479x519_every_link_shows_unscrolled` (the links scroll;
the window must be 534 high for them not to, 15 points short),
`the_rail_at_519_shows_every_link_unscrolled` (the rail must be 530, 11
short) and the grid test at 520 px (`no_link_is_ever_under_the_footer_at_scale_1`:
the same 15 points); `a_tall_sidebar_is_unchanged` fails its shapes hash,
which the shorter sidebar changes, as expected. The tests were left as they
are, the minimum window height (`lib.rs`) and the goldens untouched, and
the 15 (sidebar) and 11 (rail) points are the owner's to decide: take them
from the sidebar's rows or keep the bar's 36 points in the window sizes.
## P12: the checklists
The **For P12** paragraphs above (kept where they were written, with their