feat: accept a staged update in the app

The host has staged a downloaded, signature-checked update since step 4,
but the only way to apply it was `wanderbooks update` at a terminal, and
nothing in the viewer or on an agent's first call said one waited. The
owner's accept is the name plan 8.0.3 allocated for it: the lease socket
gains `Intent::ApplyUpdate`, and the host installs the staged copy from a
thread and lets its existing watch for a replaced program (host.rs
INVARIANT 7) restart onto it once no call runs, so the books stay open and
every holder's session carries on. With no host running there is no call
to cut off, so the viewer applies it itself.

The viewer reads `<root>/updates/staged/meta.json` every few seconds and
shows a standing notice with "Update now"; Books gains "Check for updates"
(which looks at the feed at once, whatever the daily look last did) and
"Update to X". `books.start` gains the allocated `update_waiting` field
and a next step telling the agent to tell the human; no tool can accept.

`apply_staged` waits up to five seconds for the update lock: running the
new tests showed the host's own look can hold it for a moment after it
writes `meta.json`, and the owner's accept should wait that out rather
than answer "nothing waits".

Tests: `books_start_says_an_update_waits` and
`the_owner_accepts_a_staged_update_in_the_app` in
`crates/ledger-cli/tests/update.rs` (a bridge writes all through the
restart, each account in the chart exactly once);
`the_menu_checks_for_updates_and_a_waiting_update_shows_a_notice_that_accepts`
and `books_outside_a_data_root_have_no_update_notice` in
`crates/ledger-gui/tests/update_notice.rs`.
This commit is contained in:
swaits committed 2026-11-05 08:29:11 -07:00
1 parent 812d6f203e
commit 53a233d687
10 files changed
+693 -11

No files matched your search

+52 -1
View File
@@ -648,6 +648,9 @@ impl Host {
Event::Intent(Intent::ConsentFormatUpgrade { book, passphrase }, answer) => {
self.consent(book, passphrase.unwrap_or_default(), answer);
}
Event::Intent(Intent::ApplyUpdate, answer) => {
self.apply_update(answer);
}
Event::Intent(Intent::Close, answer) => {
let _ = answer.send(HostMsg::Done {
detail: Some("the books are closing".into()),
@@ -715,7 +718,7 @@ impl Host {
let (root, every, looking) = (self.root.clone(), self.knobs.update_check, looking.clone());
std::thread::spawn(move || {
match crate::update::stage_if_due(&root, crate::update::program_version(), every) {
Ok(Some(version)) => eprintln!("wanderbooks host: version {version} is downloaded and checked; it starts the next time the books open, or at `wanderbooks update`"),
Ok(Some(version)) => eprintln!("wanderbooks host: version {version} is downloaded and checked; it starts when you accept it in the app, the next time the books open, or at `wanderbooks update`"),
Ok(None) => {}
Err(why) => eprintln!("wanderbooks host: the look for a newer version failed: {why}"),
}
@@ -860,6 +863,54 @@ impl Host {
}
}
/// The owner's accept of the staged update (P11a step 4): install it
/// now, as `wanderbooks update` does, and let the host's watch for a
/// replaced program (INVARIANT 7) restart onto it once no call is
/// running: the server finishes its calls before it closes, and the
/// leases carry on across it. The answer is sent when the file is
/// in place (or why not), from a thread, so the loop never waits.
fn apply_update(&self, answer: oneshot::Sender<HostMsg>) {
if !matches!(self.phase, Phase::Open) {
let _ = answer.send(HostMsg::Refused(
"the books are closing or restarting: ask again in a moment".into(),
));
return;
}
#[cfg(unix)]
{
let root = self.root.clone();
std::thread::spawn(move || {
let said = match crate::update::apply_staged(
&root,
crate::update::program_version(),
) {
Ok(Some(version)) => {
eprintln!(
"wanderbooks host: version {version} accepted: restarting onto it when no call is running"
);
HostMsg::Done {
detail: Some(format!(
"version {version} is installed; the books restart onto it as soon as no call is running, and stay open meanwhile"
)),
}
}
Ok(None) => HostMsg::Refused(
"no newer version waits, or this install is updated by its package manager"
.into(),
),
Err(why) => HostMsg::Refused(why.to_string()),
};
let _ = answer.send(said);
});
}
#[cfg(not(unix))]
{
let _ = answer.send(HostMsg::Refused(
"updating from the app isn't built for this system yet".into(),
));
}
}
/// Close the server's input: it closes the books (INVARIANT 3).
fn close_server(&mut self) {
self.server_stdin = None;