From f4a73739d596e3097e71627eb5edc2b0b7c571b1 Mon Sep 17 00:00:00 2001 From: YifanXu1999 Date: Tue, 24 Nov 2026 18:40:07 +0800 Subject: [PATCH 1/8] fix(sandbox): tombstone only confirmed-stopped Sandboxes; place in the start write (#784 review) A Sandbox's retired tombstone proves its generation's mounts dead once the home record is gone, so it is now written only where the runtime is confirmed stopped, gone or never started: - lifecycle::close no longer writes it for a retired docker record (its container is left for the user) or a record this build does not read (forget_unread: its daemon may still run). - sandbox.remove: the unread-local, foreign, retired-docker and nameless-machine forgets write none (Worker::Ask / Skip); a gone VM or a machine recorded stopped (Worker::Gone) still does. After the close its side ran, only a `Closed` answer or `NoSuchSandbox` writes it; a `Forgotten` answer (with or without `left`) writes none. A forget whose worker refused or was unreachable writes none. - Kept: the normal close, force::close, reclaim and remove_unstarted. - reclaim reports a tombstone it could not write in its answer's `left`; close carries it in the gone refusal's `left` detail and sandbox.remove's NoSuchSandbox arm adds it to `left` (it was dropped). A worker's record now gets its place in the same write that records it started (files::write_started, called by save_sandbox; save_place removed): the caller's place always wins, and a worker record sent no place drops any machine/generation a leftover record kept, so a failure leaves no evidence, never an older generation. lifecycle::start, launch::local::start and save_sandbox take the place with the host and platform. family::create_on runs sandbox.create with a stand-in for the side that starts it on a machine whose calls run in this process; create calls it with dispatch::call. Tests: new tests/retired_tombstone.rs (unread record and retired docker forget through sandbox.remove and lifecycle::close write no tombstone; a forget whose worker keeps its record writes none; gone VM writes one, nameless machine none; a recreate through create_on drops the older tombstone and sends its side the recorded place). half_created.rs: the forced remove's confirmed stop leaves the tombstone; new reclaim test (tombstone written, or its failure in the refusal's `left`). place_evidence.rs: the save_place test is replaced by write_started tests (new place in the start write; a leftover worker record never keeps its older generation; a home record keeps its place). No test deleted. Production LOC: 214259 -> 214288 (delta +29) scope: tools/production_loc.py (repo-pinned counter), first-parent tree vs committed tree reference absent (retired R9c; last counted 65,417 at tree 498dd1917812) Co-Authored-By: Claude Opus 5.5 --- control/crates/layerfs-sandbox/src/create.rs | 16 +- control/crates/layerfs-sandbox/src/family.rs | 2 +- control/crates/layerfs-sandbox/src/files.rs | 70 ++-- .../layerfs-sandbox/src/launch/local.rs | 8 +- .../crates/layerfs-sandbox/src/lifecycle.rs | 68 ++-- .../layerfs-sandbox/src/record/sandbox.rs | 8 + .../layerfs-sandbox/src/record/tombstone.rs | 16 +- control/crates/layerfs-sandbox/src/remove.rs | 62 +++- .../layerfs-sandbox/tests/half_created.rs | 81 ++++- .../layerfs-sandbox/tests/place_evidence.rs | 82 +++-- .../tests/retired_tombstone.rs | 331 ++++++++++++++++++ 11 files changed, 634 insertions(+), 110 deletions(-) create mode 100644 control/crates/layerfs-sandbox/tests/retired_tombstone.rs diff --git a/control/crates/layerfs-sandbox/src/create.rs b/control/crates/layerfs-sandbox/src/create.rs index 4d15f69ce0..d684183387 100644 --- a/control/crates/layerfs-sandbox/src/create.rs +++ b/control/crates/layerfs-sandbox/src/create.rs @@ -62,6 +62,18 @@ pub fn create( home: &Path, events: &mut Events<'_>, request: &CreateRequest, +) -> Result { + create_on(home, events, request, crate::dispatch::call) +} + +/// [`create`], whose start runs through `local` on a machine whose calls +/// run in this process (`crate::dispatch::call` in [`create`]; a test may +/// stand in for the Sandbox's own side there). +pub fn create_on( + home: &Path, + events: &mut Events<'_>, + request: &CreateRequest, + local: crate::route::Local, ) -> Result { let home = home.to_path_buf(); let project = request.project.as_str(); @@ -166,8 +178,8 @@ pub fn create( image: request.image.clone(), start: Some((0, total(request.mount))), }; - let started = on_machine(&home, events, &record, asked, crate::dispatch::call) - .map(|value| Started::read(&value)); + let started = + on_machine(&home, events, &record, asked, local).map(|value| Started::read(&value)); // a worker's Sandbox whose daemon this host reaches directly (#535 G4): // its forward opens before the locks are taken let opened = (started.as_ref().ok()).map(|started| direct::open(&home, &record, started)); diff --git a/control/crates/layerfs-sandbox/src/family.rs b/control/crates/layerfs-sandbox/src/family.rs index d487807121..b61c9df2df 100644 --- a/control/crates/layerfs-sandbox/src/family.rs +++ b/control/crates/layerfs-sandbox/src/family.rs @@ -18,7 +18,7 @@ //! (`create`, `list`, `get`, `remove`), the state of a Sandbox in //! `state.rs`, the route of a host operation in `route.rs`, and the //! `workspace` calls in `workspace/calls.rs`. -pub use super::create::{create, CreateRequest, Created}; +pub use super::create::{create, create_on, CreateRequest, Created}; pub use super::get::{get, Down, GetRequest, Got, ListedWorkspace}; pub use super::list::{list, ListRequest, Listed, ListedSandbox}; use super::record::SandboxRecord; diff --git a/control/crates/layerfs-sandbox/src/files.rs b/control/crates/layerfs-sandbox/src/files.rs index fa836cd6d7..9116f0875a 100644 --- a/control/crates/layerfs-sandbox/src/files.rs +++ b/control/crates/layerfs-sandbox/src/files.rs @@ -55,11 +55,12 @@ pub fn started(directory: &Path) -> Result> { /// Records started Sandbox `state` in its folder `directory`: its daemon /// keys in `control.json`, then what reopens it in its record (`daemon`, /// with its backend, route and runtime id, and `platform`, which `create` -/// checked before any effect, #529), the record's other fields kept. +/// checked before any effect, #529), the record's other fields kept, and +/// its place in the same write ([`write_started`]). pub fn save_sandbox( directory: &Path, state: &SandboxState, - (host, platform): (&Host, &str), + (host, platform, place): (&Host, &str, Option<&(String, String)>), secret: [u8; 32], peer: [u8; 32], instance: [u8; 32], @@ -104,40 +105,49 @@ pub fn save_sandbox( ("instance", SdkValue::Bytes(instance.to_vec())), ]), )?; - // on `native` this is the home's record, which keeps its other fields - // (its `op` among them): changed under the Sandbox lock (#536 §8) - let _sandbox = crate::record::lock_in(directory, &state.id)?; - let record = SandboxRecord::read_in(directory, &state.id)? - .unwrap_or_else(|| SandboxRecord::from_record(&state.id, SdkValue::Null)); - let store = &host.store; let facts = [ crate::runtime::kind(runtime).to_owned(), route(runtime).to_owned(), runtime.identity().to_string(), ]; - let record = record.with_start(format!("{store}/{}", state.project), facts, daemon); - record.write_in(directory) + let project = format!("{}/{}", host.store, state.project); + let worker = layerfs_home::home::guest::is_root(&host.home); + write_started( + directory, + &state.id, + (project, facts, daemon), + (place, worker), + ) } -/// Writes the machine and generation a worker's caller minted (`place`) -/// into the worker's own record of Sandbox `name` in `directory`, so the -/// mounts it places carry them (#783 gap 1). The caller's values always win: -/// a record an interrupted removal left behind may name an older generation, -/// and a mount recording that one would look retired beside the home's -/// newer record. On `native` the record is the home's own and already names -/// them (nothing is written). Best effort: a record left without them only -/// means its mounts carry no place evidence, and missing evidence is never -/// death. -pub fn save_place(directory: &Path, name: &str, (machine, generation): &(String, String)) { - let _ = (|| -> Result<()> { - let _sandbox = crate::record::lock_in(directory, name)?; - let Some(record) = SandboxRecord::read_in(directory, name)? else { - return Ok(()); - }; - if record.generation() == Some(generation) && record.machine() == machine { - return Ok(()); - } - record.with_place(machine, generation).write_in(directory) - })(); + +/// Writes the record of Sandbox `name` in `directory` once it started: its +/// `project`, backend, route and runtime id (`facts`) and `daemon` +/// ([`SandboxRecord::with_start`]), with its place in the same write, so a +/// mount never reads a place from another write (#783 gap 1). `place` is +/// the machine and generation the caller's home minted; the caller's values +/// always win. A worker's own record (`worker`) keeps no other place: a +/// record an interrupted removal left behind may name an older generation, +/// which the home's newer record would prove retired, so without `place` +/// it names none (missing evidence is never death, wrong evidence is). +/// On `native` the record is the home's own, which names its place already. +/// Changed under the Sandbox lock (#536 §8), its other fields kept (its +/// `op` among them). +pub fn write_started( + directory: &Path, + name: &str, + (project, facts, daemon): (String, [String; 3], DaemonRecord), + (place, worker): (Option<&(String, String)>, bool), +) -> Result<()> { + let _sandbox = crate::record::lock_in(directory, name)?; + let record = SandboxRecord::read_in(directory, name)? + .unwrap_or_else(|| SandboxRecord::from_record(name, SdkValue::Null)) + .with_start(project, facts, daemon); + match (place, worker) { + (Some((machine, generation)), _) => record.with_place(machine, generation), + (None, true) => record.without_place(), + (None, false) => record, + } + .write_in(directory) } /// The kernel route a running Sandbox's Workspaces use: loopback NFS for a diff --git a/control/crates/layerfs-sandbox/src/launch/local.rs b/control/crates/layerfs-sandbox/src/launch/local.rs index 5eb8f10c65..e2f5e81525 100644 --- a/control/crates/layerfs-sandbox/src/launch/local.rs +++ b/control/crates/layerfs-sandbox/src/launch/local.rs @@ -38,7 +38,7 @@ use std::sync::Arc; /// Store, whose daemon dials the server (#535 §7.4). `platform` is the /// one `create` checked, recorded with it. pub fn start( - (host, platform): (&Host, &str), + (host, platform, place): (&Host, &str, Option<&(String, String)>), directory: &Path, project: OpenedStore, backend: crate::runtime::Backend, @@ -77,7 +77,7 @@ pub fn start( }; let id = host.sandbox()?; start_named( - (host, platform), + (host, platform, place), directory, id, project, @@ -88,7 +88,7 @@ pub fn start( /// Starts Sandbox `id`: directory and daemon on the installed Store, its /// first control connection, then its records in its folder `directory`. fn start_named( - (host, platform): (&Host, &str), + (host, platform, place): (&Host, &str, Option<&(String, String)>), directory: &Path, id: &str, project: OpenedStore, @@ -243,7 +243,7 @@ fn start_named( crate::files::save_sandbox( &state.directory, &state, - (host, platform), + (host, platform, place), controller.private, daemon.public, instance, diff --git a/control/crates/layerfs-sandbox/src/lifecycle.rs b/control/crates/layerfs-sandbox/src/lifecycle.rs index ea5e16800d..db81958ff4 100644 --- a/control/crates/layerfs-sandbox/src/lifecycle.rs +++ b/control/crates/layerfs-sandbox/src/lifecycle.rs @@ -189,9 +189,10 @@ fn repaired( /// Starts the Sandbox the call names (`sandbox`) as its deployment says /// (`deploy.sandbox`: native or namespaces), its daemon on `store`. Called /// under the guard of its folder `directory`, so no other call on it runs -/// meanwhile. +/// meanwhile. `place`, the machine and generation the caller's home minted, +/// is written with its record ([`crate::files::save_sandbox`]). pub fn start( - (host, platform): (&Host, &str), + (host, platform, place): (&Host, &str, Option<&(String, String)>), directory: &Path, store: OpenedStore, ) -> Result, SdkRefusal> { @@ -202,11 +203,11 @@ pub fn start( let backend = crate::runtime::backend(deploy)?; #[cfg(any(target_os = "linux", target_os = "macos"))] { - crate::launch::local::start((host, platform), directory, store, backend) + crate::launch::local::start((host, platform, place), directory, store, backend) } #[cfg(not(any(target_os = "linux", target_os = "macos")))] { - drop((directory, store, backend, platform)); + drop((directory, store, backend, platform, place)); Err(refused( "Unsupported", "a Sandbox runs on Linux (namespaces) or macOS (native)", @@ -224,7 +225,8 @@ pub fn start( /// `namespaces`; a native one's `image` is `local`. `platform` (#529) is /// checked against that backend and recorded. /// `place`, the machine and generation the caller's home minted, goes into -/// a worker's own record once the Sandbox started ([`crate::files::save_place`]). +/// a worker's own record in the same write that records it started +/// ([`crate::files::save_sandbox`]). /// The only call that starts a Sandbox. Failures are `Failed` or /// `Unknown`, never retried. pub fn create(host: &Host, named: Option<&str>, place: Option<&(String, String)>) -> Outcome { @@ -261,11 +263,7 @@ pub fn create(host: &Host, named: Option<&str>, place: Option<&(String, String)> } None => {} } - let state = start((host, &platform), &directory, store)?; - if let Some(place) = place { - crate::files::save_place(&directory, &state.id, place); - } - Ok(state) + start((host, &platform, place), &directory, store) })(); let state = match made { Ok(state) => state, @@ -306,9 +304,12 @@ pub fn create(host: &Host, named: Option<&str>, place: Option<&(String, String)> /// Stop, then delete, each attempted once: a failed stop is not followed by /// a delete and keeps its cause; the folder goes after the delete. A /// Sandbox whose runtime ended by itself is reclaimed ([`reclaim`]) and -/// answered `NoSuchSandbox`, as gone. A local record this build does not -/// read is forgotten ([`forget_unread`]), no signal sent: a worker's own -/// record, when the caller's home keeps only the forward to it. +/// answered `NoSuchSandbox`, as gone (its `left` detail names a retired +/// tombstone the reclaim could not write). A local record this build does +/// not read is forgotten ([`forget_unread`]), no signal sent: a worker's own +/// record, when the caller's home keeps only the forward to it. Neither it +/// nor a retired docker record ([`forget`]) gets a retired tombstone: its +/// runtime was not stopped, so nothing proves its mounts dead. /// Once the runtime is gone, each drained Workspace's mount intent is /// ended once (`left` names each one not ended); on a PostgreSQL Store /// whose URL this machine cannot dial, those bound by id go back to the @@ -324,19 +325,23 @@ pub fn close(host: &Host, force: bool, held: &[String]) -> Outcome { )); }; if recorded.retired() { - let _ = retired(host, &id); return forget(&id, &directory, &recorded); } if let Some(why) = crate::reopen::unread(&recorded) { - let unretired = retired(host, &id); - return forget_unread(&id, &directory, &recorded, &why, unretired); + return forget_unread(&id, &directory, &recorded, &why); } let state = match crate::registry::sandbox_live(host) { Ok(state) => state, Err(gone) if gone.detail.get_bool("containerGone") => { let container = gone.detail.get_text("container").unwrap_or("").to_owned(); - reclaim(host, &container, gone.detail.get_bool("containerStopped"))?; - return Err(gone); + let reclaimed = reclaim(host, &container, gone.detail.get_bool("containerStopped"))?; + return Err(match reclaimed.get("left") { + Some(left @ SdkValue::List(items)) if !items.is_empty() => SdkRefusal { + detail: layerfs_home::home::with_field(gone.detail, "left", left.clone()), + ..gone + }, + _ => gone, + }); } Err(refusal) => return Err(refusal), }; @@ -516,25 +521,18 @@ fn forget(id: &str, directory: &Path, recorded: &DaemonRecord) -> Outcome { /// build does not read (`why`, [`crate::reopen::unread`]; RV3 FAIL 2, 3): /// its identity cannot be checked, so nothing is signalled. Its folder goes /// under its guard, and the answer (`Forgotten`, with `left`) says what may -/// remain: its daemon or init process and its run folder. -/// `unretired` is the sentence of a retirement tombstone that was not -/// written, which `left` carries too. -fn forget_unread( - id: &str, - directory: &Path, - recorded: &DaemonRecord, - why: &str, - unretired: Option, -) -> Outcome { +/// remain: its daemon or init process and its run folder. No retired +/// tombstone is written: that process may still run. +fn forget_unread(id: &str, directory: &Path, recorded: &DaemonRecord, why: &str) -> Outcome { let _guard = layerfs_store::project::discovery::guard(directory)?; discard(directory, recorded)?; std::fs::remove_dir_all(directory).map_err(failed)?; layerfs_home::home::generation::moved_above(directory); - let left = std::iter::once(SdkValue::text(unread_left(recorded, why))).chain(unretired); + let left = vec![SdkValue::text(unread_left(recorded, why))]; Ok(SdkValue::map([ ("kind", SdkValue::text("Forgotten")), ("sandbox", SdkValue::text(id)), - ("left", SdkValue::List(left.collect())), + ("left", SdkValue::List(left)), ])) } @@ -582,7 +580,9 @@ const STOP_S: u16 = 5; /// stopped (`container`, its runtime id; `stopped`): one Delete of a /// stopped runtime, then its folder. Under its folder's guard the record is /// read again: a Sandbox started again meanwhile has another runtime id -/// and is left alone (`Busy`). +/// and is left alone (`Busy`). Its runtime is confirmed gone, so the home +/// record's retired tombstone is written before the folder goes; one that +/// was not written is the sentence of its answer's `left`. pub fn reclaim(host: &Host, container: &str, stopped: bool) -> Outcome { let id = host.sandbox()?; let directory = crate::files::sandbox_dir(host)?; @@ -606,13 +606,15 @@ pub fn reclaim(host: &Host, container: &str, stopped: bool) -> Outcome { .map_err(values::wire)?; } // its runtime is gone: the home record's tombstone first, best effort - // (the close that reclaimed it answers `NoSuchSandbox`, with no `left`) - let _ = retired(host, id); + // (the close that reclaimed it answers `NoSuchSandbox`, its `left` + // detail naming a tombstone that was not written) + let unretired = retired(host, id); lock(&SANDBOXES)?.remove(&directory); std::fs::remove_dir_all(&directory).map_err(failed)?; layerfs_home::home::generation::moved_above(&directory); Ok(SdkValue::map([ ("kind", SdkValue::text("Reclaimed")), ("id", SdkValue::text(id)), + ("left", SdkValue::List(unretired.into_iter().collect())), ])) } diff --git a/control/crates/layerfs-sandbox/src/record/sandbox.rs b/control/crates/layerfs-sandbox/src/record/sandbox.rs index 1d756d264b..8fef08c254 100644 --- a/control/crates/layerfs-sandbox/src/record/sandbox.rs +++ b/control/crates/layerfs-sandbox/src/record/sandbox.rs @@ -280,6 +280,14 @@ impl SandboxRecord { self } + /// The record naming no machine or generation: a worker's own record + /// whose caller sent no place keeps none an earlier one left. + pub fn without_place(mut self) -> Self { + self.fields.remove("machine"); + self.fields.remove("generation"); + self + } + /// The intent the record holds, if any. pub fn op(&self) -> Option { self.fields diff --git a/control/crates/layerfs-sandbox/src/record/tombstone.rs b/control/crates/layerfs-sandbox/src/record/tombstone.rs index e329514e0b..3b657128ba 100644 --- a/control/crates/layerfs-sandbox/src/record/tombstone.rs +++ b/control/crates/layerfs-sandbox/src/record/tombstone.rs @@ -1,10 +1,16 @@ //! Retired Sandbox tombstones: `machine//sandbox-retired/.json`. //! -//! Every removal of a Sandbox's home record writes the tombstone **before** it -//! deletes that record, best effort: a close or force close on `native`, a -//! reclaim of a runtime that ended by itself, a forget, and `sandbox.remove` -//! on every route (normal, forgotten, unstarted), which writes the home's -//! tombstone for a worker's Sandbox. A crash leaves the record or both, never +//! A removal of a Sandbox's home record writes the tombstone **before** it +//! deletes that record, best effort, only when the Sandbox's runtime is +//! confirmed stopped, confirmed gone or never started: a close or force +//! close on `native`, a reclaim of a runtime that ended by itself, and +//! `sandbox.remove` after its side answered `Closed` or `NoSuchSandbox`, +//! on a gone VM or stopped machine, or of a create that ended claiming the +//! name (it writes the home's tombstone for a worker's Sandbox). A removal +//! that did not stop the runtime (a record this build does not read or +//! reopen, a retired docker record, a worker that keeps its record) writes +//! none: a tombstone proves the mounts of its generation dead, and no +//! evidence is the safe outcome. A crash leaves the record or both, never //! neither; a write that fails is reported in `left` and the removal goes on, //! since a missing tombstone is only "no proof". The path is outside //! `sandbox/`, so a Sandbox listing never mistakes a tombstone for a Sandbox. diff --git a/control/crates/layerfs-sandbox/src/remove.rs b/control/crates/layerfs-sandbox/src/remove.rs index 334c106a1b..a9273214f3 100644 --- a/control/crates/layerfs-sandbox/src/remove.rs +++ b/control/crates/layerfs-sandbox/src/remove.rs @@ -10,6 +10,15 @@ //! `Busy`; a gone owner's uncertain intent does not: `sandbox.remove` is the //! call that clears it. Its progress is its op's phases: `cancel` (forced, //! one event per command this home records), `stop` and `delete`. +//! +//! The home's retired tombstone of the Sandbox is written before its record +//! goes only when its runtime is confirmed stopped (a close answered +//! `Closed`), confirmed gone (its side answered `NoSuchSandbox`, its VM is +//! gone or its machine is stopped) or never started (a create that ended +//! claiming the name). A removal that leaves a runtime it did not stop (a +//! record this build does not read or reopen, or a worker that keeps its +//! record) writes none: no evidence is the safe outcome, a tombstone would +//! prove a live mount dead. use super::create::remove_folder; use super::direct; use super::family::named; @@ -112,7 +121,11 @@ pub fn remove(home: &Path, events: &mut Events<'_>, request: &RemoveRequest) -> its daemon and run folder were in that VM, which its provider no longer holds" ), }; - return forget(&home, events, name, first, Worker::Skip); + let worker = match on.nameless() { + true => Worker::Skip, + false => Worker::Gone, + }; + return forget(&home, events, name, first, worker); } if let Some(unnamed) = foreign(&home, &found)? { return forget(&home, events, name, unnamed, Worker::Ask); @@ -132,7 +145,7 @@ pub fn remove(home: &Path, events: &mut Events<'_>, request: &RemoveRequest) -> // with `force`, goes by its records alone; without either, the remove // says how it can go if let Some(first) = stopped_on(&home, &found, request.force)? { - return forget(&home, events, name, first, Worker::Skip); + return forget(&home, events, name, first, Worker::Gone); } let force = request.force; // the commands this home records, which a forced remove cancels first @@ -225,24 +238,28 @@ pub fn remove(home: &Path, events: &mut Events<'_>, request: &RemoveRequest) -> }; match stopped { // a record its side does not read went by its records alone, no - // signal sent (RV3 FAIL 2, 3): as gone, `left` saying what may remain + // signal sent (RV3 FAIL 2, 3): as gone, `left` saying what may + // remain. Its daemon may still run, so no tombstone is written Ok(value) if value.get_text("kind") == Some("Forgotten") && value.get("left").is_some() => { phase(events, "delete", None); direct::release(&home, &record); - let unretired = retire_home(&home, &record, &dir); remove_folder(&dir)?; done(events); let left = match value.get("left") { Some(SdkValue::List(items)) => texts(items).map(str::to_owned).collect(), _ => Vec::new(), }; - let left = left.into_iter().chain(unretired).collect(); Ok(Removed::AlreadyGone { left }) } Ok(value) => { phase(events, "delete", None); direct::release(&home, &record); - let unretired = retire_home(&home, &record, &dir); + // only a close that stopped the runtime proves its mounts dead; + // a retired docker record its side forgot left its container + let unretired = match value.get_text("kind") { + Some("Closed") => retire_home(&home, &record, &dir), + _ => None, + }; remove_folder(&dir)?; let unmounted = match value.get("unknown") { Some(SdkValue::List(paths)) => texts(paths).map(&handle_of).collect(), @@ -263,11 +280,17 @@ pub fn remove(home: &Path, events: &mut Events<'_>, request: &RemoveRequest) -> done(events); Ok(Removed::Stopped { unmounted, left }) } - // a Sandbox already gone loses its record too + // a Sandbox already gone loses its record too; its side's reclaim + // names a tombstone it could not write in its `left` detail Err(refusal) if refusal.code == "NoSuchSandbox" => { phase(events, "delete", None); direct::release(&home, &record); - let left = retire_home(&home, &record, &dir).into_iter().collect(); + let reclaimed: Vec = match refusal.detail.get("left") { + Some(SdkValue::List(items)) => texts(items).map(str::to_owned).collect(), + _ => Vec::new(), + }; + let unretired = retire_home(&home, &record, &dir); + let left = reclaimed.into_iter().chain(unretired).collect(); remove_folder(&dir)?; done(events); Ok(Removed::AlreadyGone { left }) @@ -379,7 +402,10 @@ fn foreign(home: &Path, record: &SandboxRecord) -> Result> { /// machine's worker is asked once to drop its own record of it (a worker /// that cannot be reached or refuses leaves that record, and `left` says /// so), unless `worker` skips it, then the home's record goes. Nothing it -/// ran is touched; `first`, the first of `left`, says what was left. +/// ran is touched; `first`, the first of `left`, says what was left. The +/// home's retired tombstone is written only for [`Worker::Gone`], whose +/// runtime is confirmed gone: a worker that keeps its record, or one that +/// forgot it without stopping it, proves nothing. fn forget( home: &Path, events: &mut Events<'_>, @@ -400,7 +426,7 @@ fn forget( let left = match (here, worker) { // the record of a Sandbox on a machine whose calls run in this // process is the folder removed below - (true, _) | (_, Worker::Skip) => None, + (true, _) | (_, Worker::Skip | Worker::Gone) => None, _ => on_machine( home, events, @@ -422,7 +448,10 @@ fn forget( let _sandbox = record::lock(home, name)?; direct::release(home, &record); } - let unretired = retire_home(home, &record, &dir); + let unretired = match worker { + Worker::Gone => retire_home(home, &record, &dir), + Worker::Ask | Worker::Skip => None, + }; remove_folder(&dir)?; done(events); let kept = left.map(|left| { @@ -482,13 +511,18 @@ fn stopped_on(home: &Path, record: &SandboxRecord, force: bool) -> Result