The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(orchestration): move recovery claim helpers into completion_target
Steven Enamakel088b86add90e
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions.rs b/crates/openhuman-core/src/agent/orchestration/background_completions.rsindex 699e0d54ec..4234a1d218 100644--- a/crates/openhuman-core/src/agent/orchestration/background_completions.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_completions.rs@@ -37,6 +37,7 @@ use tinyagents_tasks::{use super::completion_notice::BackgroundCompletionFormatter;pub(crate) use super::completion_notice::{BackgroundAgentOutcome, AWAITING_INPUT_LABEL};pub(crate) use super::completion_target::CompletionTarget;+pub(crate) use super::completion_target::{claim_recovery, forget_recovery};#[cfg(test)]pub(crate) use super::completion_target::{forget_workspace_for_test, install_store_for_test, TestWorkspace,@@ -207,31 +208,6 @@ pub(crate) fn workspace_for_thread(thread_id: &str) -> Option<PathBuf> {state().thread_workspaces.get(&key(thread_id)).cloned()}-/// Claim `workspace_dir`'s boot recovery for this process. `true` exactly once-/// per workspace, so the host can scan every workspace it opens (the bootstrap-/// one, then any other a spawn later opens) without rescanning.-pub(crate) fn claim_recovery(workspace_dir: &Path) -> bool {- state()- .recovered_workspaces- .insert(workspace_dir.to_path_buf())-}--/// Let `workspace_dir` be recovered again (a profile re-leased after release),-/// and drop its cached router when nothing is using it so the next scan replays-/// the log another holder may have appended to. A router still in use stays,-/// so a log never has two writers.-pub(crate) fn forget_recovery(workspace_dir: &Path) {- let mut st = state();- st.recovered_workspaces.remove(workspace_dir);- let idle = st- .routers- .get(workspace_dir)- .is_some_and(|e| Arc::strong_count(e) == 1 && Arc::strong_count(&e.router) == 1);- if idle {- st.routers.remove(workspace_dir);- }-}-/// Remember that `session_id` is a turn on `thread_id`.pub(crate) fn note_session_thread(session_id: &str, thread_id: &str) {let session_key = key(session_id);diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rsindex e063bddc10..3e048ef00c 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs@@ -43,10 +43,10 @@ use tinybus::EventHandler;use tinybus::SubscriptionHandle;use super::background_completions;-use super::completion_notice::build_undelivered_notice;use super::busy_guard::is_busy;#[cfg(test)]use super::busy_guard::{busy, clear_busy_for_thread, TurnBusy};+use super::completion_notice::build_undelivered_notice;use super::completion_owners;use crate::core::runtime::tenant;use crate::core::runtime::CoreContext;diff --git a/crates/openhuman-core/src/agent/orchestration/busy_guard.rs b/crates/openhuman-core/src/agent/orchestration/busy_guard.rsindex aa391dc2dc..a7de2d7b6c 100644--- a/crates/openhuman-core/src/agent/orchestration/busy_guard.rs+++ b/crates/openhuman-core/src/agent/orchestration/busy_guard.rs@@ -102,4 +102,3 @@ pub(crate) fn clear_busy_for_thread(thread_id: &str) -> usize {}cleared}-diff --git a/crates/openhuman-core/src/agent/orchestration/completion_target.rs b/crates/openhuman-core/src/agent/orchestration/completion_target.rsindex ff9ff90b6d..e51bf7a22e 100644--- a/crates/openhuman-core/src/agent/orchestration/completion_target.rs+++ b/crates/openhuman-core/src/agent/orchestration/completion_target.rs@@ -12,8 +12,9 @@ use std::sync::Arc;#[cfg(test)]use tinyagents_tasks::CompletionStore;+use super::background_completions::state;#[cfg(test)]-use super::background_completions::{new_router, state, Entry};+use super::background_completions::{new_router, Entry};use super::background_completions::{record_awaiting_input, record_completion, record_failure};@@ -143,3 +144,28 @@ pub(crate) fn forget_workspace_for_test(workspace_dir: &Path) {st.session_threads.clear();st.session_order.clear();}++/// Claim `workspace_dir`'s boot recovery for this process. `true` exactly once+/// per workspace, so the host can scan every workspace it opens (the bootstrap+/// one, then any other a spawn later opens) without rescanning.+pub(crate) fn claim_recovery(workspace_dir: &Path) -> bool {+ state()+ .recovered_workspaces+ .insert(workspace_dir.to_path_buf())+}++/// Let `workspace_dir` be recovered again (a profile re-leased after release),+/// and drop its cached router when nothing is using it so the next scan replays+/// the log another holder may have appended to. A router still in use stays,+/// so a log never has two writers.+pub(crate) fn forget_recovery(workspace_dir: &Path) {+ let mut st = state();+ st.recovered_workspaces.remove(workspace_dir);+ let idle = st+ .routers+ .get(workspace_dir)+ .is_some_and(|e| Arc::strong_count(e) == 1 && Arc::strong_count(&e.router) == 1);+ if idle {+ st.routers.remove(workspace_dir);+ }+}diff --git a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rsindex f69fffa248..ca9c40bf4c 100644--- a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs@@ -78,9 +78,8 @@ impl OpenHumanSessionHost {// Busy state for background-result delivery is marked here, in the// turn's own (profile) scope; the bus subscriber runs off-task.// A guard, so a turn dropped mid-flight does not leave it busy.- let busy = crate::agent::orchestration::busy_guard::TurnBusy::start(- self.event_session_id(),- );+ let busy =+ crate::agent::orchestration::busy_guard::TurnBusy::start(self.event_session_id());BUS.publish(DomainEvent::AgentTurnStarted {session_id: self.event_session_id().to_string(),channel: self.event_channel().to_string(),