Skip to content

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

fix(agent): give the startup sweep a correlation id and complete its log lines\n\nThe sweep logged progress but nothing tied its lines together, and a restart\nloop is exactly when two sweeps interleave with no way to tell whose line is\nwhose. Adds a `sweep_id` (millisecond clock, so a log tail stays ordered)\ncarried by every line, plus an entry event with the workspace, an exit event on\neach of the four branches, and the state transition spelled out\n(`Running->Cancelled phase=Done`) rather than left as "reaped".\n\ntinyagents::reaper tests pass.\n\nReported by CodeRabbit on #5261.\n\nClaude-Session: https://claude.ai/code/session_01SRSNnqQsokuGmkbpLoLCGy\n

yh928f33043bb6b9d
diff --git a/src/openhuman/agent/tinyagents/reaper.rs b/src/openhuman/agent/tinyagents/reaper.rs
index 88c824c4d4..ea97170c4e 100644
--- a/src/openhuman/agent/tinyagents/reaper.rs
+++ b/src/openhuman/agent/tinyagents/reaper.rs
@@ -37,46 +37,76 @@ pub(crate) const ORPHAN_REAP_REASON: &str =
/// failure to open/list the store logs and yields `0` rather than blocking
/// boot. Returns the number of runs reaped.
pub(crate) async fn reap_orphaned_runs(workspace: &Path) -> usize {
+ // One id for the whole sweep so every line below can be tied to the same
+ // boot — a restart loop otherwise interleaves two sweeps' lines with nothing
+ // to tell them apart. Derived from the clock rather than a uuid so it stays
+ // ordered in a log tail.
+ let sweep_id = SystemTime::now()
+ .duration_since(SystemTime::UNIX_EPOCH)
+ .map(|d| d.as_millis())
+ .unwrap_or(0);
+ log::debug!(
+ "[agent] startup run sweep entry sweep_id={sweep_id} workspace={}",
+ workspace.display()
+ );
+
let stores = open_session_stores(workspace);
let store = FileStatusStore::new(stores.kv);
let active = match store.list_active().await {
Ok(runs) => runs,
Err(err) => {
- log::warn!("[agent] startup run sweep: list_active failed: {err}");
+ log::warn!(
+ "[agent] startup run sweep exit sweep_id={sweep_id} branch=list-failed: {err}"
+ );
return 0;
}
};
if active.is_empty() {
- log::debug!("[agent] startup run sweep: no orphaned runs");
+ log::debug!("[agent] startup run sweep exit sweep_id={sweep_id} branch=none-active");
return 0;
}
log::debug!(
- "[agent] startup run sweep: {} orphaned run(s) to reap",
+ "[agent] startup run sweep sweep_id={sweep_id} active={} to reap",
active.len()
);
let mut reaped = 0usize;
for mut status in active {
let run_id = status.run_id.as_str().to_string();
+ // The source state is read before the mutation, not assumed: `list_active`
+ // returns whatever non-terminal state a run was left in, and logging a
+ // presumed `Running` would misreport a run that died mid-`Queued`.
+ let from_status = format!("{:?}", status.status);
mark_orphaned(&mut status);
+ let to_status = format!("{:?}", status.status);
+ log::debug!(
+ "[agent] startup run sweep sweep_id={sweep_id} run_id={run_id} \
+ transition={from_status}->{to_status} phase=Done persisting"
+ );
match store.put_status(status).await {
Ok(()) => {
reaped += 1;
- log::debug!("[agent] startup run sweep: reaped run_id={run_id}");
+ log::debug!(
+ "[agent] startup run sweep sweep_id={sweep_id} run_id={run_id} \
+ transition={from_status}->{to_status} persisted"
+ );
}
Err(err) => {
- log::warn!("[agent] startup run sweep: reap failed run_id={run_id}: {err}");
+ log::warn!(
+ "[agent] startup run sweep sweep_id={sweep_id} run_id={run_id} \
+ transition={from_status}->{to_status} failed: {err}"
+ );
}
}
}
// One operator-visible line for the whole sweep, and only when it did
// something: a clean boot is the normal case and says nothing.
if reaped > 0 {
- log::info!("[agent] startup run sweep: reaped {reaped} orphaned run(s)");
+ log::info!("[agent] startup run sweep sweep_id={sweep_id} reaped {reaped} orphaned run(s)");
} else {
- log::debug!("[agent] startup run sweep: nothing to reap");
+ log::debug!("[agent] startup run sweep exit sweep_id={sweep_id} branch=nothing-reaped");
}
reaped
}