Skip to content

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

feat(profiles): add host profile recovery support

Steven Enamakel4c36d2114896
diff --git a/crates/openhuman-core/src/profiles/host.rs b/crates/openhuman-core/src/profiles/host.rs
index 09f1edc4b7..835c44d6bd 100644
--- a/crates/openhuman-core/src/profiles/host.rs
+++ b/crates/openhuman-core/src/profiles/host.rs
@@ -25,6 +25,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use super::layout::{self, ProfileLayout};
use super::lease::{self as profile_lease, OpenError};
+use super::recovery::{recover_session_store, recover_workspace};
use super::registry::ProfileRegistry;
use super::types::{ProfileId, ProfileMeta, ProfileSummary, LAYOUT_VERSION};
use crate::config::Config;
@@ -639,54 +640,6 @@ fn profile_policy(config: &Config) -> Arc<crate::security::SecurityPolicy> {
)
}
-/// Settle what a previous holder left in profile `id`'s workspace: turns that
-/// were mid-flight become interrupted and run-ledger rows left running are
-/// closed. The sweep a single-user core runs at boot, run when a profile's
-/// lease is taken over from a holder that never released it. Failures are
-/// logged; the profile still opens.
-pub(crate) fn recover_workspace(id: &ProfileId, workspace_dir: &std::path::Path) {
- let now = chrono::Utc::now().to_rfc3339();
- match tinyagents_session::turn_state::store::mark_all_interrupted(
- workspace_dir.to_path_buf(),
- &now,
- ) {
- Ok(0) => {}
- Ok(turns) => log::info!("[profiles] profile={id} recovered {turns} interrupted turn(s)"),
- Err(error) => log::warn!("[profiles] profile={id} turn recovery failed: {error}"),
- }
- match tinyagents_session::run_ledger::interrupt_orphaned_agent_runs(workspace_dir) {
- Ok(0) => {}
- Ok(runs) => log::info!("[profiles] profile={id} settled {runs} orphaned run(s)"),
- Err(error) => log::warn!("[profiles] profile={id} run recovery failed: {error:#}"),
- }
-}
-
-/// [`recover_workspace`] for turn states kept in a storage-backed session
-/// store, which the workspace sweep cannot see: the profile's default
-/// session key is swept through the installed provider.
-fn recover_session_store(id: &ProfileId, context: &Arc<CoreContext>) {
- let Some(provider) = crate::agent::session_store::installed() else {
- return;
- };
- if provider.workspace_dir().is_some() {
- // File-backed: the workspace sweep already covered it.
- return;
- }
- let key = crate::core::runtime::session_key(&crate::core::runtime::Tenant::of(context));
- let now = chrono::Utc::now().to_rfc3339();
- match provider
- .for_agent(&key)
- .turn_states
- .mark_all_interrupted(&now)
- {
- Ok(0) => {}
- Ok(turns) => {
- log::info!("[profiles] profile={id} recovered {turns} interrupted stored turn(s)");
- }
- Err(error) => log::warn!("[profiles] profile={id} stored turn recovery failed: {error}"),
- }
-}
-
static HOST: OnceLock<Arc<ProfileHost>> = OnceLock::new();
/// Install the process's profile host. A SaaS boot does this once; later calls
diff --git a/crates/openhuman-core/src/profiles/mod.rs b/crates/openhuman-core/src/profiles/mod.rs
index bfe9a1f032..dae2fb7810 100644
--- a/crates/openhuman-core/src/profiles/mod.rs
+++ b/crates/openhuman-core/src/profiles/mod.rs
@@ -24,11 +24,13 @@
pub mod background;
pub mod credentials;
+pub mod fence;
pub mod gateway;
pub mod host;
pub mod layout;
pub mod lease;
pub mod ops;
+mod recovery;
pub mod registry;
pub mod schemas;
pub mod surface;
diff --git a/crates/openhuman-core/src/profiles/recovery.rs b/crates/openhuman-core/src/profiles/recovery.rs
new file mode 100644
index 0000000000..dfc441d47f
--- /dev/null
+++ b/crates/openhuman-core/src/profiles/recovery.rs
@@ -0,0 +1,57 @@
+//! Recovery after an unclean hand-over: when a profile's lease is taken
+//! over from a holder that never released it, that holder's turns may have
+//! died mid-flight. [`ProfileHost::open`](super::ProfileHost::open) runs
+//! these sweeps before the profile opens.
+
+use std::sync::Arc;
+
+use super::types::ProfileId;
+use crate::core::runtime::CoreContext;
+
+/// Settle what a previous holder left in profile `id`'s workspace: turns that
+/// were mid-flight become interrupted and run-ledger rows left running are
+/// closed. The sweep a single-user core runs at boot, run when a profile's
+/// lease is taken over from a holder that never released it. Failures are
+/// logged; the profile still opens.
+pub(crate) fn recover_workspace(id: &ProfileId, workspace_dir: &std::path::Path) {
+ let now = chrono::Utc::now().to_rfc3339();
+ match tinyagents_session::turn_state::store::mark_all_interrupted(
+ workspace_dir.to_path_buf(),
+ &now,
+ ) {
+ Ok(0) => {}
+ Ok(turns) => log::info!("[profiles] profile={id} recovered {turns} interrupted turn(s)"),
+ Err(error) => log::warn!("[profiles] profile={id} turn recovery failed: {error}"),
+ }
+ match tinyagents_session::run_ledger::interrupt_orphaned_agent_runs(workspace_dir) {
+ Ok(0) => {}
+ Ok(runs) => log::info!("[profiles] profile={id} settled {runs} orphaned run(s)"),
+ Err(error) => log::warn!("[profiles] profile={id} run recovery failed: {error:#}"),
+ }
+}
+
+/// [`recover_workspace`] for turn states kept in a storage-backed session
+/// store, which the workspace sweep cannot see: the profile's default
+/// session key is swept through the installed provider.
+pub(crate) fn recover_session_store(id: &ProfileId, context: &Arc<CoreContext>) {
+ let Some(provider) = crate::agent::session_store::installed() else {
+ return;
+ };
+ if provider.workspace_dir().is_some() {
+ // File-backed: the workspace sweep already covered it.
+ return;
+ }
+ let key = crate::core::runtime::session_key(&crate::core::runtime::Tenant::of(context));
+ let now = chrono::Utc::now().to_rfc3339();
+ match provider
+ .for_agent(&key)
+ .turn_states
+ .mark_all_interrupted(&now)
+ {
+ Ok(0) => {}
+ Ok(turns) => {
+ log::info!("[profiles] profile={id} recovered {turns} interrupted stored turn(s)");
+ }
+ Err(error) => log::warn!("[profiles] profile={id} stored turn recovery failed: {error}"),
+ }
+}