Skip to content

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

refactor(core): expose legacy controller accessor and tidy formatting

Steven Enamakel5eefab3ce91a
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index 9aa0c5cd58..a5aea073b4 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -12,8 +12,8 @@ use std::{
use serde_json::{Map, Value};
-use crate::core::runtime::DispatchCtx;
use crate::core::ControllerSchema;
+use crate::core::runtime::DispatchCtx;
/// A pinned, boxed future returned by a controller handler.
pub type ControllerFuture = Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'static>>;
@@ -69,11 +69,16 @@ impl BoundRegisteredController {
parse: fn(Map<String, Value>) -> Result<P, String>,
run: fn(DispatchCtx, P) -> ControllerFuture,
) -> Self {
- let decode = Arc::new(move |params| parse(params).map(|_| ())) as Arc<dyn Fn(_) -> _ + Send + Sync>;
+ let decode =
+ Arc::new(move |params| parse(params).map(|_| ())) as Arc<dyn Fn(_) -> _ + Send + Sync>;
let invoke = Arc::new(move |ctx, params| {
Box::pin(async move { run(ctx, parse(params)?).await }) as ControllerFuture
}) as Arc<dyn Fn(_, _) -> _ + Send + Sync>;
- Self { schema, invoke, decode }
+ Self {
+ schema,
+ invoke,
+ decode,
+ }
}
/// Preserve a manual pre-parse gate while sharing the parser with validation.
@@ -83,14 +88,19 @@ impl BoundRegisteredController {
parse: fn(Map<String, Value>) -> Result<P, String>,
run: fn(DispatchCtx, G, P) -> ControllerFuture,
) -> Self {
- let decode = Arc::new(move |params| parse(params).map(|_| ())) as Arc<dyn Fn(_) -> _ + Send + Sync>;
+ let decode =
+ Arc::new(move |params| parse(params).map(|_| ())) as Arc<dyn Fn(_) -> _ + Send + Sync>;
let invoke = Arc::new(move |ctx, params| {
Box::pin(async move {
let gated = gate(ctx.clone()).await?;
run(ctx, gated, parse(params)?).await
}) as ControllerFuture
}) as Arc<dyn Fn(_, _) -> _ + Send + Sync>;
- Self { schema, invoke, decode }
+ Self {
+ schema,
+ invoke,
+ decode,
+ }
}
/// Decode params through the parser used by runtime invocation.
@@ -118,15 +128,33 @@ enum EntryHandler {
impl ControllerEntry {
pub(crate) fn legacy(controller: RegisteredController) -> Self {
- Self { schema: controller.schema, handler: EntryHandler::Legacy(controller.handler) }
+ Self {
+ schema: controller.schema,
+ handler: EntryHandler::Legacy(controller.handler),
+ }
}
pub(crate) fn bound(controller: BoundRegisteredController) -> Self {
- Self { schema: controller.schema.clone(), handler: EntryHandler::Bound(controller) }
+ Self {
+ schema: controller.schema.clone(),
+ handler: EntryHandler::Bound(controller),
+ }
}
/// Returns the canonical RPC method name for this controller.
- pub fn rpc_method_name(&self) -> String { rpc_method_name(&self.schema) }
+ pub fn rpc_method_name(&self) -> String {
+ rpc_method_name(&self.schema)
+ }
+
+ fn legacy_controller(&self) -> Option<RegisteredController> {
+ match &self.handler {
+ EntryHandler::Legacy(handler) => Some(RegisteredController {
+ schema: self.schema.clone(),
+ handler: *handler,
+ }),
+ EntryHandler::Bound(_) => None,
+ }
+ }
fn invoke(&self, ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
match &self.handler {
@@ -158,17 +186,20 @@ struct GroupedController {
/// This is the single seam that attaches a [`DomainGroup`] to every domain's
/// controllers without the domain modules knowing about groups.
fn push(dst: &mut Vec<GroupedController>, group: DomainGroup, items: Vec<RegisteredController>) {
+ dst.extend(items.into_iter().map(|controller| GroupedController {
+ group,
+ controller: ControllerEntry::legacy(controller),
+ }));
+}
+
+fn push_entries(dst: &mut Vec<GroupedController>, group: DomainGroup, items: Vec<ControllerEntry>) {
dst.extend(
items
.into_iter()
- .map(|controller| GroupedController { group, controller: ControllerEntry::legacy(controller) }),
+ .map(|controller| GroupedController { group, controller }),
);
}
-fn push_entries(dst: &mut Vec<GroupedController>, group: DomainGroup, items: Vec<ControllerEntry>) {
- dst.extend(items.into_iter().map(|controller| GroupedController { group, controller }));
-}
-
/// The [`DomainSet`](crate::core::runtime::DomainSet) of the ambient dispatch
/// context, if any. `None` before any [`crate::core::runtime::context::CoreContext`]
/// is built (some unit tests) ⇒ callers treat that as "no filtering" (full).
diff --git a/crates/openhuman-core/src/core/all_bound_controller_tests.rs b/crates/openhuman-core/src/core/all_bound_controller_tests.rs
index d8531ad8a6..88ddac1273 100644
--- a/crates/openhuman-core/src/core/all_bound_controller_tests.rs
+++ b/crates/openhuman-core/src/core/all_bound_controller_tests.rs
@@ -47,8 +47,7 @@ fn schema() -> ControllerSchema {
}
fn params() -> Map<String, Value> {
- serde_json::from_value(serde_json::json!({"value":"fixture"}))
- .expect("fixture is an object")
+ serde_json::from_value(serde_json::json!({"value":"fixture"})).expect("fixture is an object")
}
#[test]
@@ -64,18 +63,20 @@ fn bound_controller_uses_its_parser_for_decode_and_runtime_invocation() {
let output = futures::executor::block_on(controller.invoke(DispatchCtx::unbound(), params()))
.expect("runtime invocation succeeds");
assert_eq!(output, Value::String("fixture".to_owned()));
- assert_eq!(CALLS.load(Ordering::SeqCst), 3, "invocation parses then runs");
+ assert_eq!(
+ CALLS.load(Ordering::SeqCst),
+ 3,
+ "invocation parses then runs"
+ );
}
#[test]
fn bound_controller_decode_does_not_run_gate_or_business_handler() {
CALLS.store(0, Ordering::SeqCst);
- let controller = BoundRegisteredController::after_gate(
- schema(),
- gate,
- parse_value,
- |_ctx, (), parsed| run_value(DispatchCtx::unbound(), parsed),
- );
+ let controller =
+ BoundRegisteredController::after_gate(schema(), gate, parse_value, |_ctx, (), parsed| {
+ run_value(DispatchCtx::unbound(), parsed)
+ });
controller
.decode_params(params())
@@ -91,12 +92,8 @@ fn bound_controller_decode_does_not_run_gate_or_business_handler() {
#[test]
fn bound_controller_runs_gate_before_parser() {
CALLS.store(0, Ordering::SeqCst);
- let controller = BoundRegisteredController::after_gate(
- schema(),
- gate,
- parse_value,
- run_value_after_gate,
- );
+ let controller =
+ BoundRegisteredController::after_gate(schema(), gate, parse_value, run_value_after_gate);
let output = futures::executor::block_on(controller.invoke(DispatchCtx::unbound(), params()))
.expect("gated runtime invocation succeeds");
diff --git a/crates/openhuman-core/src/core/all_dispatch_ctx_tests.rs b/crates/openhuman-core/src/core/all_dispatch_ctx_tests.rs
index 16c958cdcb..981bc9cb19 100644
--- a/crates/openhuman-core/src/core/all_dispatch_ctx_tests.rs
+++ b/crates/openhuman-core/src/core/all_dispatch_ctx_tests.rs
@@ -1,6 +1,6 @@
//! The dispatch context reaches the handler as an argument, per call.
-use serde_json::{json, Map, Value};
+use serde_json::{Map, Value, json};
use super::*;
use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
diff --git a/crates/openhuman-core/src/core/all_extensions_tests.rs b/crates/openhuman-core/src/core/all_extensions_tests.rs
index b77961284f..7626dfc05b 100644
--- a/crates/openhuman-core/src/core/all_extensions_tests.rs
+++ b/crates/openhuman-core/src/core/all_extensions_tests.rs
@@ -31,9 +31,11 @@ async fn registry_extension_is_visible_to_every_lookup_and_dispatches() {
Some("openhuman.ext_probe_ping")
);
assert!(schema_for_rpc_method("openhuman.ext_probe_ping").is_some());
- assert!(all_controller_schemas()
- .iter()
- .any(|s| s.namespace == "ext_probe" && s.function == "ping"));
+ assert!(
+ all_controller_schemas()
+ .iter()
+ .any(|s| s.namespace == "ext_probe" && s.function == "ping")
+ );
assert_eq!(
namespace_description("ext_probe"),
Some("Registry extension probe.")
diff --git a/crates/openhuman-core/src/core/all_invoke.rs b/crates/openhuman-core/src/core/all_invoke.rs
index 6de319ac4a..8afacee0fa 100644
--- a/crates/openhuman-core/src/core/all_invoke.rs
+++ b/crates/openhuman-core/src/core/all_invoke.rs
@@ -5,7 +5,7 @@ use std::pin::Pin;
use serde_json::{Map, Value};
-use super::{internal_registry, registry_view, visible, ControllerFuture};
+use super::{ControllerFuture, internal_registry, registry_view, visible};
use crate::core::runtime::{CoreContext, DispatchCtx};
type Dispatched = Pin<Box<dyn Future<Output = Option<Result<Value, String>>> + Send + 'static>>;
diff --git a/crates/openhuman-core/src/core/all_schema_contract_tests.rs b/crates/openhuman-core/src/core/all_schema_contract_tests.rs
index 21bd03a012..5e877c670a 100644
--- a/crates/openhuman-core/src/core/all_schema_contract_tests.rs
+++ b/crates/openhuman-core/src/core/all_schema_contract_tests.rs
@@ -40,9 +40,11 @@ fn registered_memory_contract_rejects_missing_or_optional_question() {
.expect("real recall schema declares question")
.required = false;
}
- assert!(independent_registered_schema_contract(&broken)
- .unwrap_err()
- .contains("memory.recall required inputs mismatch"));
+ assert!(
+ independent_registered_schema_contract(&broken)
+ .unwrap_err()
+ .contains("memory.recall required inputs mismatch")
+ );
}
}
@@ -140,14 +142,16 @@ fn registered_wallet_schema_contract_rejects_missing_encrypted_mnemonic() {
.inputs
.retain(|input| input.name != "encryptedMnemonic");
- assert!(independent_registered_schema_contract(&schema)
- .unwrap_err()
- .contains("is missing required input `encryptedMnemonic`"));
+ assert!(
+ independent_registered_schema_contract(&schema)
+ .unwrap_err()
+ .contains("is missing required input `encryptedMnemonic`")
+ );
}
/// Built-in/internal snapshots avoid ambient DomainSet filtering and global
/// hosted-extension mutation. Hosted/RPC contracts belong to their own crates.
-fn builtin_controller_snapshot() -> Vec<RegisteredController> {
+fn builtin_controller_snapshot() -> Vec<ControllerEntry> {
registry()
.iter()
.chain(internal_registry())
@@ -165,6 +169,7 @@ fn representative_parameter_contracts() -> (Vec<RegisteredController>, Vec<Contr
&& controller.schema.method_name() == "mcp_clients.registry_get")
|| controller.schema.method_name() == "modules.computer_status"
})
+ .filter_map(|controller| controller.legacy_controller())
.collect();
let contracts = vec![crate::modules::schemas::computer_status_parameter_contract()];
#[cfg(feature = "mcp")]
@@ -238,15 +243,19 @@ fn real_contract_inventory_rejects_a_missing_and_an_extra_row() {
let removed = contracts
.pop()
.expect("representative contracts are nonempty");
- assert!(verify_parameter_contracts(&controllers, &contracts)
- .unwrap_err()
- .contains("missing contract"));
+ assert!(
+ verify_parameter_contracts(&controllers, &contracts)
+ .unwrap_err()
+ .contains("missing contract")
+ );
contracts.push(removed.clone());
contracts.push(ControllerParamContract {
method: "unregistered.fixture",
..removed
});
- assert!(verify_parameter_contracts(&controllers, &contracts)
- .unwrap_err()
- .contains("extra contract"));
+ assert!(
+ verify_parameter_contracts(&controllers, &contracts)
+ .unwrap_err()
+ .contains("extra contract")
+ );
}
diff --git a/crates/openhuman-core/src/core/all_tests.rs b/crates/openhuman-core/src/core/all_tests.rs
index c1cd50f25f..74822ffd29 100644
--- a/crates/openhuman-core/src/core/all_tests.rs
+++ b/crates/openhuman-core/src/core/all_tests.rs
@@ -856,8 +856,8 @@ fn every_registered_controller_has_matching_declared_schema() {
// --- DomainSet registration filter (#4796) ------------------------------
-use crate::core::runtime::context::CoreContext;
use crate::core::runtime::DomainSet;
+use crate::core::runtime::context::CoreContext;
/// The [`DomainGroup`] a registered controller (agent-facing OR internal) is
/// tagged with, looked up by its namespace. Test-only helper over the private
diff --git a/crates/openhuman-core/src/core/schema_test_support_tests.rs b/crates/openhuman-core/src/core/schema_test_support_tests.rs
index badc747371..7def87c3fa 100644
--- a/crates/openhuman-core/src/core/schema_test_support_tests.rs
+++ b/crates/openhuman-core/src/core/schema_test_support_tests.rs
@@ -61,9 +61,11 @@ fn contract_inventory_rejects_missing_extra_duplicate_and_empty_rows() {
.unwrap_err()
.contains("duplicate contract")
);
- assert!(verify_parameter_contracts(&[], &[])
- .unwrap_err()
- .contains("empty"));
+ assert!(
+ verify_parameter_contracts(&[], &[])
+ .unwrap_err()
+ .contains("empty")
+ );
}
#[test]
@@ -110,43 +112,55 @@ fn callback_identity_and_explicit_example_failures_are_not_hidden() {
);
let mut broken = contract;
broken.examples = vec![serde_json::json!({"id":7})];
- assert!(verify_parameter_contracts(&[controller], &[broken])
- .unwrap_err()
- .contains("schema rejects example"));
+ assert!(
+ verify_parameter_contracts(&[controller], &[broken])
+ .unwrap_err()
+ .contains("schema rejects example")
+ );
}
#[test]
fn duplicate_controller_and_schema_identity_failures_are_rejected() {
let (controller, contract) = fixture();
- assert!(verify_parameter_contracts(
- &[controller.clone(), controller.clone()],
- std::slice::from_ref(&contract)
- )
- .unwrap_err()
- .contains("duplicate controller"));
+ assert!(
+ verify_parameter_contracts(
+ &[controller.clone(), controller.clone()],
+ std::slice::from_ref(&contract)
+ )
+ .unwrap_err()
+ .contains("duplicate controller")
+ );
let mut broken = controller.schema.clone();
broken.function = "other";
- assert!(verify_parameter_schema(&broken, &contract)
- .unwrap_err()
- .contains("method identity"));
+ assert!(
+ verify_parameter_schema(&broken, &contract)
+ .unwrap_err()
+ .contains("method identity")
+ );
let mut broken = controller.schema;
broken.description = " ";
- assert!(verify_parameter_schema(&broken, &contract)
- .unwrap_err()
- .contains("no description"));
+ assert!(
+ verify_parameter_schema(&broken, &contract)
+ .unwrap_err()
+ .contains("no description")
+ );
}
#[test]
fn examples_must_be_objects_and_satisfy_schema_before_decoding() {
let (controller, mut contract) = fixture();
contract.examples = vec![Value::Null];
- assert!(verify_parameter_schema(&controller.schema, &contract)
- .unwrap_err()
- .contains("not an object"));
+ assert!(
+ verify_parameter_schema(&controller.schema, &contract)
+ .unwrap_err()
+ .contains("not an object")
+ );
contract.examples = vec![serde_json::json!({})];
- assert!(verify_parameter_schema(&controller.schema, &contract)
- .unwrap_err()
- .contains("schema rejects example"));
+ assert!(
+ verify_parameter_schema(&controller.schema, &contract)
+ .unwrap_err()
+ .contains("schema rejects example")
+ );
}
#[test]
diff --git a/crates/openhuman-core/src/threads/schemas/handlers.rs b/crates/openhuman-core/src/threads/schemas/handlers.rs
index 4f67e9d43b..cb8fc4f24e 100644
--- a/crates/openhuman-core/src/threads/schemas/handlers.rs
+++ b/crates/openhuman-core/src/threads/schemas/handlers.rs
@@ -32,10 +32,7 @@ pub(super) fn parse_upsert(
parse(params)
}
-pub(super) fn run_upsert(
- ctx: DispatchCtx,
- p: UpsertConversationThreadRequest,
-) -> ControllerFuture {
+pub(super) fn run_upsert(ctx: DispatchCtx, p: UpsertConversationThreadRequest) -> ControllerFuture {
Box::pin(async move {
// A SaaS user picks thread ids for their own threads only; reserved
// prefixes and path-like ids are refused (no-op outside SaaS).
diff --git a/crates/openhuman-core/src/threads/schemas/registry.rs b/crates/openhuman-core/src/threads/schemas/registry.rs
index 608cd9b31e..608bded3e0 100644
--- a/crates/openhuman-core/src/threads/schemas/registry.rs
+++ b/crates/openhuman-core/src/threads/schemas/registry.rs
@@ -1,8 +1,8 @@
//! Controller schema and registered-controller lists for the `threads`
//! namespace.
-use crate::core::all::{BoundRegisteredController, ControllerEntry, RegisteredController};
use crate::core::ControllerSchema;
+use crate::core::all::{BoundRegisteredController, ControllerEntry, RegisteredController};
use super::handlers::{
handle_create_new, handle_delete, handle_edit_message, handle_generate_title, handle_goal_get,
diff --git a/crates/openhuman-core/src/threads/schemas/schema_defs.rs b/crates/openhuman-core/src/threads/schemas/schema_defs.rs
index 99c3b9d34c..4c68c11ad4 100644
--- a/crates/openhuman-core/src/threads/schemas/schema_defs.rs
+++ b/crates/openhuman-core/src/threads/schemas/schema_defs.rs
@@ -154,8 +154,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"generate_title" => ControllerSchema {
namespace: "threads",
function: "generate_title",
- description:
- "Generate a short thread title from the first user message and assistant reply.",
+ description: "Generate a short thread title from the first user message and assistant reply.",
inputs: vec![
FieldSchema {
name: "thread_id",
@@ -166,8 +165,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
FieldSchema {
name: "assistant_message",
ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment:
- "Optional completed assistant reply to use instead of the stored first agent message.",
+ comment: "Optional completed assistant reply to use instead of the stored first agent message.",
required: false,
},
],
@@ -310,8 +308,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"turn_state_list" => ControllerSchema {
namespace: "threads",
function: "turn_state_list",
- description:
- "List every persisted turn snapshot — used to surface interrupted turns on cold boot.",
+ description: "List every persisted turn snapshot — used to surface interrupted turns on cold boot.",
inputs: vec![],
outputs: vec![FieldSchema {
name: "result",
@@ -323,8 +320,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"turn_state_history" => ControllerSchema {
namespace: "threads",
function: "turn_state_history",
- description:
- "List every persisted turn snapshot for one thread, newest first — the per-turn process history.",
+ description: "List every persisted turn snapshot for one thread, newest first — the per-turn process history.",
inputs: vec![FieldSchema {
name: "thread_id",
ty: TypeSchema::String,
@@ -400,8 +396,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"transcript_get" => ControllerSchema {
namespace: "threads",
function: "transcript_get",
- description:
- "Project a thread's settled transcript (read from the session store) into typed display items, newest-first paginated.",
+ description: "Project a thread's settled transcript (read from the session store) into typed display items, newest-first paginated.",
inputs: vec![
FieldSchema {
name: "thread_id",
@@ -432,8 +427,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"goal_get" => ControllerSchema {
namespace: "threads",
function: "goal_get",
- description:
- "Read a thread's current goal (Codex-style completion contract), or null when it has none.",
+ description: "Read a thread's current goal (Codex-style completion contract), or null when it has none.",
inputs: vec![FieldSchema {
name: "thread_id",
ty: TypeSchema::String,
@@ -467,8 +461,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"edit_message" => ControllerSchema {
namespace: "threads",
function: "edit_message",
- description:
- "Edit a past user message: cancel the thread's in-flight turn, drop that message and everything after it, and restart the turn with the new content.",
+ description: "Edit a past user message: cancel the thread's in-flight turn, drop that message and everything after it, and restart the turn with the new content.",
inputs: vec![
FieldSchema {
name: "thread_id",
@@ -505,8 +498,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"regenerate" => ControllerSchema {
namespace: "threads",
function: "regenerate",
- description:
- "Regenerate a past assistant reply (or, with no message_id, the thread's last turn): cancel the in-flight turn, drop the answer and everything after it, and restart with the same prompt.",
+ description: "Regenerate a past assistant reply (or, with no message_id, the thread's last turn): cancel the in-flight turn, drop the answer and everything after it, and restart with the same prompt.",
inputs: vec![
FieldSchema {
name: "thread_id",
@@ -537,8 +529,7 @@ pub(crate) fn schemas(function: &str) -> ControllerSchema {
"search" => ControllerSchema {
namespace: "threads",
function: "search",
- description:
- "Search message text across every thread (global search). Hits are newest first, each with a snippet around the match.",
+ description: "Search message text across every thread (global search). Hits are newest first, each with a snippet around the match.",
inputs: vec![
FieldSchema {
name: "query",