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
Merge remote-tracking branch 'upstream/main' into epic-8131-440-host-storage
Steven Enamakelc6f2f17a92e9
diff --cc Cargo.lockindex fff14bc586,a6cb81f8ec..132bbfda01--- a/Cargo.lock+++ b/Cargo.lock@@@ -8544,11 -8572,10 +8578,10 @@@ dependencies ="tinyagents-definition","tinyagents-graph","tinyagents-harness",- "tinyagents-runtime","tinyagents-session",+ "tinyagents-storage-kit","tinyagents-tasks","tinyinference-llm 0.4.1",- "tinystoragedrivers-core","tinytools","tokio","tracing",diff --cc crates/openhuman-core/src/config/schema/mod.rsindex 2fb99eb3f1,14feb3eac4..96654596a8--- a/crates/openhuman-core/src/config/schema/mod.rs+++ b/crates/openhuman-core/src/config/schema/mod.rs@@@ -32,15 -32,14 +32,16 @@@ pub use hosting::HostingConfigpub mod storage;pub use storage::StorageConfig;pub mod profile_layout;-pub use profile_layout::{users_dir, ProfileLayout};+pub use profile_layout::{ProfileLayout, users_dir};mod identity_cost;+ mod inbound_debounce;pub(crate) mod load;pub(crate) use load::config_from_toml_str;-pub(crate) use load::source::storage_schema::storage_schema as config_storage_schema;+pub(crate) use load::source::storage_schema::collection_specs as config_storage_collections;+#[cfg(feature = "legacy-import")]+pub(crate) use load::source::storage_schema::upgrade_records as upgrade_config_records;pub use load::{- action_dir_env_override, active_user_marker_path, active_workspace_dir,+ PRE_LOGIN_USER_ID, action_dir_env_override, active_user_marker_path, active_workspace_dir,active_workspace_dir_cached, active_workspace_snapshot, clear_active_user, default_action_dir,default_files_dir, default_projects_dir, default_root_openhuman_dir, pre_login_user_dir,read_active_user_id, resolve_action_dir, resolve_files_dir, user_openhuman_dir,diff --cc crates/openhuman-core/src/core/runtime/context.rsindex a3583eda48,b30b55bb5f..a3490471ae--- a/crates/openhuman-core/src/core/runtime/context.rs+++ b/crates/openhuman-core/src/core/runtime/context.rs@@@ -142,198 -138,6 +142,7 @@@ struct WorkspaceBinding}impl CoreContext {- /// Run the core initialization sequence and return the context plus whether- /// an operator-supplied RPC bearer exists (for the public-bind safety check- /// in `openhuman_rpc::server::serve`) plus the loaded config, when boot reached- /// workspace-bound init. Order is load-bearing and mirrors the original- /// `run_server_inner` sequence:- ///- /// 1. register controllers, 2. master key, 3. seed RPC bearer,- /// 4. workspace stores ([`init_stores`]), 5. pure runtime registration.- ///- /// `preloaded_config` lets an embedder supply the [`Config`] outright- /// instead of having step 4 discover one from disk and the environment. See- /// [`init_with_config`](Self::init_with_config) for why that matters.- pub async fn init(- host_kind: HostKind,- token: &TokenSource,- domains: crate::core::runtime::DomainSet,- ) -> anyhow::Result<(Arc<CoreContext>, bool, Option<crate::config::Config>)> {- Self::init_with_config(host_kind, token, domains, Default::default(), None).await- }-- /// [`init`](Self::init) with an optional caller-supplied configuration.- ///- /// Passing `Some(config)` skips `Config::load_or_init()` entirely — the- /// config is used verbatim, exactly as loaded config would be. This is the- /// seam that lets a library embedder configure the core with struct fields- /// rather than by mutating the process environment before `build()`, which- /// is order-dependent, process-global, and invisible at the call site.- ///- /// Note it does not make the core hermetic on its own: `init_stores`, the- /// session database and the keyring still write beneath- /// `config.workspace_dir`. It decides *where*, not *whether*.- pub async fn init_with_config(- host_kind: HostKind,- token: &TokenSource,- mut domains: crate::core::runtime::DomainSet,- mut tool_groups: crate::tools::toolpacks::ToolGroups,- preloaded_config: Option<crate::config::Config>,- ) -> anyhow::Result<(Arc<CoreContext>, bool, Option<crate::config::Config>)> {- log::debug!(- "[core-context] init: host_kind={host_kind:?} domains={domains:?} \- tool_groups={tool_groups:?}"- );- crate::core::runtime::mode::admit_core(host_kind, DEFAULT_CONTEXT.get().is_some())- .map_err(|e| anyhow::anyhow!("[core-context] {e}"))?;- // 1. Ensure all controllers are registered before anything dispatches.- let _ = crate::core::all::all_registered_controllers();-- // 2. Load the master encryption key before any config/credential op that- // needs to decrypt secrets. No-op if already called (e.g. from- // run_core_from_args for the CLI).- if let Some(config) = &preloaded_config {- crate::security::secret_storage::init_workspace(&config.workspace_dir);- }- crate::security::secret_storage::init_master_key().map_err(anyhow::Error::msg)?;-- // 4. Seed the per-process RPC bearer. `Fixed` seeds the in-memory value- // directly (never touches the env); `EnvOrFile` reads- // OPENHUMAN_CORE_TOKEN or generates + writes {root}/core.token.- //- // `has_operator_token` records whether an OPERATOR-supplied bearer- // exists (in-memory handoff or env var). The self-generated core.token- // file does NOT count — remote clients cannot read it — so it must not- // satisfy the public-bind safety check in `serve`.- let has_operator_token = match token {- TokenSource::Fixed(token) => {- crate::core::auth::init_rpc_token_with_value(token)?;- !token.trim().is_empty()- }- TokenSource::EnvOrFile => {- // A caller-supplied config scopes the core's state, so a- // self-generated bearer must land beside it rather than under- // the operator's real `~/.openhuman` root — otherwise an- // "ephemeral" harness still writes a `core.token` into the- // operator's install. Fall back to the default root only when- // no config was supplied.- let token_dir = preloaded_config- .as_ref()- .map(|cfg| {- cfg.config_path- .parent()- .map(|p| p.to_path_buf())- .unwrap_or_else(|| cfg.config_path.clone())- })- .unwrap_or_else(|| {- crate::config::default_root_openhuman_dir().unwrap_or_else(|_| {- dirs::home_dir()- .unwrap_or_else(|| std::path::PathBuf::from("."))- .join(".openhuman")- })- });- crate::core::auth::init_rpc_token(&token_dir)?;- std::env::var(crate::core::auth::CORE_TOKEN_ENV_VAR)- .ok()- .filter(|s| !s.trim().is_empty())- .is_some()- }- };-- // 5. Resolve config once, then initialize workspace-bound stores- // (memory, attachments, people) with that exact workspace.- // Kept for the context: `preloaded_config` is consumed below, and the- // whole point is that handlers can reach it after boot.- let embedder_config = preloaded_config.clone();- let latest_embedder_config = embedder_config.clone().map(|config| {- let snapshot = Arc::new(std::sync::Mutex::new(config));- crate::config::Config::bind_context_snapshot(&snapshot);- snapshot- });- let loaded = match preloaded_config {- // A supplied config is authoritative: no disk read, no env overlay,- // and no `Err` arm to reach, because there was nothing to fail.- Some(cfg) => {- log::debug!("[core-context] init: using caller-supplied config (scoped workspace)");- Ok(cfg)- }- None => crate::config::Config::load_or_init().await,- };- // `[components]` can only narrow what the host chose.- let components = match &loaded {- Ok(cfg) => crate::core::runtime::ComponentSet::from_config(&cfg.components),- Err(_) => crate::core::runtime::ComponentSet::all(),- };- domains = components.narrow_domains(domains);- tool_groups = components.narrow_tool_groups(tool_groups);- log::debug!("[core-context] init: components={components:?} effective domains={domains:?}");- let config = match loaded {- Ok(cfg) => {- init_stores(&cfg, domains).await;- Some(cfg)- }- Err(e) => {- log::error!(- "[boot] workspace-bound store init SKIPPED — \- Config::load_or_init failed ({e:#}). Memory persistence is \- DISABLED for this run; no silent fallback to the default \- workspace (which would cause chunk loss / cross-workspace \- bleed-over). Fix config.toml or set OPENHUMAN_WORKSPACE to a \- writable path, then restart."- );- None- }- };- let workspace_dir = config.as_ref().map(|cfg| cfg.workspace_dir.clone());-- // Construct and publish the context before bootstrap. Host-installed- // session providers may resolve their cold-boot recovery workspace via- // CoreContext, which does not exist until this point.- let ctx = Arc::new(CoreContext {- host_kind,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: workspace_dir.clone(),- }))),- domains,- tool_groups,- autonomy_tier_source: if embedder_config.is_some() {- super::AutonomyTierSource::Captured- } else {- super::AutonomyTierSource::LiveConfig- },- autonomy_tier_ceiling: None,- components,- embedder_config,- latest_embedder_config,- user_skill_roots: true,- extensions: Default::default(),- turn_origin: None,- channel_thread: None,- session_agent: None,- profile: None,- profile_admission: Arc::new(()),- agent: Default::default(),- bare: false,- });- let _ = DEFAULT_CONTEXT.set(ctx.clone());-- // 6. Long-lived runtime infrastructure: event bus, domain subscribers,- // ledgers, agent-definition registry, live security policy, approval- // gate, socket manager. Idempotent (Once-guarded internally). Selected- // background jobs start later, from CoreRuntime::start_services(), after a transport binds- // succeeds.- let runtime_config = config.clone();- super::bootstrap::bootstrap_core_runtime(- host_kind,- config,- domains,- &super::DispatchCtx::new(ctx.clone()),- )- .await;-- Ok((ctx, has_operator_token, runtime_config))- }+/// The host that constructed this context (Tauri shell / CLI / Docker).pub fn host_kind(&self) -> HostKind {self.host_kind@@@ -388,16 -192,9 +197,16 @@@parent_config: &crate::config::Config,overlay: ContextOverlay,) -> Arc<CoreContext> {- self.derive_with_parent_config_inner(Some(parent_config), overlay)+ self.derive_with_parent_config_inner(Some(parent_config), overlay, false)}+ /// Whether `other` descends from the same admitted profile context+ /// generation. This differs from context pointer identity: turn contexts+ /// may be derived while the profile remains admitted.+ pub(crate) fn shares_profile_admission(&self, other: &Self) -> bool {+ Arc::ptr_eq(&self.profile_admission, &other.profile_admission)+ }+fn derive_with_parent_config_inner(&self,parent_config: Option<&crate::config::Config>,diff --cc crates/openhuman-core/src/core/runtime/context_boot.rsindex 0000000000,30f2bc55a3..28ad5d4eafmode 000000,100644..100644--- a/crates/openhuman-core/src/core/runtime/context_boot.rs+++ b/crates/openhuman-core/src/core/runtime/context_boot.rs@@@ -1,0 -1,247 +1,248 @@@+ use super::*;+ use crate::core::runtime::TokenSource;++ impl CoreContext {+ /// Run the core initialization sequence and return the context plus whether+ /// an operator-supplied RPC bearer exists (for the public-bind safety check+ /// in `openhuman_rpc::server::serve`) plus the loaded config, when boot reached+ /// workspace-bound init. Order is load-bearing and mirrors the original+ /// `run_server_inner` sequence:+ ///+ /// 1. register controllers, 2. master key, 3. seed RPC bearer,+ /// 4. workspace stores ([`init_stores`]), 5. pure runtime registration.+ ///+ /// `preloaded_config` lets an embedder supply the [`Config`] outright+ /// instead of having step 4 discover one from disk and the environment. See+ /// [`init_with_config`](Self::init_with_config) for why that matters.+ pub async fn init(+ host_kind: HostKind,+ token: &TokenSource,+ domains: crate::core::runtime::DomainSet,+ ) -> anyhow::Result<(Arc<CoreContext>, bool, Option<crate::config::Config>)> {+ Self::init_with_config(host_kind, token, domains, Default::default(), None).await+ }++ /// [`init`](Self::init) with an optional caller-supplied configuration.+ ///+ /// Passing `Some(config)` skips `Config::load_or_init()` entirely — the+ /// config is used verbatim, exactly as loaded config would be. This is the+ /// seam that lets a library embedder configure the core with struct fields+ /// rather than by mutating the process environment before `build()`, which+ /// is order-dependent, process-global, and invisible at the call site.+ ///+ /// Note it does not make the core hermetic on its own: `init_stores`, the+ /// session database and the keyring still write beneath+ /// `config.workspace_dir`. It decides *where*, not *whether*.+ pub async fn init_with_config(+ host_kind: HostKind,+ token: &TokenSource,+ domains: crate::core::runtime::DomainSet,+ tool_groups: crate::tools::toolpacks::ToolGroups,+ preloaded_config: Option<crate::config::Config>,+ ) -> anyhow::Result<(Arc<CoreContext>, bool, Option<crate::config::Config>)> {+ Self::init_with_boot_mode(+ host_kind,+ token,+ domains,+ tool_groups,+ preloaded_config,+ crate::core::runtime::CoreBootMode::Normal,+ )+ .await+ }++ /// [`init_with_config`](Self::init_with_config) with an explicit startup+ /// policy. Inspection mode uses the supplied config but skips every+ /// persistent workspace/bootstrap effect while retaining a real dispatch+ /// context.+ pub(crate) async fn init_with_boot_mode(+ host_kind: HostKind,+ token: &TokenSource,+ mut domains: crate::core::runtime::DomainSet,+ mut tool_groups: crate::tools::toolpacks::ToolGroups,+ preloaded_config: Option<crate::config::Config>,+ boot_mode: crate::core::runtime::CoreBootMode,+ ) -> anyhow::Result<(Arc<CoreContext>, bool, Option<crate::config::Config>)> {+ if boot_mode == crate::core::runtime::CoreBootMode::Inspection {+ anyhow::ensure!(+ preloaded_config.is_some(),+ "inspection boot requires a caller-supplied config"+ );+ anyhow::ensure!(+ matches!(token, TokenSource::Fixed(_)),+ "inspection boot requires a process-local fixed RPC bearer"+ );+ }+ log::debug!(+ "[core-context] init: host_kind={host_kind:?} domains={domains:?} \+ tool_groups={tool_groups:?}"+ );+ crate::core::runtime::mode::admit_core(host_kind, DEFAULT_CONTEXT.get().is_some())+ .map_err(|e| anyhow::anyhow!("[core-context] {e}"))?;+ // 1. Ensure all controllers are registered before anything dispatches.+ let _ = crate::core::all::all_registered_controllers();++ // 2. Load the master encryption key before any config/credential op that+ // needs to decrypt secrets. No-op if already called (e.g. from+ // run_core_from_args for the CLI).+ if boot_mode == crate::core::runtime::CoreBootMode::Normal {+ if let Some(config) = &preloaded_config {+ crate::security::secret_storage::init_workspace(&config.workspace_dir);+ }+ crate::security::secret_storage::init_master_key().map_err(anyhow::Error::msg)?;+ }++ // 4. Seed the per-process RPC bearer. `Fixed` seeds the in-memory value+ // directly (never touches the env); `EnvOrFile` reads+ // OPENHUMAN_CORE_TOKEN or generates + writes {root}/core.token.+ //+ // `has_operator_token` records whether an OPERATOR-supplied bearer+ // exists (in-memory handoff or env var). The self-generated core.token+ // file does NOT count — remote clients cannot read it — so it must not+ // satisfy the public-bind safety check in `serve`.+ let has_operator_token = match token {+ TokenSource::Fixed(token) => {+ crate::core::auth::init_rpc_token_with_value(token)?;+ !token.trim().is_empty()+ }+ TokenSource::EnvOrFile => {+ // A caller-supplied config scopes the core's state, so a+ // self-generated bearer must land beside it rather than under+ // the operator's real `~/.openhuman` root — otherwise an+ // "ephemeral" harness still writes a `core.token` into the+ // operator's install. Fall back to the default root only when+ // no config was supplied.+ let token_dir = preloaded_config+ .as_ref()+ .map(|cfg| {+ cfg.config_path+ .parent()+ .map(|p| p.to_path_buf())+ .unwrap_or_else(|| cfg.config_path.clone())+ })+ .unwrap_or_else(|| {+ crate::config::default_root_openhuman_dir().unwrap_or_else(|_| {+ dirs::home_dir()+ .unwrap_or_else(|| std::path::PathBuf::from("."))+ .join(".openhuman")+ })+ });+ crate::core::auth::init_rpc_token(&token_dir)?;+ std::env::var(crate::core::auth::CORE_TOKEN_ENV_VAR)+ .ok()+ .filter(|s| !s.trim().is_empty())+ .is_some()+ }+ };++ // 5. Resolve config once, then initialize workspace-bound stores+ // (memory, attachments, people) with that exact workspace.+ // Kept for the context: `preloaded_config` is consumed below, and the+ // whole point is that handlers can reach it after boot.+ let embedder_config = preloaded_config.clone();+ let latest_embedder_config = embedder_config.clone().map(|config| {+ let snapshot = Arc::new(std::sync::Mutex::new(config));+ crate::config::Config::bind_context_snapshot(&snapshot);+ snapshot+ });+ let loaded = match preloaded_config {+ // A supplied config is authoritative: no disk read, no env overlay,+ // and no `Err` arm to reach, because there was nothing to fail.+ Some(cfg) => {+ log::debug!("[core-context] init: using caller-supplied config (scoped workspace)");+ Ok(cfg)+ }+ None => crate::config::Config::load_or_init().await,+ };+ // `[components]` can only narrow what the host chose.+ let components = match &loaded {+ Ok(cfg) => crate::core::runtime::ComponentSet::from_config(&cfg.components),+ Err(_) => crate::core::runtime::ComponentSet::all(),+ };+ domains = components.narrow_domains(domains);+ tool_groups = components.narrow_tool_groups(tool_groups);+ log::debug!("[core-context] init: components={components:?} effective domains={domains:?}");+ let config = match loaded {+ Ok(cfg) => {+ if boot_mode == crate::core::runtime::CoreBootMode::Normal {+ init_stores(&cfg, domains).await;+ }+ Some(cfg)+ }+ Err(e) => {+ log::error!(+ "[boot] workspace-bound store init SKIPPED — \+ Config::load_or_init failed ({e:#}). Memory persistence is \+ DISABLED for this run; no silent fallback to the default \+ workspace (which would cause chunk loss / cross-workspace \+ bleed-over). Fix config.toml or set OPENHUMAN_WORKSPACE to a \+ writable path, then restart."+ );+ None+ }+ };+ let workspace_dir = config.as_ref().map(|cfg| cfg.workspace_dir.clone());++ // Construct the runtime context before bootstrap. Inspection contexts+ // stay local and no-store; normal hosts still publish the process+ // default before their session provider can request it.+ let ctx = if boot_mode == crate::core::runtime::CoreBootMode::Inspection {+ super::CoreContext::for_runtime_inspection(+ config+ .clone()+ .expect("inspection boot validated its preloaded config"),+ host_kind,+ domains,+ tool_groups,+ )+ } else {+ let context = Arc::new(CoreContext {+ host_kind,+ workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {+ workspace_dir: workspace_dir.clone(),+ config_path: config.as_ref().map(|cfg| cfg.config_path.clone()),+ }))),+ domains,+ tool_groups,+ autonomy_tier_source: if embedder_config.is_some() {+ super::AutonomyTierSource::Captured+ } else {+ super::AutonomyTierSource::LiveConfig+ },+ autonomy_tier_ceiling: None,+ components,+ embedder_config,+ latest_embedder_config,+ user_skill_roots: true,+ extensions: Default::default(),+ turn_origin: None,+ channel_thread: None,+ session_agent: None,+ profile: None,++ profile_admission: Arc::new(()),+ agent: Default::default(),+ bare: false,+ });+ let _ = DEFAULT_CONTEXT.set(context.clone());+ context+ };++ // 6. Long-lived runtime infrastructure: event bus, domain subscribers,+ // ledgers, agent-definition registry, live security policy, approval+ // gate, socket manager. Idempotent (Once-guarded internally). Selected+ // background jobs start later, from CoreRuntime::start_services(), after a transport binds+ // succeeds.+ let runtime_config = config.clone();+ if boot_mode == crate::core::runtime::CoreBootMode::Normal {+ crate::core::runtime::bootstrap::bootstrap_core_runtime(+ host_kind,+ config,+ domains,+ &crate::core::runtime::DispatchCtx::new(ctx.clone()),+ )+ .await;+ }++ Ok((ctx, has_operator_token, runtime_config))+ }+ }diff --cc crates/openhuman-core/src/core/runtime/context_inspection.rsindex 0000000000,cd96010f9f..59ba1ccf6bmode 000000,100644..100644--- a/crates/openhuman-core/src/core/runtime/context_inspection.rs+++ b/crates/openhuman-core/src/core/runtime/context_inspection.rs@@@ -1,0 -1,64 +1,65 @@@+ use super::*;++ impl CoreContext {+ /// Derive a no-store context for read-only inspection under a selected+ /// config. It inherits host registrations and policies while owning fresh+ /// agent state slots; the parent's tenant and agent identities are retained.+ pub fn derive_for_inspection(&self, mut overlay: ContextOverlay) -> Arc<CoreContext> {+ let components =+ crate::core::runtime::ComponentSet::from_config(&overlay.config.components);+ overlay.domains = components.narrow_domains(overlay.domains);+ overlay.tool_groups = components.narrow_tool_groups(overlay.tool_groups);+ let parent_config = self.latest_embedder_config();+ self.derive_with_parent_config_inner(parent_config.as_ref(), overlay, true)+ }++ /// Construct a no-store inspection context before runtime boot. It carries+ /// the supplied config only for the scoped inspection and does not publish+ /// a process-default context or initialize stores.+ pub fn for_inspection(config: crate::config::Config) -> Arc<CoreContext> {+ Self::for_runtime_inspection(+ config,+ HostKind::Cli,+ crate::core::runtime::DomainSet::full(),+ Default::default(),+ )+ }++ /// Build an inspection runtime context while retaining the host's selected+ /// domains and tool groups. The builder merges its scoped extensions after+ /// this constructor returns.+ pub(super) fn for_runtime_inspection(+ config: crate::config::Config,+ host_kind: HostKind,+ domains: crate::core::runtime::DomainSet,+ tool_groups: crate::tools::toolpacks::ToolGroups,+ ) -> Arc<CoreContext> {+ let components = crate::core::runtime::ComponentSet::from_config(&config.components);+ let domains = components.narrow_domains(domains);+ let tool_groups = components.narrow_tool_groups(tool_groups);+ let latest_embedder_config = Some(Arc::new(std::sync::Mutex::new(config.clone())));+ Arc::new(CoreContext {+ host_kind,+ workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {+ workspace_dir: Some(config.workspace_dir.clone()),+ config_path: Some(config.config_path.clone()),+ }))),+ domains,+ tool_groups,+ autonomy_tier_source: super::AutonomyTierSource::Captured,+ autonomy_tier_ceiling: None,+ components,+ embedder_config: Some(config),+ latest_embedder_config,+ user_skill_roots: true,+ extensions: Default::default(),+ turn_origin: None,+ channel_thread: None,+ session_agent: None,+ profile: None,++ profile_admission: Arc::new(()),+ agent: Default::default(),+ bare: false,+ })+ }+ }diff --cc crates/openhuman-core/src/profiles/host_migration_fence_tests.rsindex 0000000000,0000000000..06d877f535new file mode 100644--- /dev/null+++ b/crates/openhuman-core/src/profiles/host_migration_fence_tests.rs@@@ -1,0 -1,0 +1,176 @@@++use super::*;++++#[tokio::test]++async fn provisioning_with_a_new_root_replaces_a_dead_higher_epoch_fence() {++ const CHILD: &str = "OPENHUMAN_PROFILE_DEAD_HIGHER_FENCE_CHILD";++ if std::env::var_os(CHILD).is_none() {++ let output = std::process::Command::new(std::env::current_exe().unwrap())++ .args([++ "--exact",++ "profiles::host::tests::provisioning_with_a_new_root_replaces_a_dead_higher_epoch_fence",++ "--nocapture",++ ])++ .env(CHILD, "1")++ .output()++ .unwrap();++ assert!(++ output.status.success(),++ "isolated profile fence child failed:\n{}\n{}",++ String::from_utf8_lossy(&output.stdout),++ String::from_utf8_lossy(&output.stderr)++ );++ let stdout = String::from_utf8_lossy(&output.stdout);++ assert!(++ stdout.contains("running 1 test"),++ "child selected no test: {stdout}"++ );++ assert!(stdout.contains("test profiles::host::tests::provisioning_with_a_new_root_replaces_a_dead_higher_epoch_fence"), "expected child test did not run: {stdout}");++ assert!(++ stdout.contains("test result: ok. 1 passed"),++ "child did not pass exactly one test: {stdout}"++ );++ return;++ }++++ let _storage_slot = crate::storage::test_support::lock_storage_slot();++ let first_root = tempfile::tempdir().unwrap();++ let second_root = tempfile::tempdir().unwrap();++ let id = profile(&format!("cron-fence-{}", uuid::Uuid::new_v4().simple()));++ let registry = crate::storage::fence::registry();++ let backend: Arc<dyn crate::storage::StorageBackend> =++ Arc::new(crate::storage::fenced_backend::FencedBackend::new(++ crate::storage::test_support::memory_backend(),++ Arc::clone(®istry),++ ));++ let _storage = RestoreInstalledStorage(crate::storage::install(backend));++++ let mut first_saas = SaasConfig::new(first_root.path());++ first_saas.cron.agent_jobs_only = true;++ first_saas.cron.max_active_jobs = 1;++ let first = ProfileHost::new(first_saas, CoreContext::for_test(DomainSet::full(), None));++ first.provision(&id).await.unwrap();++ let opened = first.open(&id).await.unwrap();++ let old_epoch = opened.lease_fence().epoch();++ let _retire_stale_fence = RetireProfileFence {++ registry: Arc::clone(®istry),++ profile_id: id.as_str().to_string(),++ epoch: old_epoch,++ };++ drop(opened);++ drop(first);++++ let mut second_saas = SaasConfig::new(second_root.path());++ second_saas.cron.agent_jobs_only = true;++ second_saas.cron.max_active_jobs = 1;++ let second = ProfileHost::new(second_saas, CoreContext::for_test(DomainSet::full(), None));++ let provisioned = second.provision(&id).await;++ assert!(++ provisioned.unwrap(),++ "the new root must be able to register its own profile fence"++ );++}++++#[tokio::test]++async fn opening_replaces_a_dropped_hosts_fence_before_cron_reconciliation() {++ const CHILD: &str = "OPENHUMAN_PROFILE_REOPEN_DROPPED_FENCE_CHILD";++ if std::env::var_os(CHILD).is_none() {++ let output = std::process::Command::new(std::env::current_exe().unwrap())++ .args([++ "--exact",++ "profiles::host::tests::opening_replaces_a_dropped_hosts_fence_before_cron_reconciliation",++ "--nocapture",++ ])++ .env(CHILD, "1")++ .output()++ .unwrap();++ assert!(++ output.status.success(),++ "isolated profile reopen child failed:\n{}\n{}",++ String::from_utf8_lossy(&output.stdout),++ String::from_utf8_lossy(&output.stderr)++ );++ let stdout = String::from_utf8_lossy(&output.stdout);++ assert!(++ stdout.contains("running 1 test"),++ "child selected no test: {stdout}"++ );++ assert!(stdout.contains("test profiles::host::tests::opening_replaces_a_dropped_hosts_fence_before_cron_reconciliation"), "expected child test did not run: {stdout}");++ assert!(++ stdout.contains("test result: ok. 1 passed"),++ "child did not pass exactly one test: {stdout}"++ );++ return;++ }++++ let _storage_slot = crate::storage::test_support::lock_storage_slot();++ let tmp = tempfile::tempdir().unwrap();++ let id = profile(&format!("cron-fence-{}", uuid::Uuid::new_v4().simple()));++ let registry = crate::storage::fence::registry();++ let backend: Arc<dyn crate::storage::StorageBackend> =++ Arc::new(crate::storage::fenced_backend::FencedBackend::new(++ crate::storage::test_support::memory_backend(),++ Arc::clone(®istry),++ ));++ let _storage = RestoreInstalledStorage(crate::storage::install(backend));++++ let mut first_saas = SaasConfig::new(tmp.path());++ first_saas.cron.agent_jobs_only = true;++ first_saas.cron.max_active_jobs = 1;++ let first = ProfileHost::new(first_saas, CoreContext::for_test(DomainSet::full(), None));++ first.provision(&id).await.unwrap();++ let opened = first.open(&id).await.unwrap();++ let old_epoch = opened.lease_fence().epoch();++ let _retire_stale_fence = RetireProfileFence {++ registry: Arc::clone(®istry),++ profile_id: id.as_str().to_string(),++ epoch: old_epoch,++ };++ drop(opened);++ drop(first);++++ let mut second_saas = SaasConfig::new(tmp.path());++ second_saas.cron.agent_jobs_only = true;++ second_saas.cron.max_active_jobs = 1;++ let second = ProfileHost::new(second_saas, CoreContext::for_test(DomainSet::full(), None));++ assert!(!second.provision(&id).await.unwrap());++ let reopened = second.open(&id).await;++ assert!(++ reopened.is_ok(),++ "the later lease in this root must replace the dropped host's profile fence"++ );++}++++#[tokio::test]++async fn disabling_profile_cron_limits_clears_the_persisted_store_cap() {++ let tmp = tempfile::tempdir().unwrap();++ let id = profile("cron-cap-toggle-off");++ let mut saas = SaasConfig::new(tmp.path());++ saas.cron.agent_jobs_only = true;++ saas.cron.max_active_jobs = 1;++ let enforced = ProfileHost::new(saas, CoreContext::for_test(DomainSet::full(), None));++ enforced.provision(&id).await.unwrap();++ let config = enforced.provisioned_config(&id).await.unwrap();++ let scope = crate::cron::documents_port::DocScope::for_scope(++ &config,++ crate::storage::scope_for_profile(id.as_str()),++ );++ crate::cron::client::store_in::<crate::cron::CronJob>(&config, &scope, raw_profile_agent_add())++ .await++ .unwrap();++++ let unenforced = ProfileHost::new(++ SaasConfig::new(tmp.path()),++ CoreContext::for_test(DomainSet::full(), None),++ );++ unenforced.provision(&id).await.unwrap();++ let _profile = unenforced.open(&id).await.unwrap();++ let config = unenforced.provisioned_config(&id).await.unwrap();++ let scope = crate::cron::documents_port::DocScope::for_scope(++ &config,++ crate::storage::scope_for_profile(id.as_str()),++ );++++ crate::cron::client::store_in::<crate::cron::CronJob>(&config, &scope, raw_profile_agent_add())++ .await++ .expect("disabling operator policy should clear its persisted cap");++}diff --cc crates/openhuman-core/src/profiles/host_tests.rsindex 9f6f4d1901,db6c6000b4..28698bf773--- a/crates/openhuman-core/src/profiles/host_tests.rs+++ b/crates/openhuman-core/src/profiles/host_tests.rs@@@ -507,177 -737,5 +737,10 @@@ async fn opening_an_existing_profile_ad.contains("Failed to insert cron agent job"));}- #[tokio::test]- async fn provisioning_with_a_new_root_replaces_a_dead_higher_epoch_fence() {- const CHILD: &str = "OPENHUMAN_PROFILE_DEAD_HIGHER_FENCE_CHILD";- if std::env::var_os(CHILD).is_none() {- let output = std::process::Command::new(std::env::current_exe().unwrap())- .args([- "--exact",- "profiles::host::tests::provisioning_with_a_new_root_replaces_a_dead_higher_epoch_fence",- "--nocapture",- ])- .env(CHILD, "1")- .output()- .unwrap();- assert!(- output.status.success(),- "isolated profile fence child failed:\n{}\n{}",- String::from_utf8_lossy(&output.stdout),- String::from_utf8_lossy(&output.stderr)- );- let stdout = String::from_utf8_lossy(&output.stdout);- assert!(- stdout.contains("running 1 test"),- "child selected no test: {stdout}"- );- assert!(stdout.contains("test profiles::host::tests::provisioning_with_a_new_root_replaces_a_dead_higher_epoch_fence"), "expected child test did not run: {stdout}");- assert!(- stdout.contains("test result: ok. 1 passed"),- "child did not pass exactly one test: {stdout}"- );- return;- }-- let _storage_slot = crate::storage::test_support::lock_storage_slot();- let first_root = tempfile::tempdir().unwrap();- let second_root = tempfile::tempdir().unwrap();- let id = profile(&format!("cron-fence-{}", uuid::Uuid::new_v4().simple()));- let registry = crate::storage::fence::registry();- let backend: Arc<dyn crate::storage::StorageBackend> =- Arc::new(crate::storage::fenced_backend::FencedBackend::new(- crate::storage::test_support::memory_backend(),- Arc::clone(®istry),- ));- let _storage = RestoreInstalledStorage(crate::storage::install(backend));-- let mut first_saas = SaasConfig::new(first_root.path());- first_saas.cron.agent_jobs_only = true;- first_saas.cron.max_active_jobs = 1;- let first = ProfileHost::new(first_saas, CoreContext::for_test(DomainSet::full(), None));- first.provision(&id).await.unwrap();- let opened = first.open(&id).await.unwrap();- let old_epoch = opened.lease_fence().epoch();- let _retire_stale_fence = RetireProfileFence {- registry: Arc::clone(®istry),- profile_id: id.as_str().to_string(),- epoch: old_epoch,- };- drop(opened);- drop(first);-- let mut second_saas = SaasConfig::new(second_root.path());- second_saas.cron.agent_jobs_only = true;- second_saas.cron.max_active_jobs = 1;- let second = ProfileHost::new(second_saas, CoreContext::for_test(DomainSet::full(), None));- let provisioned = second.provision(&id).await;- assert!(- provisioned.unwrap(),- "the new root must be able to register its own profile fence"- );- }-- #[tokio::test]- async fn opening_replaces_a_dropped_hosts_fence_before_cron_reconciliation() {- const CHILD: &str = "OPENHUMAN_PROFILE_REOPEN_DROPPED_FENCE_CHILD";- if std::env::var_os(CHILD).is_none() {- let output = std::process::Command::new(std::env::current_exe().unwrap())- .args([- "--exact",- "profiles::host::tests::opening_replaces_a_dropped_hosts_fence_before_cron_reconciliation",- "--nocapture",- ])- .env(CHILD, "1")- .output()- .unwrap();- assert!(- output.status.success(),- "isolated profile reopen child failed:\n{}\n{}",- String::from_utf8_lossy(&output.stdout),- String::from_utf8_lossy(&output.stderr)- );- let stdout = String::from_utf8_lossy(&output.stdout);- assert!(- stdout.contains("running 1 test"),- "child selected no test: {stdout}"- );- assert!(stdout.contains("test profiles::host::tests::opening_replaces_a_dropped_hosts_fence_before_cron_reconciliation"), "expected child test did not run: {stdout}");- assert!(- stdout.contains("test result: ok. 1 passed"),- "child did not pass exactly one test: {stdout}"- );- return;- }-- let _storage_slot = crate::storage::test_support::lock_storage_slot();- let tmp = tempfile::tempdir().unwrap();- let id = profile(&format!("cron-fence-{}", uuid::Uuid::new_v4().simple()));- let registry = crate::storage::fence::registry();- let backend: Arc<dyn crate::storage::StorageBackend> =- Arc::new(crate::storage::fenced_backend::FencedBackend::new(- crate::storage::test_support::memory_backend(),- Arc::clone(®istry),- ));- let _storage = RestoreInstalledStorage(crate::storage::install(backend));-- let mut first_saas = SaasConfig::new(tmp.path());- first_saas.cron.agent_jobs_only = true;- first_saas.cron.max_active_jobs = 1;- let first = ProfileHost::new(first_saas, CoreContext::for_test(DomainSet::full(), None));- first.provision(&id).await.unwrap();- let opened = first.open(&id).await.unwrap();- let old_epoch = opened.lease_fence().epoch();- let _retire_stale_fence = RetireProfileFence {- registry: Arc::clone(®istry),- profile_id: id.as_str().to_string(),- epoch: old_epoch,- };- drop(opened);- drop(first);-- let mut second_saas = SaasConfig::new(tmp.path());- second_saas.cron.agent_jobs_only = true;- second_saas.cron.max_active_jobs = 1;- let second = ProfileHost::new(second_saas, CoreContext::for_test(DomainSet::full(), None));- assert!(!second.provision(&id).await.unwrap());- let reopened = second.open(&id).await;- assert!(- reopened.is_ok(),- "the later lease in this root must replace the dropped host's profile fence"- );- }-- #[tokio::test]- async fn disabling_profile_cron_limits_clears_the_persisted_store_cap() {- let tmp = tempfile::tempdir().unwrap();- let id = profile("cron-cap-toggle-off");- let mut saas = SaasConfig::new(tmp.path());- saas.cron.agent_jobs_only = true;- saas.cron.max_active_jobs = 1;- let enforced = ProfileHost::new(saas, CoreContext::for_test(DomainSet::full(), None));- enforced.provision(&id).await.unwrap();- let config = enforced.provisioned_config(&id).await.unwrap();- let scope = crate::cron::documents_port::DocScope::for_scope(- &config,- crate::storage::scope_for_profile(id.as_str()),- );- crate::cron::client::store_in::<crate::cron::CronJob>(&config, &scope, raw_profile_agent_add())- .await- .unwrap();++#[path = "host_migration_fence_tests.rs"]++mod migration_fence_tests;+- let unenforced = ProfileHost::new(- SaasConfig::new(tmp.path()),- CoreContext::for_test(DomainSet::full(), None),- );- unenforced.provision(&id).await.unwrap();- let _profile = unenforced.open(&id).await.unwrap();- let config = unenforced.provisioned_config(&id).await.unwrap();- let scope = crate::cron::documents_port::DocScope::for_scope(- &config,- crate::storage::scope_for_profile(id.as_str()),- );-- crate::cron::client::store_in::<crate::cron::CronJob>(&config, &scope, raw_profile_agent_add())- .await- .expect("disabling operator policy should clear its persisted cap");- }++#[path = "host_fence_tests.rs"]++mod fence_tests;+ #[path = "host_fence_tests.rs"]+ mod fence_tests;diff --cc crates/openhuman-core/src/profiles/registry_tests.rsindex c9e1075621,97f78fbe29..d4aafa7be0--- a/crates/openhuman-core/src/profiles/registry_tests.rs+++ b/crates/openhuman-core/src/profiles/registry_tests.rs@@@ -1,5 -1,6 +1,9 @@@use super::*;+use crate::storage::test_support::memory_backend;++use crate::storage::{CollectionSpec, MemoryStorage, Scope, StorageBackend};++use tinystoragedrivers::Precondition;+ use crate::storage::{CollectionSpec, MemoryStorage, Scope, StorageBackend};+ use tinystoragedrivers::Precondition;fn meta(id: &str, created_at: u64) -> ProfileMeta {ProfileMeta {diff --cc crates/openhuman-core/src/skills/run_log_tests.rsindex 2b0fd1bdce,dc8bc7e5e4..234ee6a386--- a/crates/openhuman-core/src/skills/run_log_tests.rs+++ b/crates/openhuman-core/src/skills/run_log_tests.rs@@@ -104,16 -84,27 +104,25 @@@ async fn host_written_log_parses_like_llet runs = scan_runs(tmp.path(), Some("triage-inbox"), 10);assert_eq!(runs.len(), 1);assert_eq!(runs[0].run_id, "run-abcdef123456");+ assert_eq!(+ find_run_log_path(tmp.path(), "run-abcdef123456"),+ Some(path.clone())+ );assert_eq!(runs[0].status, "DONE");assert_eq!(runs[0].duration_ms, Some(42));- assert_eq!(read_terminal_outcome(&path).unwrap().status, "DONE");+ assert_eq!(+ read_terminal_outcome(tmp.path(), &path).unwrap().status,+ "DONE"+ );- // A pre-existing log in the legacy format still parses.- let legacy = runs_dir(tmp.path()).join("old_20260528T075113Z_aaaaaaaa.log");- std::fs::write(- &legacy,- "==== workflow_run: old ====\nrun_id : aaaaaaaa-1\nstarted: 2026-05-28T07:51:13+00:00 UTC\ninputs : {}\n\n--- task prompt ---\nx\n\n--- steps ---\n\n--- result ---\nstatus : FAILED\nduration: 5 ms\nfinished: 2026-05-28T07:51:14+00:00 UTC\n\nboom\n",- )- .unwrap();- let old = scan_runs(tmp.path(), Some("old"), 10);- assert_eq!(old[0].status, "FAILED");- assert_eq!(old[0].duration_ms, Some(5));+ // The stream retains the same parsed run metadata as the old log format.}++ #[test]+ fn a_compaction_is_logged_as_a_step() {+ let line = format_event(&AgentProgress::ContextCompacting).expect("a step line");+ assert!(+ line.ends_with("· summarizing earlier conversation"),+ "{line}"+ );+ }diff --cc crates/openhuman-core/src/storage/fenced_backend_tests.rsindex 358aec0dfc,20ceafbacc..506c5b3d8d--- a/crates/openhuman-core/src/storage/fenced_backend_tests.rs+++ b/crates/openhuman-core/src/storage/fenced_backend_tests.rs@@@ -227,41 -505,29 +227,44 @@@ async fn a_manually_latched_cached_fenc.is_none());}-/// The wrapper must pass a conditional append through to a driver that has it:-/// the trait default answers `Unsupported(ConditionalStreamAppend)`, which-/// refused every conversation append on the default (SQLite) backend.-async fn conditional_append_passes_through(inner: Arc<dyn StorageBackend>) {- let wrapped = wrap(inner);- let scoped = wrapped.for_scope(&Scope::local()).unwrap();- let streams = scoped.streams();+#[tokio::test]+async fn captured_profile_sweeps_cannot_follow_a_replacement_epoch() {+ let shared = shared();+ let a = Node::new("node-a", Arc::clone(&shared.backend));+ let b = Node::new("node-b", Arc::clone(&shared.backend));+ let base = a.now.load(Ordering::SeqCst);+ let (_grant, fence) = a.acquire("alice").await;+ let captured = FencedBackend::for_fence(+ Arc::clone(&shared.backend),+ Arc::clone(&a.fences),+ Arc::clone(&fence),+ );+ let scope = Scope::new("profile:alice").unwrap();+ let storage = captured.for_scope(&scope).unwrap();+ storage+ .blobs()+ .put_expiring(+ "aging",+ b"preserve".to_vec(),+ None,+ Duration::from_millis(1),+ )+ .await+ .unwrap();++ b.set_now(base + TTL.as_millis() as u64 + 1);+ b.acquire("alice").await;+ a.set_now(base + 1_000);assert_eq!(- streams- .append_batch_if_offset("log", 0, vec![json!(1)])- .await- .unwrap(),+ super::super::blob_sweep::sweep_scope(&captured, &scope).await,0);- let stale = streams- .append_batch_if_offset("log", 0, vec![json!(2)])- .await- .unwrap_err();- assert_eq!(stale.kind(), tinystoragedrivers::ErrorKind::Conflict);- assert_eq!(streams.len("log").await.unwrap(), 1);+ let raw = shared.backend.for_scope(&scope).unwrap();+ assert_eq!(+ raw.blobs().get("aging").await.unwrap().unwrap().bytes,+ b"preserve"+ );}+-#[tokio::test]-async fn fenced_memory_backend_passes_conditional_appends_through() {- conditional_append_passes_through(shared()).await;-}++#[path = "fenced_backend_upstream_tests.rs"]++mod upstream_tests;diff --cc crates/openhuman-core/src/storage/fenced_backend_upstream_tests.rsindex 0000000000,0000000000..20ceafbaccnew file mode 100644--- /dev/null+++ b/crates/openhuman-core/src/storage/fenced_backend_upstream_tests.rs@@@ -1,0 -1,0 +1,533 @@@++//! Node A loses a profile's lease to node B; A's writes through its fenced++//! view of the shared backend are refused while B's succeed.++++use super::*;++use crate::storage::fence::{fence_error, FenceError, LeaseFence, ScopeMatch};++use crate::storage::lease::{DocumentLeases, LeaseGrant, LeaseStore, LocalLeases};++use crate::storage::MemoryStorage;++use serde_json::json;++use std::sync::atomic::{AtomicU64, Ordering};++use std::time::Duration;++++#[path = "fenced_blob_stream_tests.rs"]++mod blob_stream_tests;++++const TTL: Duration = Duration::from_secs(30);++const MARGIN_MS: u64 = 5_000;++++/// One node: its clock, its lease store and fence registry, and its fenced++/// view of the shared backend.++struct Node {++ name: &'static str,++ clock: Arc<AtomicU64>,++ leases: Arc<dyn LeaseStore>,++ fences: Arc<FenceRegistry>,++ storage: FencedBackend,++}++++impl Node {++ fn new(name: &'static str, shared: &Arc<dyn StorageBackend>) -> Self {++ let clock = Arc::new(AtomicU64::new(0));++ let reading = Arc::clone(&clock);++ let fences = Arc::new(FenceRegistry::new(move || reading.load(Ordering::SeqCst)));++ Self {++ name,++ leases: Arc::new(DocumentLeases::cluster(shared.as_ref(), name, None, TTL).unwrap()),++ storage: FencedBackend::new(Arc::clone(shared), Arc::clone(&fences)),++ fences,++ clock,++ }++ }++++ fn set_clock(&self, ms: u64) {++ self.clock.store(ms, Ordering::SeqCst);++ }++++ async fn take(&self, key: &str) -> LeaseGrant {++ let grant = self++ .leases++ .acquire(key, self.clock.load(Ordering::SeqCst))++ .await++ .unwrap();++ self.fences.register(Arc::new(LeaseFence::new(++ Arc::clone(&self.leases),++ key,++ self.name,++ grant.epoch,++ grant.expires_at_ms,++ MARGIN_MS,++ vec![++ ScopeMatch::Exact(format!("profile:{key}")),++ ScopeMatch::Prefix(format!("{key}~")),++ ],++ )));++ grant++ }++++ fn scoped(&self, scope: &str) -> ScopedStorage {++ self.storage.for_scope(&Scope::new(scope).unwrap()).unwrap()++ }++++ async fn put(&self, scope: &str, id: &str) -> Result<Version> {++ self.scoped(scope)++ .documents()++ .put("notes", id, json!({"by": self.name}), Precondition::None)++ .await++ }++}++++fn shared() -> Arc<dyn StorageBackend> {++ Arc::new(MemoryStorage::new())++}++++#[tokio::test]++async fn a_node_that_lost_the_lease_cannot_write_and_the_new_holder_can() {++ let backend = shared();++ let (a, b) = (Node::new("node-a", &backend), Node::new("node-b", &backend));++++ a.take("alice").await;++ a.put("profile:alice", "n1").await.unwrap();++ a.put("alice~default", "n1").await.unwrap();++++ // Node B's clock passes A's expiry and takes the profile over. Node A's++ // clock is still early (it was paused, or runs behind): its local check++ // passes, so the stored record is what stops it.++ b.set_clock(TTL.as_millis() as u64 + 1);++ let stolen = b.take("alice").await;++ assert!(stolen.previous_unclean);++ a.set_clock(1_000);++++ let refused = a.put("profile:alice", "n2").await.unwrap_err();++ assert!(matches!(++ fence_error(&refused),++ Some(FenceError::Superseded {++ held: 1,++ stored: Some(2)++ })++ ));++ // Every write port, and every session scope of the profile, is fenced.++ let session = a.scoped("alice~default");++ assert!(session.streams().append("log", json!(1)).await.is_err());++ assert!(session.blobs().put("k", b"x".to_vec(), None).await.is_err());++ assert!(session++ .documents()++ .delete("notes", "n1", Precondition::None)++ .await++ .is_err());++ // Reads are not.++ assert!(session++ .documents()++ .get("notes", "n1")++ .await++ .unwrap()++ .is_some());++ // Other profiles' scopes are untouched.++ a.put("profile:bob", "n1").await.unwrap();++++ // The new holder writes, and its write is the one that stands.++ b.put("profile:alice", "n2").await.unwrap();++ let stored = backend++ .for_scope(&Scope::new("profile:alice").unwrap())++ .unwrap()++ .documents()++ .get("notes", "n2")++ .await++ .unwrap()++ .unwrap();++ assert_eq!(stored.doc["by"], "node-b");++}++++#[tokio::test]++async fn a_paused_node_refuses_its_own_writes_once_its_grant_runs_out() {++ let backend = shared();++ let a = Node::new("node-a", &backend);++ a.take("alice").await;++++ // Nobody took over yet, but node A's renewals stopped landing: inside++ // the skew margin it already refuses, with no I/O.++ a.set_clock(TTL.as_millis() as u64 - MARGIN_MS);++ let refused = a.put("profile:alice", "n").await.unwrap_err();++ assert_eq!(++ fence_error(&refused),++ Some(&FenceError::Expired { epoch: 1 })++ );++}++++#[tokio::test]++async fn a_renewed_grant_keeps_admitting_writes() {++ let backend = shared();++ let a = Node::new("node-a", &backend);++ let grant = a.take("alice").await;++ a.set_clock(20_000);++ let renewed = a.leases.renew(&grant, 20_000).await.unwrap();++ a.fences++ .lookup("profile:alice")++ .unwrap()++ .renewed(renewed.expires_at_ms);++ a.set_clock(40_000);++ a.put("profile:alice", "n").await.unwrap();++}++++/// File leases (`LocalLeases`, hosts without a backend) cannot be lost while++/// the process lives, so a fence over one admits writes until the holder++/// releases it.++#[tokio::test]++async fn a_fence_over_file_leases_admits_until_release() {++ let tmp = tempfile::tempdir().unwrap();++ let leases: Arc<dyn LeaseStore> = Arc::new(LocalLeases::new(tmp.path(), "node-a"));++ let grant = leases.acquire("alice", 0).await.unwrap();++ assert_eq!(grant.expires_at_ms, u64::MAX, "file leases never expire");++ let fence = LeaseFence::new(++ Arc::clone(&leases),++ "alice",++ "node-a",++ grant.epoch,++ grant.expires_at_ms,++ MARGIN_MS,++ vec![ScopeMatch::Exact("profile:alice".into())],++ );++ assert_eq!(fence.check(u64::MAX / 2).await, Ok(()));++ leases.release(grant).await.unwrap();++ assert!(matches!(++ fence.check(1).await,++ Err(FenceError::Superseded { .. })++ ));++}++++/// Node A's lease store, with the pause the host check cannot see: its next++/// record read returns what it read and *then* lets node B take the key++/// over, as if A were paused between its check and its write.++struct PausedAfterCheck {++ inner: Arc<dyn LeaseStore>,++ thief: Arc<dyn LeaseStore>,++ armed: std::sync::atomic::AtomicBool,++}++++#[async_trait]++impl LeaseStore for PausedAfterCheck {++ async fn acquire(++ &self,++ key: &str,++ now_ms: u64,++ ) -> std::result::Result<LeaseGrant, crate::storage::lease::LeaseError> {++ self.inner.acquire(key, now_ms).await++ }++++ async fn renew(++ &self,++ grant: &LeaseGrant,++ now_ms: u64,++ ) -> std::result::Result<LeaseGrant, crate::storage::lease::LeaseError> {++ self.inner.renew(grant, now_ms).await++ }++++ async fn release(++ &self,++ grant: LeaseGrant,++ ) -> std::result::Result<(), crate::storage::lease::LeaseError> {++ self.inner.release(grant).await++ }++++ async fn holder(++ &self,++ key: &str,++ ) -> std::result::Result<++ Option<crate::storage::lease::LeaseRecord>,++ crate::storage::lease::LeaseError,++ > {++ let record = self.inner.holder(key).await?;++ if self.armed.swap(false, Ordering::SeqCst) {++ let stolen = self.thief.acquire(key, TTL.as_millis() as u64 + 1).await?;++ assert_eq!(stolen.epoch, 2);++ }++ Ok(record)++ }++++ async fn holder_readonly(++ &self,++ key: &str,++ ) -> std::result::Result<++ Option<crate::storage::lease::LeaseRecord>,++ crate::storage::lease::LeaseError,++ > {++ self.inner.holder_readonly(key).await++ }++++ fn driver_fence(&self, key: &str, node: &str, epoch: u64) -> Option<tinystoragedrivers::Fence> {++ self.inner.driver_fence(key, node, epoch)++ }++}++++/// Node A holds `alice` on `shared`; returns A's fenced view, its fence,++/// and the switch that makes its next check go stale.++async fn paused_holder(++ shared: &Arc<dyn StorageBackend>,++) -> (FencedBackend, Arc<LeaseFence>, Arc<PausedAfterCheck>) {++ let leases = Arc::new(PausedAfterCheck {++ inner: Arc::new(DocumentLeases::cluster(shared.as_ref(), "node-a", None, TTL).unwrap()),++ thief: Arc::new(DocumentLeases::cluster(shared.as_ref(), "node-b", None, TTL).unwrap()),++ armed: std::sync::atomic::AtomicBool::new(false),++ });++ let grant = leases.acquire("alice", 0).await.unwrap();++ let fences = Arc::new(FenceRegistry::new(|| 1_000));++ let fence = Arc::new(LeaseFence::new(++ Arc::clone(&leases) as Arc<dyn LeaseStore>,++ "alice",++ "node-a",++ grant.epoch,++ grant.expires_at_ms,++ MARGIN_MS,++ vec![ScopeMatch::Exact("profile:alice".into())],++ ));++ fences.register(Arc::clone(&fence));++ (++ FencedBackend::new(Arc::clone(shared), fences),++ fence,++ leases,++ )++}++++/// The race the host check alone leaves open: A's check passes, A pauses,++/// B takes over, A's write lands. The driver re-reads the lease record in++/// the write's own atomic step and refuses it.++async fn driver_refuses_the_write_the_host_check_admitted(shared: Arc<dyn StorageBackend>) {++ assert!(shared.capabilities().contains(Capability::Fencing));++ let (a, fence, leases) = paused_holder(&shared).await;++ let scoped = a.for_scope(&Scope::new("profile:alice").unwrap()).unwrap();++ scoped++ .documents()++ .put("notes", "n1", json!({"v": 1}), Precondition::None)++ .await++ .unwrap();++++ leases.armed.store(true, Ordering::SeqCst);++ let refused = scoped++ .documents()++ .put("notes", "n1", json!({"v": 2}), Precondition::None)++ .await++ .unwrap_err();++ assert!(++ matches!(++ fence_error(&refused),++ Some(FenceError::Superseded {++ held: 1,++ stored: Some(2)++ })++ ),++ "{refused:?}"++ );++ assert!(fence.is_fenced(), "a driver refusal latches the fence");++ let stored = shared++ .for_scope(&Scope::new("profile:alice").unwrap())++ .unwrap()++ .documents()++ .get("notes", "n1")++ .await++ .unwrap()++ .unwrap();++ assert_eq!(stored.doc["v"], 1, "the late write did not land");++ // Latched: every later write is refused before it reaches the driver.++ assert!(scoped.streams().append("log", json!(1)).await.is_err());++}++++#[tokio::test]++async fn memory_driver_refuses_a_write_after_a_takeover_the_check_missed() {++ driver_refuses_the_write_the_host_check_admitted(shared()).await;++}++++/// Streams and blobs go through the driver fence too.++#[tokio::test]++async fn stream_and_blob_writes_are_driver_fenced() {++ let backend = shared();++ let (a, _fence, leases) = paused_holder(&backend).await;++ let scoped = a.for_scope(&Scope::new("profile:alice").unwrap()).unwrap();++ leases.armed.store(true, Ordering::SeqCst);++ assert!(scoped.streams().append("log", json!(1)).await.is_err());++ let raw = backend++ .for_scope(&Scope::new("profile:alice").unwrap())++ .unwrap();++ assert_eq!(raw.streams().len("log").await.unwrap(), 0);++++ let (b, _fence, leases) = paused_holder(&shared()).await;++ let scoped = b.for_scope(&Scope::new("profile:alice").unwrap()).unwrap();++ leases.armed.store(true, Ordering::SeqCst);++ assert!(scoped.blobs().put("k", b"x".to_vec(), None).await.is_err());++}++++/// A driver without fencing gets the host check only, and writes through.++#[tokio::test]++async fn a_driver_without_fencing_falls_back_to_the_host_check() {++ let backend: Arc<dyn StorageBackend> = Arc::new(NoFencing(MemoryStorage::new()));++ let (a, _fence, _leases) = paused_holder(&backend).await;++ let scoped = a.for_scope(&Scope::new("profile:alice").unwrap()).unwrap();++ scoped++ .documents()++ .put("notes", "n", json!({}), Precondition::None)++ .await++ .unwrap();++}++++/// The memory driver, reporting no fencing (MongoDB without transactions).++#[derive(Debug)]++struct NoFencing(MemoryStorage);++++impl StorageBackend for NoFencing {++ fn driver(&self) -> &'static str {++ "no-fencing"++ }++ fn capabilities(&self) -> Capabilities {++ self.0.capabilities().without(Capability::Fencing)++ }++ fn for_scope(&self, scope: &Scope) -> Result<ScopedStorage> {++ self.0.for_scope(scope)++ }++}++++/// The run ledger claims team tasks with `atomic_batch_checked`. The fenced++/// view must pass it through to a driver that supports it (the default trait++/// method answers `Unsupported`), and still refuse it for a stale lease.++#[tokio::test]++async fn a_checked_batch_reaches_the_driver_through_the_fenced_view() {++ use tinystoragedrivers::{ExpectedDocument, ReadCheck};++++ let shared: Arc<dyn StorageBackend> = Arc::new(MemoryStorage::new());++ let a = Node::new("a", &shared);++ let docs = Arc::clone(a.scoped("plain").documents());++ docs.ensure_collection(&CollectionSpec::new("things"))++ .await++ .unwrap();++++ let applied = docs++ .atomic_batch_checked(++ vec![ReadCheck {++ collection: "things".into(),++ id: "dependency".into(),++ expected: ExpectedDocument::Absent,++ }],++ vec![WriteOp::Put {++ collection: "things".into(),++ id: "claimed".into(),++ doc: json!({ "by": "a" }),++ precondition: Precondition::Absent,++ }],++ )++ .await++ .expect("the checked batch is not answered Unsupported");++ assert_eq!(applied.len(), 1);++ assert!(docs.get("things", "claimed").await.unwrap().is_some());++++ // The dependency is validated: a check that no longer holds writes nothing.++ docs.put("things", "dependency", json!({}), Precondition::Absent)++ .await++ .unwrap();++ let conflict = docs++ .atomic_batch_checked(++ vec![ReadCheck {++ collection: "things".into(),++ id: "dependency".into(),++ expected: ExpectedDocument::Absent,++ }],++ vec![WriteOp::Put {++ collection: "things".into(),++ id: "second".into(),++ doc: json!({}),++ precondition: Precondition::Absent,++ }],++ )++ .await++ .unwrap_err();++ assert_eq!(conflict.kind(), ErrorKind::Conflict);++ assert!(docs.get("things", "second").await.unwrap().is_none());++}++++/// The fenced view must not hide what the driver can do: an expiring blob++/// written through it is stored, reads back, and the view advertises the++/// capability (before, `FencedBlobs` reported none and `put_expiring` fell to++/// the trait default, `Unsupported`, on every driver).++#[tokio::test]++async fn fenced_blobs_forward_expiry_and_capabilities() {++ let backend = shared();++ let node = Node::new("node-a", &backend);++ node.take("alice").await;++ let scoped = node.scoped("profile:alice");++++ let blobs = scoped.blobs();++ assert!(blobs.capabilities().contains(Capability::BlobTtl));++ assert!(!blobs.capabilities().contains(Capability::PresignedUrls));++ assert_eq!(++ blobs.max_key_len(),++ backend++ .for_scope(&Scope::new("profile:alice").unwrap())++ .unwrap()++ .blobs()++ .max_key_len()++ );++++ blobs++ .put_expiring("live", b"x".to_vec(), None, Duration::from_secs(3600))++ .await++ .unwrap();++ assert_eq!(blobs.get("live").await.unwrap().unwrap().bytes, b"x");++ assert!(blobs.get_stream("live").await.unwrap().is_some());++++ // A zero lifetime is already expired: written, never visible.++ blobs++ .put_expiring("gone", b"x".to_vec(), None, Duration::ZERO)++ .await++ .unwrap();++ assert!(blobs.get("gone").await.unwrap().is_none());++ assert!(blobs.get_stream("gone").await.unwrap().is_none());++}++++/// An expiring write is a write: a node that lost the lease cannot make one.++#[tokio::test]++async fn expiring_blob_writes_are_fenced() {++ let backend = shared();++ let (a, b) = (Node::new("node-a", &backend), Node::new("node-b", &backend));++ a.take("alice").await;++ b.set_clock(TTL.as_millis() as u64 + 1);++ b.take("alice").await;++ a.set_clock(1_000);++++ let session = a.scoped("alice~default");++ assert!(session++ .blobs()++ .put_expiring("k", b"x".to_vec(), None, Duration::from_secs(60))++ .await++ .is_err());++ assert!(backend++ .for_scope(&Scope::new("alice~default").unwrap())++ .unwrap()++ .blobs()++ .get("k")++ .await++ .unwrap()++ .is_none());++}++++/// The wrapper must pass a conditional append through to a driver that has it:++/// the trait default answers `Unsupported(ConditionalStreamAppend)`, which++/// refused every conversation append on the default (SQLite) backend.++async fn conditional_append_passes_through(inner: Arc<dyn StorageBackend>) {++ let wrapped = wrap(inner);++ let scoped = wrapped.for_scope(&Scope::local()).unwrap();++ let streams = scoped.streams();++ assert_eq!(++ streams++ .append_batch_if_offset("log", 0, vec![json!(1)])++ .await++ .unwrap(),++ 0++ );++ let stale = streams++ .append_batch_if_offset("log", 0, vec![json!(2)])++ .await++ .unwrap_err();++ assert_eq!(stale.kind(), tinystoragedrivers::ErrorKind::Conflict);++ assert_eq!(streams.len("log").await.unwrap(), 1);++}++++#[tokio::test]++async fn fenced_memory_backend_passes_conditional_appends_through() {++ conditional_append_passes_through(shared()).await;++}diff --cc crates/openhuman-core/src/storage/lease.rsindex 999fa2db8f,fc2f04655b..e156454698--- a/crates/openhuman-core/src/storage/lease.rs+++ b/crates/openhuman-core/src/storage/lease.rs@@@ -170,7 -171,16 +170,16 @@@ pub trait LeaseStore: Send + Sync/// [`LeaseError::Storage`].async fn holder(&self, key: &str) -> Result<Option<LeaseRecord>, LeaseError>;+ /// Reads the stored holder without declaring schema or creating local+ /// lease files. Implementations that cannot guarantee a read-only lookup+ /// fail closed.+ async fn holder_readonly(&self, _key: &str) -> Result<Option<LeaseRecord>, LeaseError> {+ Err(LeaseError::Storage(StorageError::backend(+ "lease store does not support read-only holder inspection",+ )))+ }+- /// The fence a storage driver enforces for `node`'s grant on `key` at+ /// The condition a storage driver evaluates for `node`'s grant on `key` at/// `epoch`, when the record lives in the storage ports at all: the/// record must still name `node` at `epoch`, unreleased. The driver then/// checks a write against the record in the same atomic stepdiff --cc crates/openhuman-core/src/storage/lease_documents.rsindex 173d69abf9,1b8f5bb533..a221a76009--- a/crates/openhuman-core/src/storage/lease_documents.rs+++ b/crates/openhuman-core/src/storage/lease_documents.rs@@@ -7,37 -20,21 +7,38 @@@ use std::sync::{Arc, Mutex}use std::time::Duration;use async_trait::async_trait;-use tinystoragedrivers::primitives::{self, Acquire, Acquisition};-use tinystoragedrivers::{- CollectionSpec, DocumentStore, ErrorKind, Fence, Filter, Key, Leases, Scope, StorageBackend,- Version,+use serde::{Deserialize, Serialize};- use tinystoragedrivers::{CollectionSpec, Precondition, Scope, StorageBackend};++use tinystoragedrivers::{CollectionSpec, ErrorKind, Key, Precondition, Scope, StorageBackend};+use tinystoragedrivers_api::DocumentStore;+use tinystoragedrivers_types::{- Filter, Key, Scope as DriverScope, Version, Versioned, WriteCondition, WriteOptions,++ Filter, Scope as DriverScope, Version, Versioned, WriteCondition, WriteOptions,++};};+use super::StorageError;use super::lease::{- validate_key, LeaseError, LeaseGrant, LeaseRecord, LeaseStore, CLUSTER_SCOPE, LEASE_COLLECTION,+ CLUSTER_SCOPE, LEASE_COLLECTION, LeaseError, LeaseGrant, LeaseRecord, LeaseStore, validate_key,};-use super::StorageError;-/// The `tsd.leases` owner of the host's process-placement leases.+/// The owner namespace of the host's process-placement lease documents.pub const LEASE_OWNER: &str = "profiles";-/// Leases kept in `tsd.leases`. See the module docs.+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+struct LeaseBody {+ holder: String,+ epoch: u64,+ expires_ms: i64,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ endpoint: Option<String>,+ #[serde(default, skip_serializing_if = "is_false")]+ released: bool,+}++fn is_false(value: &bool) -> bool {+ !*value+}++/// Host leases kept in [`LEASE_COLLECTION`]. See the module docs.pub struct DocumentLeases {docs: Arc<dyn DocumentStore>,/// The scope `docs` is bound to, when known ([`Self::cluster`]); a@@@ -398,14 -338,49 +399,35 @@@ impl LeaseStore for DocumentLeasesasync fn holder(&self, key: &str) -> Result<Option<LeaseRecord>, LeaseError> {validate_key(key)?;self.declare().await?;- Ok(self- .leases_at(0)- .inspect(LEASE_OWNER, key)- .await?- .map(record_of))+ Ok(self.read(key).await?.map(|record| record_of(record.doc)))}+ async fn holder_readonly(&self, key: &str) -> Result<Option<LeaseRecord>, LeaseError> {+ validate_key(key)?;- match self- .docs- .validate_collection_spec(&CollectionSpec::new(LEASE_COLLECTION))- .await- {++ match self.docs.validate_collection_spec(&CollectionSpec::new(LEASE_COLLECTION)).await {+ Ok(()) => {}+ Err(error) if error.kind() == ErrorKind::NotFound => {- match self- .docs- .validate_collection_spec(&CollectionSpec::new("leases"))- .await- {- Ok(()) => {- return Err(LeaseError::Storage(StorageError::backend(- "legacy profile leases require explicit storage migration",- )));- }++ match self.docs.validate_collection_spec(&CollectionSpec::new("leases")).await {++ Ok(()) => return Err(LeaseError::Storage(StorageError::backend(++ "legacy profile leases require explicit storage migration",++ ))),+ Err(error) if error.kind() == ErrorKind::NotFound => return Ok(None),- Err(error) => return Err(LeaseError::Storage(error)),++ Err(error) => return Err(LeaseError::Storage(error.into())),+ }+ }- Err(error) => return Err(LeaseError::Storage(error)),++ Err(error) => return Err(LeaseError::Storage(error.into())),+ }- self.leases_at(0)- .inspect(LEASE_OWNER, key)++ self.read(key)+ .await- .map(|record| record.map(record_of))++ .map(|record| record.map(|record| record_of(record.doc)))+ .map_err(LeaseError::from)+ }+- fn driver_fence(&self, key: &str, node: &str, epoch: u64) -> Option<Fence> {+ fn write_condition(&self, key: &str, node: &str, epoch: u64) -> Option<WriteCondition> {let scope = self.scope.clone()?;- let id = Key::of([LEASE_OWNER, key]).ok()?;- Some(Fence::new(+ let id = Key::new(format!("{LEASE_OWNER}/{key}")).ok()?;+ let scope = DriverScope::new(scope.as_str()).ok()?;+ WriteCondition::new(scope,LEASE_COLLECTION,id.as_str().to_string(),diff --cc crates/openhuman-core/src/storage/lease_documents_tests.rsindex 1e2db7ffb8,694f147bea..e5452444a0--- a/crates/openhuman-core/src/storage/lease_documents_tests.rs+++ b/crates/openhuman-core/src/storage/lease_documents_tests.rs@@@ -4,24 -2,43 +4,52 @@@ use super::*use std::time::Duration;+use crate::storage::test_support::SqliteBackend;++use crate::storage::{CollectionSpec, MemoryStorage, Scope};+use tinystoragedrivers_types::Precondition;+ use crate::storage::MemoryStorage;+ use tinystoragedrivers::{CollectionSpec, Precondition, Scope};const TTL: Duration = Duration::from_millis(1_000);-fn node(storage: &MemoryStorage, id: &str) -> DocumentLeases {- DocumentLeases::cluster(storage, id, Some(format!("http://{id}")), TTL).unwrap()+fn node(storage: &SqliteBackend, id: &str) -> DocumentLeases {+ DocumentLeases::cluster(+ storage.backend.as_ref(),+ id,+ Some(format!("http://{id}")),+ TTL,+ )+ .unwrap()}+ #[tokio::test]+ async fn doctor_holder_inspection_does_not_declare_the_lease_collection() {+ let storage = MemoryStorage::new();- let leases = node(&storage, "a");++ let leases = DocumentLeases::cluster(&storage, "a", None, TTL).unwrap();+ let documents = storage+ .for_scope(&Scope::new(CLUSTER_SCOPE).unwrap())+ .unwrap();+ let spec = CollectionSpec::new(LEASE_COLLECTION);++ assert!(documents+ .documents()+ .validate_collection_spec(&spec)+ .await+ .is_err());+ assert!(leases.holder_readonly("alice").await.unwrap().is_none());+ assert!(+ documents+ .documents()+ .validate_collection_spec(&spec)+ .await+ .is_err(),+ "a doctor-style holder inspection must not create storage schema"+ );+ }+#[tokio::test]async fn acquire_contend_expire_and_take_over() {- let storage = MemoryStorage::new();+ let storage = crate::storage::test_support::sqlite_backend().unwrap();let (a, b) = (node(&storage, "a"), node(&storage, "b"));let first = a.acquire("user-1", 0).await.unwrap();diff --cc crates/openhuman-core/src/storage/mod.rsindex 6ab4f7dbee,ea71c53a5d..4b186e7905--- a/crates/openhuman-core/src/storage/mod.rs+++ b/crates/openhuman-core/src/storage/mod.rs@@@ -44,8 -44,8 +45,9 @@@ pub mod localpub mod rebind;pub mod schema;pub mod schema_support;+ pub(crate) use inspection::probe_directory_writable;pub mod scope;+#[cfg(feature = "legacy-import")]pub mod scope_move;pub mod secrets;pub mod sessions;diff --cc crates/openhuman-embed/src/lib.rsindex f5d42ff4fd,58597f5684..ef3962b832--- a/crates/openhuman-embed/src/lib.rs+++ b/crates/openhuman-embed/src/lib.rs@@@ -240,15 -248,12 +248,15 @@@ pub mod session_storepub use tinyagents_harness::events::{AgentEvent, HarnessRunStatus};pub use tinyagents_harness::ids::ExecutionStatus;pub use tinyagents_harness::observability::AgentObservation;+ pub use tinyagents_harness_tools::todos::TodoList;pub use tinyagents_session::port::{AgentStores, SessionStoreProvider};+ pub use tinyagents_session::port::{AppendStore, Store, TurnStates};+ /// In-memory provider and contract suites for providers implemented by embedders.+ #[cfg(feature = "testkit")]pub use tinyagents_session::port::{- AppendStore, InMemorySessionStores, InMemoryTranscriptLocator, InMemoryTurnStates, Store,- TurnStates,+ InMemorySessionStores, InMemoryTranscriptLocator, InMemoryTurnStates,};+ #[cfg(feature = "testkit")]pub use tinyagents_session::testkit::conformance::{session_store_conformance, session_store_isolation_conformance,};@@@ -264,11 -269,11 +272,13 @@@}pub use complete::{ChatMessage, Completer, CompletionObserver, CompletionRequest, CompletionResponse,- CompletionTrace, CompletionUsage,+ CompletionTrace, CompletionUsage, PhysicalDispatchMetadata, PhysicalDispatchObserver,+ PhysicalDispatchOutcome, PhysicalDispatchStatus, PhysicalDispatchTerminal,+ PhysicalDispatchUsage,};-pub use session_store::{InMemorySessionStores, SessionStoreProvider};+#[cfg(feature = "testkit")]+pub use session_store::InMemorySessionStores;+pub use session_store::SessionStoreProvider;pub use turn::{absolute, Route, Turn, TurnOutcome, TurnRequest};pub use turn_cancellation::TurnCancellation;pub use turn_steering::{SteerRefused, TurnSteering};diff --cc crates/openhuman-embed/src/runtime/build.rsindex fdfef09ee5,c9f4db4373..cd4ad910d5--- a/crates/openhuman-embed/src/runtime/build.rs+++ b/crates/openhuman-embed/src/runtime/build.rs@@@ -162,35 -194,40 +194,49 @@@ impl RuntimeBuilderlet mut storage_info = super::StorageInfo::describe(self.seams.storage.as_ref(),config.as_ref().unwrap_or(&Config::default()),+ self.seams.storage_driver.as_deref(),);let mut host_seams = std::mem::take(&mut self.seams);- if host_seams.storage.is_none() {- if let Some(config) = &config {- if let Some(url) = openhuman_core::storage::explicit_url(config) {- host_seams.storage = Some(super::StorageSource::Url(url));+ if !inspection {+ if host_seams.storage.is_none() {+ if let Some(config) = &config {+ if let Some(url) = openhuman_core::storage::explicit_url(config) {+ host_seams.storage = Some(super::StorageSource::Url(url));+ }}}+ // A stateless workspace keeps nothing durable on disk: with no host+ // backend, the documents the core keeps beside the session store (run+ // status, cron, flows) go to memory instead of the workspace-default+ // SQLite under `<workspace>/storage`. Installed process-wide like any+ // storage seam, and removed with the runtime.+ if host_seams.storage.is_none() && matches!(self.workspace, Workspace::Stateless) {+ host_seams.storage = Some(super::StorageSource::Url("memory".into()));+ }+ validate_storage_feature(host_seams.storage.as_ref())?;+ host_seams+ .open_storage()+ .await+ .map_err(RuntimeError::Invalid)?;}- // A stateless workspace keeps nothing durable on disk: with no host- // backend, the documents the core keeps beside the session store (run- // status, cron, flows) go to memory instead of the workspace-default- // SQLite under `<workspace>/storage`. Installed process-wide like any- // storage seam, and removed with the runtime.- if host_seams.storage.is_none() && matches!(self.workspace, Workspace::Stateless) {++ if !inspection++ && host_seams.storage.is_none()++ && matches!(self.workspace, Workspace::Stateless)++ {+ host_seams.storage = Some(super::StorageSource::Url("memory".into()));+ storage_info = super::StorageInfo::url("backend", "memory");+ }- validate_storage_feature(host_seams.storage.as_ref())?;- host_seams- .open_storage()- .await- .map_err(RuntimeError::Invalid)?;- let storage_backend = match &host_seams.storage {- Some(super::StorageSource::Backend(backend)) => Some(backend.clone()),- _ => None,+ let storage_backend = if inspection {+ None+ } else {+ match &host_seams.storage {+ Some(super::StorageSource::Backend(backend)) => Some(backend.clone()),+ _ => None,+ }};- if self.session_store.is_none() {++ };+ let core_extensions = host_seams.core_extensions.clone();+ if !inspection && self.session_store.is_none() {if let Some(backend) = &storage_backend {let stores = openhuman_core::storage::sessions::TenantSessionStores::new(backend.clone(),@@@ -279,11 -330,18 +339,15 @@@RuntimeError::Build(error)})?;let core = Core::from_runtime(Arc::new(runtime));- let storage_backend = storage_backend.or_else(openhuman_core::storage::installed);+ let storage_backend = if inspection {+ None+ } else {+ storage_backend.or_else(openhuman_core::storage::installed)+ };if !storage_info.configured {if let Some(backend) = &storage_backend {- storage_info = super::StorageInfo {- source: "backend".into(),- driver: Some(backend.driver().into()),- configured: true,- };+ let installed_url = openhuman_core::storage::installed_url();+ storage_info = super::StorageInfo::backend(installed_url.as_deref());}}