fix(host): what holds the books is known, not guessed; a command joins what starts beside it

Plan P15 unit A5, fix round. A server answering its admin socket with no host
over it was taken to be "the app". Three wrong outcomes followed: a `serve`
started while a killed host's server was still finishing its last backup was
told "the app has these books open" and exited, `close` and `doctor` said "the
app" during such a close, and a command attached to another command's short-lived
server as if it were the app (refused "not open" for another company, or its
server closed under the other).

A server now says what it is. `wanderbooks server --started-by app|host|command`
writes run/server.info beside its lock (who started it, its pid, whether it has
begun to close), moved into place whole as soon as the lock is its, rewritten
`closing` the moment it is told to close, removed just before the lock goes. It
is read only while the lock is held, which is when it is the lock holder's. A
file beside the lock, not a field in the admin hello: it also covers a server
that has no admin socket yet (opening) and costs the older admin protocol
nothing. A server that says nothing (an earlier build's) is taken for the app's,
as before. `opener::what_holds` reads it: only a server the app started, not
closing and answering, is the app. A command's server, or one that is closing
(the app's, or the orphan of a host that went), is waited for, said in words,
bounded by `open_wait` (a bridge waits as long as its session does), and the
holder or command goes on once it is gone. `close`, `doctor` and the bridge say
the true thing for each.

A command racing another program's start no longer fails with "close it" or waits
silently 300 s: if its own server loses the lock to a program that started after
its look, it lets its start go and joins what runs (`wait_ready_unless_beaten`,
`reach`), inside one `open_wait`.

A command's own server is started clean, as a host is: the host's environment
only, the root as an absolute path, `/` as its folder (Windows: `run/`), and
every server closes the descriptors above 2 at its start, so one that outlives
its command (still closing after 90 s) holds none of the invoker's pipes. The
app's own child keeps its environment: it is the window's child, closes with the
window and needs the user's session (ssh agent, git configuration) for backups;
it too loses stray descriptors, since the server does that for any starter.

Test knobs: `--start-delay` (a server's slow start) and `timer_hold=1` for a
command's own server, following `--timer-hold`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 12:12:28 -07:00
1 parent 6b95ce59ad
commit 2ff2913274
9 files changed
+598 -80

No files matched your search

+28 -5
View File
@@ -119,6 +119,15 @@ fn opening_words(book: &str) -> String {
)
}
/// What the agent is told when a command of the owner's has the books for
/// a moment (a server of its own, for the length of its work): the app is
/// not running, and it is not that either.
fn command_words(book: &str) -> String {
format!(
"A wanderbooks command has the books for a moment: {book} can be reached in a moment. Try again shortly."
)
}
/// What the agent is told when the app runs but the company is not open
/// in it (INVARIANT 12).
fn not_open_words(book: &str) -> String {
@@ -1106,7 +1115,19 @@ impl Bridge {
let mut epoch = 0u64;
loop {
if matches!(&*self.link.borrow(), Link::Opening) {
match self.socket_is_ours() {
// What holds the books is read before a session is tried
// (opener.rs INVARIANT 6a): a command's server, or one
// that is closing, is not the app, whatever its socket
// answers.
let held =
crate::opener::what_holds(&run_dir).unwrap_or(crate::opener::Holder::Nothing);
let owner_check = match held {
crate::opener::Holder::Command | crate::opener::Holder::Closing => {
Err(Owner::Unreachable)
}
_ => self.socket_is_ours(),
};
match owner_check {
Err(Owner::Other(why)) => {
self.link.send_replace(Link::Failed(why));
return;
@@ -1114,10 +1135,12 @@ impl Bridge {
Err(Owner::Unreachable) => {
// A server holding the books with no socket yet is
// opening (or finishing), not absent.
let words = if crate::opener::server_lock_held(&run_dir) {
opening_words(&self.book)
} else {
not_running_words(&self.book)
let words = match held {
crate::opener::Holder::Command => command_words(&self.book),
_ if crate::opener::server_lock_held(&run_dir) => {
opening_words(&self.book)
}
_ => not_running_words(&self.book),
};
self.link.send_replace(Link::Refused(words));
}