Skip to content

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

fix(schemas): declare pid as U64 and document param-validation precedence\n\n`health_system_info` declared `pid` as `TypeSchema::String` while\n`SystemInfo.pid: u32` serializes as a JSON number. Output fields are not\nvalidated at dispatch, so nothing failed at runtime — but the schema\ngenerates the frontend's RPC types and feeds the model-facing tool\n`output_schema` (`tools/registry/ops.rs:375`), so the wrong type reached\nboth consumers. Declaring `U64` leaves the wire format untouched.\n`platform/health/README.md` documented the mismatch as intended; updated.\n\nSeparately, handler-level "missing required param" strings cannot reach a\ncaller: `core::all::validate_params` is the single pre-dispatch gate and\nrefuses first, in its own wording, carrying the field's schema comment as\na suffix. Rather than delete the shadowed handler checks, document them.\nDeletion is not the near-zero-risk change it looks like: the coverage\nsuites invoke controllers via `(controller.handler)(params)` with no\nvalidation, so ~18 existing assertions pass *because* of those checks, and\nmost of the 150 `missing required param` sites across 74 files belong to\nagent tool handlers taking model-produced arguments, which never pass\nthrough `validate_params` at all.\n\n`validate_params` now documents its own precedence: the entry points that\nvalidate before `try_invoke_registered_rpc`, the one internal call site\nthat relies on its caller (`mcp::server::write_dispatch`), and what that\nmeans for whoever writes the next test. The three handler sites named in\nthe issue point back at it.\n\nAdds `tests/raw_coverage/dispatch_param_validation_e2e.rs`, which drives\nthe real dispatcher and pins what a caller observes for missing, unknown\nand mistyped params, plus a health test pairing every declared output type\nagainst the handler's live JSON.\n\nCloses #6073\nCloses #6074\n

Shanude8a99efa79d
diff --git a/src/core/all.rs b/src/core/all.rs
index 2a39ca1860..a01fa275f1 100644
--- a/src/core/all.rs
+++ b/src/core/all.rs
@@ -1328,6 +1328,45 @@ pub fn schema_for_rpc_method(method: &str) -> Option<ControllerSchema> {
/// Validates that the provided parameters match the requirements of the controller schema.
///
+/// This is the *single* pre-dispatch gate for every registered controller. Each
+/// path that reaches `try_invoke_registered_rpc` validates first:
+///
+/// | entry point | validates in |
+/// | --- | --- |
+/// | HTTP JSON-RPC | `core::jsonrpc` |
+/// | dynamic dispatch fallback | `core::dispatch::try_registry_dispatch` |
+/// | CLI | `core::cli` |
+/// | MCP read and write tools | `openhuman::mcp::server::tools::params` |
+///
+/// The one call site that does not validate for itself is
+/// `openhuman::mcp::server::write_dispatch`, whose sole caller
+/// (`openhuman::mcp::server::tools::dispatch`) validates immediately before it.
+/// That is not a gap today, but it is the place a refactor could open one.
+///
+/// # Relationship to handler-side parameter checks (#6073)
+///
+/// Many handlers re-check required params themselves, in wording of their own
+/// (`missing required param: id`, ``missing required `class` ``,
+/// `invalid params: …`). A caller never sees those: this function has already
+/// refused the call, and its message carries the field's *schema comment* as a
+/// suffix — `missing required param 'id': Session ID.` — so the two are not
+/// interchangeable strings.
+///
+/// Those handler checks are kept deliberately, for two reasons:
+///
+/// - Not every `missing required param` in the tree belongs to a registered
+/// controller. Agent *tool* handlers take model-produced arguments and are
+/// not dispatched through this function at all, so their checks are load
+/// bearing.
+/// - A `RegisteredController`'s handler can be invoked directly, and several
+/// `tests/raw_coverage` suites do exactly that, asserting the handler's own
+/// refusal.
+///
+/// The practical consequence is for whoever writes the next test: asserting
+/// handler wording exercises the handler, not the dispatch path. To pin what a
+/// caller actually observes, go through one of the entry points above — see
+/// `tests/raw_coverage/dispatch_param_validation_e2e.rs`.
+///
/// # Errors
///
/// Returns an error message if required parameters are missing or if unknown parameters are provided.
diff --git a/src/openhuman/agent/learning/schemas_part_02.rs b/src/openhuman/agent/learning/schemas_part_02.rs
index 5825d14160..0c35e3ee23 100644
--- a/src/openhuman/agent/learning/schemas_part_02.rs
+++ b/src/openhuman/agent/learning/schemas_part_02.rs
@@ -52,6 +52,12 @@ fn handle_list_facets(params: Map<String, Value>) -> ControllerFuture {
fn handle_get_facet(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
+ // Belt-and-braces. A dispatched call has already been through
+ // `core::all::validate_params`, which refuses a missing `class`/`key`
+ // with its own wording (and the schema comment as a suffix), so these
+ // two refusals are reachable only by invoking this handler directly —
+ // which is how the `tests/raw_coverage` suites call it. See the
+ // `validate_params` docs for why they are kept (#6073).
let class_str = params
.get("class")
.and_then(Value::as_str)
diff --git a/src/openhuman/agent/session_db/schemas.rs b/src/openhuman/agent/session_db/schemas.rs
index b944c345d0..707b9aa9db 100644
--- a/src/openhuman/agent/session_db/schemas.rs
+++ b/src/openhuman/agent/session_db/schemas.rs
@@ -249,6 +249,12 @@ fn handle_session_db_list(params: Map<String, Value>) -> ControllerFuture {
})
}
+// The `missing required param: …` refusals in the handlers below (and their
+// `run_ledger` siblings) are belt-and-braces: `core::all::validate_params` has
+// already rejected such a call before dispatch, in its own wording, so a caller
+// sees `missing required param 'id': Session ID.` and never these strings. They
+// remain reachable by invoking a handler directly. See the `validate_params`
+// docs for why they are kept (#6073).
fn handle_session_db_get(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let cid = new_correlation_id();
diff --git a/src/openhuman/memory/goals/schemas.rs b/src/openhuman/memory/goals/schemas.rs
index 9042c0dde8..372a1d5ad5 100644
--- a/src/openhuman/memory/goals/schemas.rs
+++ b/src/openhuman/memory/goals/schemas.rs
@@ -242,6 +242,12 @@ struct ReflectParams {
context: Option<String>,
}
+/// Belt-and-braces deserialization for the goals handlers.
+///
+/// Its `invalid params: …` refusal is not what a dispatched caller sees: a
+/// missing or mistyped param is rejected earlier by `core::all::validate_params`,
+/// in that function's wording. This is reachable only by invoking a handler
+/// directly. See the `validate_params` docs for why it is kept (#6073).
fn parse_value<T: DeserializeOwned>(v: Value) -> Result<T, String> {
serde_json::from_value(v).map_err(|e| format!("invalid params: {e}"))
}
diff --git a/src/openhuman/platform/health/README.md b/src/openhuman/platform/health/README.md
index c0549d0eaf..251702ad5c 100644
--- a/src/openhuman/platform/health/README.md
+++ b/src/openhuman/platform/health/README.md
@@ -85,5 +85,5 @@ None on disk. State lives in a process-global `OnceLock<HealthRegistry>` (lazy-i
- `upsert_component` creates entries lazily with initial status `"starting"` and always refreshes `updated_at` after the update closure.
- `mark_component_ok` clears `last_error`; `mark_component_error` leaves `last_ok` intact (so the last-known-good time survives a failure).
- `restart_count` uses `saturating_add` (won't overflow).
-- The `system_info` schema declares `pid` as a `String` (`TypeSchema::String`) even though the `SystemInfo` struct serializes `pid` as a numeric `u32` — schema type vs. wire type differ here.
+- The `system_info` schema declares `pid` as `TypeSchema::U64`, matching `SystemInfo.pid: u32`, which serializes as a JSON number. It declared `TypeSchema::String` until #6074; the wire value has always been a number, so that fix moved only the declaration — and with it the generated frontend types and the model-facing tool `output_schema`.
- `bus.rs` short-circuits double registration via a `OnceLock` and warns (does not panic) if the bus isn't initialized.
diff --git a/src/openhuman/platform/health/schemas.rs b/src/openhuman/platform/health/schemas.rs
index bf865c6915..66180e1369 100644
--- a/src/openhuman/platform/health/schemas.rs
+++ b/src/openhuman/platform/health/schemas.rs
@@ -60,9 +60,15 @@ pub fn schemas(function: &str) -> ControllerSchema {
comment: "CPU architecture (x86_64, aarch64, …).",
required: true,
},
+ // `SystemInfo.pid` is a `u32` and serializes as a JSON number,
+ // so the declaration is `U64`, not `String` (#6074). Output
+ // fields are not validated at dispatch, but this schema is what
+ // generates the frontend's RPC types and what the agent tool
+ // surface advertises to a model, so a wrong type here is wrong
+ // at both consumers.
FieldSchema {
name: "pid",
- ty: TypeSchema::String,
+ ty: TypeSchema::U64,
comment: "Current process ID.",
required: true,
},
diff --git a/src/openhuman/platform/health/schemas_tests.rs b/src/openhuman/platform/health/schemas_tests.rs
index 0a74fdb620..5bf44b6533 100644
--- a/src/openhuman/platform/health/schemas_tests.rs
+++ b/src/openhuman/platform/health/schemas_tests.rs
@@ -70,3 +70,40 @@ fn to_json_helper() {
let outcome = RpcOutcome::single_log(serde_json::json!({"ok": true}), "log");
assert!(to_json(outcome).is_ok());
}
+
+/// Every declared output type must match the JSON the handler actually emits.
+///
+/// `pid` drifted exactly this way (#6074): the schema said `TypeSchema::String`
+/// while `SystemInfo.pid` is a `u32` that serializes as a JSON number, so the
+/// generated frontend types and the model-facing tool `output_schema` both
+/// advertised a type the wire never carried. Output fields are not validated at
+/// dispatch, so nothing at runtime would have caught it — checking the
+/// declaration against a live response is what keeps the two from separating
+/// again.
+#[tokio::test]
+async fn system_info_declared_output_types_match_emitted_json() {
+ let schema = schemas("system_info");
+ let json = handle_system_info(Map::new())
+ .await
+ .expect("system_info handler succeeds");
+
+ assert_eq!(schema.outputs.len(), 4, "version, os, arch, pid");
+ for field in &schema.outputs {
+ let value = json
+ .get(field.name)
+ .unwrap_or_else(|| panic!("`{}` missing from the response", field.name));
+ let ok = match field.ty {
+ TypeSchema::String => value.is_string(),
+ TypeSchema::U64 => value.is_u64(),
+ // Deliberately exhaustive-by-panic: a field declared as some other
+ // type has no check here yet, and silently passing would defeat the
+ // point of this test.
+ ref other => panic!("`{}` declares {other:?}; add a check for it", field.name),
+ };
+ assert!(
+ ok,
+ "`{}` declares {:?} but the handler emitted {value}",
+ field.name, field.ty
+ );
+ }
+}
diff --git a/tests/raw_coverage/dispatch_param_validation_e2e.rs b/tests/raw_coverage/dispatch_param_validation_e2e.rs
new file mode 100644
index 0000000000..7973f11b8f
--- /dev/null
+++ b/tests/raw_coverage/dispatch_param_validation_e2e.rs
@@ -0,0 +1,115 @@
+//! What a caller actually observes when a dispatched call carries bad params.
+//!
+//! `core::all::validate_params` is the single pre-dispatch gate for every
+//! registered controller, so a handler's own "missing required param" string can
+//! never reach a caller. Plenty of handlers keep such a check anyway, worded
+//! differently, and those are reachable only by invoking the handler directly —
+//! which is exactly what most suites in this directory do. That makes it easy to
+//! write a test that looks like it covers the dispatch path and does not: the
+//! assertion passes on the handler's string while a real caller would have been
+//! refused earlier, by a different message.
+//!
+//! These tests pin the observable behaviour so that the distinction cannot be
+//! erased silently (#6073).
+
+use serde_json::{json, Map};
+
+use openhuman_core::core::all::{all_registered_controllers, rpc_method_name, schema_for_rpc_method};
+use openhuman_core::core::dispatch::dispatch;
+use openhuman_core::core::types::AppState;
+
+fn state() -> AppState {
+ AppState {
+ core_version: "dispatch-param-validation-e2e".to_string(),
+ }
+}
+
+/// The refusal a caller sees carries the *schema's* comment, not the handler's
+/// wording — which is what makes the two impossible to mistake for each other.
+#[tokio::test]
+async fn missing_required_param_is_refused_with_the_schema_comment() {
+ let schema = schema_for_rpc_method("openhuman.session_db_get")
+ .expect("session_db_get is registered unconditionally");
+ let comment = schema
+ .inputs
+ .iter()
+ .find(|field| field.name == "id")
+ .expect("`id` input")
+ .comment;
+
+ let err = dispatch(state(), "openhuman.session_db_get", json!({}))
+ .await
+ .expect_err("`id` is required");
+
+ assert_eq!(err, format!("missing required param 'id': {comment}"));
+
+ // `handle_session_db_get` refuses with `missing required param: id`. If that
+ // ever starts matching, validation has moved into the handler and the shape
+ // of what callers see has changed with it.
+ assert!(!err.contains("missing required param: id"), "got: {err}");
+}
+
+/// A param that no schema declares is refused before dispatch. No handler
+/// anywhere implements an unknown-param check, so this message can only come
+/// from `validate_params` — it is the proof that the gate ran.
+#[tokio::test]
+async fn unknown_param_is_refused_by_the_gate_alone() {
+ let err = dispatch(
+ state(),
+ "openhuman.memory_goals_list",
+ json!({ "nonsense_param": 1 }),
+ )
+ .await
+ .expect_err("unknown params are refused");
+
+ assert_eq!(err, "unknown param 'nonsense_param' for memory_goals.list");
+}
+
+/// Declared types are enforced at the same gate, so a handler's own
+/// `serde_json::from_value` error is not what a caller gets either.
+#[tokio::test]
+async fn mistyped_param_is_refused_with_the_declared_type() {
+ let err = dispatch(
+ state(),
+ "openhuman.session_import_run",
+ json!({ "dry_run": "yes" }),
+ )
+ .await
+ .expect_err("`dry_run` is declared bool");
+
+ assert_eq!(
+ err,
+ "invalid type for param 'dry_run' in session_import.run: expected bool, got string"
+ );
+ assert!(!err.contains("invalid params:"), "got: {err}");
+}
+
+/// The handler-side checks are real and they do fire — just never for a caller.
+/// Reaching one takes a direct handler invocation, the way the suites in this
+/// directory call controllers.
+#[tokio::test]
+async fn handler_checks_are_reachable_only_by_calling_the_handler_directly() {
+ let dispatched = dispatch(state(), "openhuman.learning_get_facet", json!({}))
+ .await
+ .expect_err("`class` is required");
+ assert!(
+ dispatched.starts_with("missing required param 'class': "),
+ "got: {dispatched}"
+ );
+
+ let controllers = all_registered_controllers();
+ let controller = controllers
+ .iter()
+ .find(|controller| rpc_method_name(&controller.schema) == "openhuman.learning_get_facet")
+ .expect("learning_get_facet is registered unconditionally");
+ let direct = (controller.handler)(Map::new())
+ .await
+ .expect_err("the handler refuses too");
+
+ assert_eq!(direct, "missing required `class`");
+ assert_ne!(
+ dispatched, direct,
+ "the two refusals must stay distinguishable: a test written against the \
+ handler's wording is testing the handler, not the dispatch path (#6073)"
+ );
+}