Skip to content

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

docs(core): qualify param-validation precedence for explicit JSON null\n\nThe precedence note claimed a caller can never observe a handler's own\n"missing required param" string. That is false for an explicit `null`:\n`validate_params` checks required fields for key *presence* only, and\n`check_type` returns early when `value.is_null()`. A dispatched\n`{"class": null, "key": "verbosity"}` therefore passes the gate, runs\n`handle_get_facet`, and the caller gets the handler's ``missing required\n`class` ``. `core/all_tests.rs::validate_params_null_for_required_is_acceptable`\nalready pinned this ("handlers enforce stronger type contracts downstream");\nthe new note contradicted it.\n\nCorrected in all four doc sites: the dispatcher's wording wins for an\nabsent, unknown or wrong-typed param, while an explicit null reaches the\nhandler, where its own check is the only guard. That makes the handler-side\nchecks load-bearing on a dispatched path too — a stronger reason to keep\nthem than the one #6073 gives.\n\nRenames `handler_checks_are_reachable_only_by_calling_the_handler_directly`,\nwhose name asserted the wrong invariant, and adds\n`explicit_null_passes_the_gate_and_the_handler_refuses_instead` to pin the\nnull path.\n\nFound by CodeRabbit on #6095; verified against the code and the existing\ntest before applying.\n

Shanud6bbf8c9c07f
diff --git a/src/core/all.rs b/src/core/all.rs
index a01fa275f1..7a3dd21e5e 100644
--- a/src/core/all.rs
+++ b/src/core/all.rs
@@ -1347,24 +1347,34 @@ pub fn schema_for_rpc_method(method: &str) -> Option<ControllerSchema> {
///
/// 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
+/// `invalid params: …`). For an *absent*, *unknown* or *wrong-typed* param a
+/// caller never reaches those: this function refuses first, 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:
+/// They are not redundant, though. This function deliberately accepts an
+/// explicit JSON `null` for any declared type: the required check tests key
+/// *presence*, and `check_type` returns early on null (see
+/// `validate_params_null_for_required_is_acceptable`). A dispatched
+/// `{"class": null}` therefore passes this gate and runs the handler, whose own
+/// refusal is exactly what the caller sees. On that path the handler-side check
+/// is the only guard there is.
+///
+/// Two further reasons they stay:
///
/// - 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.
+/// 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
+/// The practical consequence is for whoever writes the next test: a
+/// *missing-key* case asserted against handler wording is testing 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
diff --git a/src/openhuman/agent/learning/schemas_part_02.rs b/src/openhuman/agent/learning/schemas_part_02.rs
index 0c35e3ee23..d0012cd321 100644
--- a/src/openhuman/agent/learning/schemas_part_02.rs
+++ b/src/openhuman/agent/learning/schemas_part_02.rs
@@ -52,12 +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).
+ // These refusals are reachable from a dispatched call, not only from a
+ // direct one. An *absent* `class`/`key` is refused earlier by
+ // `core::all::validate_params`, in its own wording — but an explicit
+ // `{"class": null}` passes that gate (the required check tests key
+ // presence, and its type check returns early on null), so on that path
+ // this is the only guard. See the `validate_params` docs (#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 707b9aa9db..4100c0d2fc 100644
--- a/src/openhuman/agent/session_db/schemas.rs
+++ b/src/openhuman/agent/session_db/schemas.rs
@@ -250,11 +250,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).
+// `run_ledger` siblings) are not redundant with `core::all::validate_params`.
+// An *absent* `id` is refused before dispatch in that function's wording
+// (`missing required param 'id': Session ID.`), so a caller does not see these
+// strings for that case — but an explicit `{"id": null}` passes the gate (the
+// required check tests key presence, and its type check returns early on null)
+// and lands here. See the `validate_params` docs (#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 372a1d5ad5..c3024b83b5 100644
--- a/src/openhuman/memory/goals/schemas.rs
+++ b/src/openhuman/memory/goals/schemas.rs
@@ -242,12 +242,14 @@ struct ReflectParams {
context: Option<String>,
}
-/// Belt-and-braces deserialization for the goals handlers.
+/// Deserialization guard 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).
+/// An absent or mistyped param is rejected earlier by
+/// `core::all::validate_params`, so that function's wording — not
+/// `invalid params: …` — is what a caller sees for those. But the dispatcher
+/// accepts an explicit `null` for any declared type, and `from_value` into a
+/// non-`Option` field does not, so it can hand down a value this still refuses.
+/// See the `validate_params` docs (#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/tests/raw_coverage/dispatch_param_validation_e2e.rs b/tests/raw_coverage/dispatch_param_validation_e2e.rs
index 7973f11b8f..a9d0ffc17c 100644
--- a/tests/raw_coverage/dispatch_param_validation_e2e.rs
+++ b/tests/raw_coverage/dispatch_param_validation_e2e.rs
@@ -1,16 +1,21 @@
//! 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.
+//! registered controller, so for an *absent*, *unknown* or *wrong-typed* param a
+//! handler's own "missing required param" string never reaches a caller — the
+//! gate refuses first, in different wording.
//!
-//! These tests pin the observable behaviour so that the distinction cannot be
-//! erased silently (#6073).
+//! It is not a total shield. The gate accepts an explicit JSON `null` for any
+//! declared type: the required check tests key *presence*, and its type check
+//! returns early on null. So a dispatched `{"class": null}` runs the handler and
+//! the handler's own refusal is what comes back. That is why #6073 keeps the
+//! handler-side checks instead of deleting them — on the null path they are the
+//! only guard.
+//!
+//! Most suites in this directory invoke controllers directly
+//! (`(controller.handler)(params).await`), skipping validation altogether, so it
+//! is easy to write a test that looks like it covers the dispatch path and does
+//! not. These tests pin the observable behaviour on both sides of that line.
use serde_json::{json, Map};
@@ -84,11 +89,12 @@ async fn mistyped_param_is_refused_with_the_declared_type() {
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
+/// For an *absent* param the two refusals are different strings, and the
+/// dispatcher's is the one a caller gets. The handler's own check still fires —
+/// it just takes a direct invocation to see it, the way the suites in this
/// directory call controllers.
#[tokio::test]
-async fn handler_checks_are_reachable_only_by_calling_the_handler_directly() {
+async fn handler_refusal_differs_from_the_dispatcher_refusal_for_an_absent_param() {
let dispatched = dispatch(state(), "openhuman.learning_get_facet", json!({}))
.await
.expect_err("`class` is required");
@@ -113,3 +119,26 @@ async fn handler_checks_are_reachable_only_by_calling_the_handler_directly() {
handler's wording is testing the handler, not the dispatch path (#6073)"
);
}
+
+/// An explicit `null` satisfies the gate and reaches the handler, so here the
+/// handler's own refusal *is* what the caller sees. This is the case that makes
+/// the handler-side checks load-bearing rather than redundant, and the reason
+/// #6073 documents them instead of removing them.
+#[tokio::test]
+async fn explicit_null_passes_the_gate_and_the_handler_refuses_instead() {
+ let err = dispatch(
+ state(),
+ "openhuman.learning_get_facet",
+ json!({ "class": null, "key": "verbosity" }),
+ )
+ .await
+ .expect_err("`class` is null, so the handler refuses");
+
+ // The handler's wording, not the dispatcher's — the mirror image of
+ // `missing_required_param_is_refused_with_the_schema_comment`.
+ assert_eq!(err, "missing required `class`");
+ assert!(
+ !err.starts_with("missing required param 'class'"),
+ "the gate must NOT have refused this: {err}"
+ );
+}