Skip to content

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

fix(rpc): register config hooks before boot session store

Steven Enamakel6049001beaae
diff --git a/crates/openhuman-rpc/src/host.rs b/crates/openhuman-rpc/src/host.rs
index 18c6f347a4..f442a6c0ab 100644
--- a/crates/openhuman-rpc/src/host.rs
+++ b/crates/openhuman-rpc/src/host.rs
@@ -81,8 +81,7 @@ fn embed_info(args: &[String]) -> anyhow::Result<Option<crate::embed::RuntimeInf
/// the dispatched command failed.
#[cfg(feature = "server")]
pub fn cli(args: &[String]) -> anyhow::Result<()> {
- // Before any config read (`provider_for_host` loads one), so load-time
- // migrations can recognise managed endpoints.
+ // Config reads below (and in the dispatcher) need the enricher.
openhuman_tinyhumans::register_hooks();
// Introspection belongs above the core: never introduce a core -> embed dependency.
if let Some(info) = embed_info(args)? {
@@ -114,7 +113,7 @@ pub fn cli(args: &[String]) -> anyhow::Result<()> {
// resolved storage URL, opened on the core's storage runtime so the
// backend outlives this call.
let provider =
- crate::core_host::storage::block_on_anyhow(crate::session_store::provider_for_host())?;
+ crate::core_host::storage::block_on_anyhow(session_store_for_boot())?;
log::debug!("[rpc:host] cli: storage-backed session store installed");
builder = builder.session_store(provider);
}
@@ -319,7 +318,7 @@ pub async fn tui() -> anyhow::Result<openhuman_tinyhumans::embed::Runtime> {
openhuman_tinyhumans::register_hooks();
secret_storage::install();
log::debug!("[rpc:host] tui: building connected runtime");
- let session_store = crate::session_store::provider_for_host().await?;
+ let session_store = session_store_for_boot().await?;
let runtime = tui_builder()
.session_store(session_store)
.build()
@@ -332,6 +331,18 @@ pub async fn tui() -> anyhow::Result<openhuman_tinyhumans::embed::Runtime> {
Ok(runtime)
}
+/// The storage-backed session store a host opens *before* its runtime is
+/// connected. Opening it loads the config (to resolve `[storage] url`), so the
+/// TinyHumans config hooks go in first: without the enricher the load-time
+/// migrations cannot tell a managed endpoint from a custom one and would
+/// rewrite a legacy managed config.
+#[cfg(feature = "session-store")]
+async fn session_store_for_boot(
+) -> anyhow::Result<std::sync::Arc<dyn openhuman_tinyhumans::embed::SessionStoreProvider>> {
+ openhuman_tinyhumans::register_hooks();
+ crate::session_store::provider_for_host().await
+}
+
#[cfg(test)]
#[path = "host_tests.rs"]
mod tests;
diff --git a/crates/openhuman-rpc/src/host_tests.rs b/crates/openhuman-rpc/src/host_tests.rs
index 50349ce859..6fe9cb90f6 100644
--- a/crates/openhuman-rpc/src/host_tests.rs
+++ b/crates/openhuman-rpc/src/host_tests.rs
@@ -175,3 +175,52 @@ fn embed_info_is_versioned_and_rejects_unknown_flags() {
assert!(embed_info(&["embed".into(), "info".into(), "--secret".into()]).is_err());
assert!(embed_info(&["serve".into()]).unwrap().is_none());
}
+
+/// A legacy config whose `api_url` is the managed chat-completions URL must
+/// load as managed (URL derived, not moved to `inference_url`) when the host
+/// opens its session store before connecting. The load-time migrations know
+/// the managed hosts only through the TinyHumans config enricher, which the
+/// boot path must register ahead of the first config read.
+#[cfg(feature = "session-store")]
+#[tokio::test]
+async fn boot_session_store_keeps_a_legacy_managed_config_managed() {
+ use crate::core_host::config::enrichers_test_support as _;
+ let _turn = crate::STORAGE_SLOT_TEST_LOCK.lock().await;
+ let tmp = tempfile::tempdir().unwrap();
+ std::fs::write(
+ tmp.path().join("config.toml"),
+ "api_url = \"https://api.tinyhumans.ai/openai/v1/chat/completions\"\n",
+ )
+ .unwrap();
+ let _env = crate::server::testing::EnvVarGuard::set_many(vec![
+ ("OPENHUMAN_WORKSPACE", tmp.path().into()),
+ ("OPENHUMAN_STORAGE_URL", "".into()),
+ ]);
+ openhuman_tinyhumans::embed::__host::config_enrichers::unregister_enricher(
+ "tinyhumans::endpoints",
+ );
+
+ let previous = crate::core_host::agent::session_store::installed();
+ let previous_backend = crate::core_host::storage::installed();
+ let result = session_store_for_boot().await;
+ let config = crate::core_host::config::ops::load_config_in(
+ &crate::core_host::core::runtime::DispatchCtx::host_default(),
+ )
+ .await;
+ // Put the process-wide slots back before asserting.
+ match previous_backend {
+ Some(backend) => {
+ crate::core_host::storage::install(backend);
+ }
+ None => {
+ crate::core_host::storage::clear();
+ }
+ }
+ drop(previous);
+ result.expect("the boot session store opens");
+ let config = config.expect("the legacy config loads");
+ assert!(
+ config.inference_url.is_none(),
+ "a managed api_url must not be moved to a custom inference_url"
+ );
+}