Skip to content

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

Merge remote-tracking branch 'upstream/main' into saas-delivery-slots

Steven Enamakel6b996530ff9d
diff --cc crates/openhuman-core/src/agent/orchestration/background_delivery.rs
index 1974578d7c,af60bb8c4f..da9bd59872
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
@@@ -162,11 -111,33 +162,21 @@@ impl EventHandler<DomainEvent> for Back
}
async fn handle(&self, event: &DomainEvent) {
- match event {
- DomainEvent::AgentTurnStarted { session_id, .. } => {
- busy()
- .lock()
- .expect("busy poisoned")
- .insert(session_id.clone());
- }
- // A failed turn may not emit AgentTurnCompleted — clear busy so
- // delivery isn't stuck.
- DomainEvent::AgentTurnCompleted { session_id, .. }
- | DomainEvent::AgentError { session_id, .. } => {
- busy().lock().expect("busy poisoned").remove(session_id);
- }
- _ => {}
- }
+ // Busy state is not tracked here: this runs off-task, with no tenant
+ // scope, so it cannot tell whose session an event names. The turn loop
+ // marks it in scope (`note_turn_started` / `note_turn_ended`).
let saas = crate::core::runtime::is_saas();
- for drain in drain_schedule_in(saas, event, completion_owners::context_for_profile) {
+ // Opening a profile is async (it may take its lease), so resolve the
+ // owning profiles' contexts first and hand the sync scheduler a lookup.
+ let mut live = std::collections::HashMap::new();
+ if saas {
+ for profile in owning_profiles(event) {
+ if let Some(ctx) = completion_owners::context_for_profile(&profile).await {
+ live.insert(profile, ctx);
+ }
+ }
+ }
+ for drain in drain_schedule_in(saas, event, |p| live.get(p).cloned()) {
match drain.owner {
// Re-enter the owner's scope so the scheduled task inherits it.
Some(ctx) => {
diff --cc crates/openhuman-core/src/profiles/host.rs
index 629cb0efa6,b200aa01e9..346a81537f
--- a/crates/openhuman-core/src/profiles/host.rs
+++ b/crates/openhuman-core/src/profiles/host.rs
@@@ -223,18 -343,15 +343,26 @@@ impl ProfileHost
.profile(id.as_str())
.agent_policy(profile_policy(&config)),
);
+ if grant.previous_unclean {
+ log::info!(
+ "[profiles] profile={id} taken over from a holder that never released it (epoch {}); recovering",
+ grant.epoch
+ );
+ recover_workspace(id, &layout.workspace_dir);
+ recover_session_store(id, &context);
+ }
crate::platform::cost::seed_tenant_tracker(&context, &config);
+ if first_open {
+ // Results a previous process finished but never delivered. The
+ // owner table that routes them is process-local and empty after a
+ // restart, so recover them in this profile's scope: the scheduled
+ // drains then run as this profile and reach only its tables.
+ CoreContext::sync_scope(Arc::clone(&context), || {
+ crate::agent::orchestration::background_delivery::recover_on_boot(
+ &layout.workspace_dir,
+ )
+ });
+ }
let state = Arc::new(Profile {
id: id.clone(),
layout,