Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(embed): retry workspace cleanup on drop to avoid race with background writers

Steven Enamakel52b9448e884b
diff --git a/src/embed/harness/mod.rs b/src/embed/harness/mod.rs
index 01b05a1977..6bc8d53b4b 100644
--- a/src/embed/harness/mod.rs
+++ b/src/embed/harness/mod.rs
@@ -185,6 +185,22 @@ impl Harness {
impl Drop for Harness {
fn drop(&mut self) {
HARNESS_LIVE.store(false, std::sync::atomic::Ordering::Release);
+ // For an ephemeral workspace, take ownership of the temp path and
+ // remove it with a short retry. The core's memory/session writers keep
+ // running a moment after the harness returns from a turn and can
+ // recreate workspace subdirectories while `TempDir`'s own drop-time
+ // removal is racing them, leaving an empty directory behind and
+ // breaking the documented "removed with its harness" guarantee. A
+ // bounded retry lets those writes settle before we give up.
+ if let Some(temp) = self._workspace._temp.take() {
+ let root = temp.into_path();
+ for _ in 0..20 {
+ if std::fs::remove_dir_all(&root).is_ok() {
+ break;
+ }
+ std::thread::sleep(std::time::Duration::from_millis(50));
+ }
+ }
log::debug!("[embed][harness] released");
}
}