From 6164d0fa683658400c1d547f6100447160a13455 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 21 Nov 2026 12:16:24 -0700 Subject: [PATCH] fix(host): a bridge that held a host follows the app that takes its place Plan P15 unit A5, fix round. A bridge started under a `serve` host, when that host went and the app started in its place, took a lease on the app's server: a lease with no host behind it, which never ends. When the app later closed, the assistant got a generic timeout and never "Wanderbooks isn't running". A lease with no host now turns the bridge into the line to whatever runs, as a bridge that began without a host is (`Lease::is_hostless`, `Bridge::keep`), and it answers in the same words when the app is closed. Co-Authored-By: Claude Fable 5.2 --- crates/ledger-host/src/bridge.rs | 11 +++++++++++ crates/ledger-host/src/opener.rs | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/crates/ledger-host/src/bridge.rs b/crates/ledger-host/src/bridge.rs index ae9486f9..3d23a9f2 100644 --- a/crates/ledger-host/src/bridge.rs +++ b/crates/ledger-host/src/bridge.rs @@ -1005,6 +1005,17 @@ impl Bridge { return; } }; + // The host this bridge held went, and the app started in its + // place: its lease is on a server with no host, which never + // ends, so it would never see the app go. The bridge becomes + // the line to whatever runs, as a fresh one is, and says the + // same words when the app closes (INVARIANT 12). + if lease.is_hostless() { + drop(lease); + self.app.store(true, std::sync::atomic::Ordering::SeqCst); + self.link.send_replace(Link::Opening); + return self.keep_in_app(run_dir).await; + } // Until this lease ends: whenever the server is ready and no // session is up, open one. The lease is always heard, even // while a session is being opened or a try waits (INVARIANT 1). diff --git a/crates/ledger-host/src/opener.rs b/crates/ledger-host/src/opener.rs index ed019d33..8e50099d 100644 --- a/crates/ledger-host/src/opener.rs +++ b/crates/ledger-host/src/opener.rs @@ -166,6 +166,13 @@ struct HostLink { } impl Lease { + /// Whether this lease is on the app's server with no host behind it + /// (INVARIANT 6): it never ends, so a holder that has one follows + /// what runs by looking, as a bridge with no host does. + pub fn is_hostless(&self) -> bool { + self.link.is_none() + } + /// The host's next word: `Ready`, or `Ending` with why; `None` when /// the host is gone without a word. pub async fn next(&mut self) -> Option {