Skip to content

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

fix(todos): defaulted card fields are not nullable, and pin that

M3gA-Mind3e3e801e64db
diff --git a/src/openhuman/threads/todos/schemas_part_02.rs b/src/openhuman/threads/todos/schemas_part_02.rs
index 211b8233d8..2cc98f1fc6 100644
--- a/src/openhuman/threads/todos/schemas_part_02.rs
+++ b/src/openhuman/threads/todos/schemas_part_02.rs
@@ -137,18 +137,31 @@ fn replace_cards_input() -> FieldSchema {
required: true,
},
optional_string("objective", "Richer objective for the card."),
- string_array_input("plan", "Ordered plan steps."),
+ defaulted_field(
+ "plan",
+ TypeSchema::Array(Box::new(TypeSchema::String)),
+ "Ordered plan steps. Omit the key to default to []; `null` is rejected.",
+ ),
optional_string("assignedAgent", "Agent assigned to run this card."),
- string_array_input("allowedTools", "Tools the assigned agent may use."),
+ defaulted_field(
+ "allowedTools",
+ TypeSchema::Array(Box::new(TypeSchema::String)),
+ "Tools the assigned agent may use. Omit to default to []; `null` is rejected.",
+ ),
optional_string(
"approvalMode",
"Plan-approval mode, when the card is gated.",
),
- string_array_input(
+ defaulted_field(
"acceptanceCriteria",
- "Acceptance criteria that define \"done\".",
+ TypeSchema::Array(Box::new(TypeSchema::String)),
+ "Acceptance criteria that define \"done\". Omit to default to []; `null` is rejected.",
+ ),
+ defaulted_field(
+ "evidence",
+ TypeSchema::Array(Box::new(TypeSchema::String)),
+ "Evidence gathered toward completion. Omit to default to []; `null` is rejected.",
),
- string_array_input("evidence", "Evidence gathered toward completion."),
optional_string("notes", "Free-form notes."),
optional_string("blocker", "Reason, when `status == blocked`."),
optional_string(
@@ -161,13 +174,16 @@ fn replace_cards_input() -> FieldSchema {
comment: "Provenance blob carried through untouched.",
required: false,
},
- FieldSchema {
- name: "order",
- ty: TypeSchema::Option(Box::new(TypeSchema::U64)),
- comment: "Sort position; defaults to 0.",
- required: false,
- },
- optional_string("updatedAt", "Last-update stamp; server-maintained."),
+ defaulted_field(
+ "order",
+ TypeSchema::U64,
+ "Sort position. Omit to default to 0; `null` is rejected.",
+ ),
+ defaulted_field(
+ "updatedAt",
+ TypeSchema::String,
+ "Last-update stamp, server-maintained. Omit it; `null` is rejected.",
+ ),
],
})),
comment: "Full replacement list. Each entry MUST carry `id`, `title` and \
@@ -177,6 +193,27 @@ fn replace_cards_input() -> FieldSchema {
}
}
+/// A `todos.replace` card field that upstream `#[serde(default)]`s.
+///
+/// Declared with its **non-`Option`** type and `required: false`, which is the
+/// accurate statement of the contract: the key may be *omitted* (serde supplies
+/// the default) but may not be sent as `null`. `TaskBoardCard`'s `plan`,
+/// `allowedTools`, `acceptanceCriteria` and `evidence` are `Vec<String>`,
+/// `order` is `u32` and `updatedAt` is `String` — none is an `Option`, so
+/// `null` fails deserialization with `invalid type: null`.
+///
+/// Declaring these as `Option(...)` would advertise `null` as valid and put the
+/// catalog right back to describing a call the handler rejects, which is the
+/// defect #6087 exists to remove.
+fn defaulted_field(name: &'static str, ty: TypeSchema, comment: &'static str) -> FieldSchema {
+ FieldSchema {
+ name,
+ ty,
+ comment,
+ required: false,
+ }
+}
+
fn snapshot_output() -> FieldSchema {
FieldSchema {
name: "snapshot",
diff --git a/tests/raw_coverage/todos_lifecycle_e2e.rs b/tests/raw_coverage/todos_lifecycle_e2e.rs
index 18f42694f8..e6affbe643 100644
--- a/tests/raw_coverage/todos_lifecycle_e2e.rs
+++ b/tests/raw_coverage/todos_lifecycle_e2e.rs
@@ -804,13 +804,88 @@ async fn todos_replace_accepts_a_card_built_only_from_its_declared_schema() {
card.insert(name, value);
}
+ // EXACTLY the trio, not merely "includes" it. `TaskBoardCard` has exactly
+ // three fields without a serde default; if a fourth is ever marked required
+ // in the catalog, a caller obeying the schema would send a key the handler
+ // does not need, and the loop above would happily paper over it.
+ let mut sorted = required_seen.clone();
+ sorted.sort();
+ assert_eq!(
+ sorted,
+ vec!["id".to_string(), "status".to_string(), "title".to_string()],
+ "the catalog must mark exactly `id`, `title` and `status` required — \
+ those are the only three `TaskBoardCard` fields with no serde default"
+ );
+
+ // The six `#[serde(default)]` fields must NOT be declared `Option(...)`.
+ //
+ // This is asserted against the *declaration*, not against a dispatch,
+ // because a dispatch cannot see it: `core::all::check_type` short-circuits
+ // on `Value::Null` for every declared type, so `null` reaches the handler
+ // either way and is rejected by serde either way. The declaration is
+ // therefore documentation-only at runtime — and documentation-only is
+ // exactly the thing that rots unnoticed, so it gets a direct assertion.
+ for name in [
+ "plan",
+ "allowedTools",
+ "acceptanceCriteria",
+ "evidence",
+ "order",
+ "updatedAt",
+ ] {
+ let field = card_fields
+ .iter()
+ .find(|f| f.get("name").and_then(Value::as_str) == Some(name))
+ .unwrap_or_else(|| panic!("the card must declare `{name}`"));
+ assert!(
+ field.get("ty").and_then(|t| t.get("Option")).is_none(),
+ "`{name}` is `#[serde(default)]` on a non-Option field upstream, so an \
+ explicit null fails to deserialize. Declaring it `Option(...)` advertises \
+ null as valid and puts the catalog back to describing a call the handler \
+ rejects. Declared ty was: {}",
+ field.get("ty").unwrap_or(&Value::Null)
+ );
+ assert_eq!(
+ field.get("required").and_then(Value::as_bool),
+ Some(false),
+ "`{name}` has a serde default, so it must be optional-by-omission"
+ );
+ }
+
+ // Every advertised status variant must actually parse. Taking only the
+ // first would let a misspelled later variant (`in-progress` for
+ // `in_progress`, say) sit in the catalog undetected.
+ let status_variants: Vec<String> = card_fields
+ .iter()
+ .find(|f| f.get("name").and_then(Value::as_str) == Some("status"))
+ .and_then(|f| f.get("ty"))
+ .and_then(|t| t.get("Enum"))
+ .and_then(|e| e.get("variants"))
+ .and_then(Value::as_array)
+ .unwrap_or_else(|| panic!("`status` must declare an enum of variants"))
+ .iter()
+ .filter_map(|v| v.as_str().map(str::to_string))
+ .collect();
assert!(
- required_seen.iter().any(|n| n == "id")
- && required_seen.iter().any(|n| n == "title")
- && required_seen.iter().any(|n| n == "status"),
- "the catalog must mark `id`, `title` and `status` required — those are \
- the three `TaskBoardCard` fields with no serde default. Got: {required_seen:?}"
+ status_variants.len() >= 2,
+ "a lifecycle enum with fewer than two variants is a declaration bug: {status_variants:?}"
);
+ for (i, variant) in status_variants.iter().enumerate() {
+ let mut probe = card.clone();
+ probe.insert("status".to_string(), Value::String(variant.clone()));
+ probe.insert("id".to_string(), Value::String(format!("probe-{i}")));
+ let response = rpc(
+ &harness.rpc_base,
+ 70 + i as i64,
+ "openhuman.todos_replace",
+ json!({ "thread_id": thread, "cards": [Value::Object(probe)] }),
+ )
+ .await;
+ ok(
+ &response,
+ &format!("todos_replace with the declared status variant {variant:?}"),
+ );
+ }
let replaced = rpc(
&harness.rpc_base,
@@ -846,3 +921,69 @@ async fn todos_replace_accepts_a_card_built_only_from_its_declared_schema() {
harness.join.abort();
}
+
+/// A `#[serde(default)]` collection may be **omitted**, but not sent as `null`
+/// — and the catalog now says so (#6087).
+///
+/// `TaskBoardCard`'s `plan`, `allowedTools`, `acceptanceCriteria` and
+/// `evidence` are `Vec<String>`; `order` is `u32`; `updatedAt` is `String`.
+/// None is an `Option`, so `#[serde(default)]` covers an *absent* key and an
+/// explicit `null` fails with `invalid type: null`.
+///
+/// The first draft of this schema declared all six as `Option(...)`, which
+/// advertised `null` as valid and would have put the catalog straight back to
+/// describing a call the handler rejects — the exact defect #6087 removes.
+/// They are declared with their real types and `required: false` instead, and
+/// this pins both halves of that contract.
+#[tokio::test]
+async fn todos_replace_defaulted_card_fields_may_be_omitted_but_not_null() {
+ let _lock = env_lock();
+ let harness = setup(Vec::new()).await;
+ let thread = "todos-e2e-thread-defaults";
+
+ // Omitting every defaulted field is accepted — that is what the serde
+ // defaults are for, and what `required: false` advertises.
+ let omitted = rpc(
+ &harness.rpc_base,
+ 80,
+ "openhuman.todos_replace",
+ json!({
+ "thread_id": thread,
+ "cards": [{ "id": "", "title": "only the required trio", "status": "todo" }]
+ }),
+ )
+ .await;
+ let result = ok(&omitted, "todos_replace omitting every defaulted field");
+ assert_eq!(
+ card_titles(result, "omitted defaults"),
+ vec!["only the required trio".to_string()],
+ "a card carrying only the required trio must be accepted: {result:?}"
+ );
+
+ // An explicit null for a defaulted collection is refused. If the catalog
+ // ever goes back to declaring these `Option(...)`, it will be promising a
+ // shape this assertion proves the handler does not accept.
+ for field in ["plan", "allowedTools", "acceptanceCriteria", "evidence"] {
+ let mut card = serde_json::Map::new();
+ card.insert("id".into(), json!(""));
+ card.insert("title".into(), json!("null probe"));
+ card.insert("status".into(), json!("todo"));
+ card.insert(field.to_string(), Value::Null);
+
+ let response = rpc(
+ &harness.rpc_base,
+ 81,
+ "openhuman.todos_replace",
+ json!({ "thread_id": thread, "cards": [Value::Object(card)] }),
+ )
+ .await;
+ let message = error_message(&response, &format!("todos_replace with {field}: null"));
+ assert!(
+ message.contains("invalid type: null") || message.contains(field),
+ "an explicit null for the defaulted `{field}` must be refused, so the \
+ catalog must not advertise it as nullable; got: {message}"
+ );
+ }
+
+ harness.join.abort();
+}