Skip to content

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

fix(todos): declare the real card shape on todos_replace's schema\n\n`todos.replace` declared exactly one input — `cards: TypeSchema::Json`,\ncommented "Array of card objects (id may be empty — server generates)" —\nand named no field of a card anywhere in the controller catalog. A caller\nreading the schema could not construct a card that the handler accepts.\n\n`handle_replace` deserializes each entry into `TaskBoardCard`, whose `id`,\n`title` and `status` carry no `#[serde(default)]`, so all three keys are\nmandatory. Two things the old declaration got actively wrong:\n\n * "id may be empty" is true of the *string* and false of the *key* —\n omitting it fails with ``missing field `id` ``;\n * the text field is `title`, while the sibling `todos.add` / `todos.edit`\n inputs in the same namespace call the identical field `content`, so a\n caller reaching for the namespace's own vocabulary got\n ``missing field `title` ``.\n\nSchema-side only, as the issue's fix shape specifies. The wire is\nuntouched: renaming `TaskBoardCard::title` would cross the vendored\n`tinyagents-graph` boundary and break the frontend's `title` reader at\n`app/src/types/turnState.ts:26`. `todos_replace` has no frontend caller,\nso this is inert at runtime by construction.\n\nThe declaration now spells the mandatory trio plus all fourteen optional\nfields, using the **wire** names — `TaskBoardCard` is\n`#[serde(rename_all = "camelCase")]` and `TaskCardStatus` is\n`#[serde(rename_all = "snake_case")]`, so it reads `assignedAgent` and\n`in_progress`, not `assigned_agent` / `inProgress`.\n\nThe regression test constructs its card *from the declared schema* rather\nthan hard-coding one: it reads `/schema`, populates every field marked\nrequired, and takes `status` from the declared enum's own variant list. It\ntherefore cannot pass by accident — if the schema names a field the handler\nwill not deserialize, or offers a status variant `TaskCardStatus` cannot\nparse, the dispatch fails.\n\nFault injected to prove it bites: reverted `cards` to `TypeSchema::Json`.\nThe suite failed with\n\n `cards` must declare an array of objects with named fields; an opaque\n type cannot be built from. Got ty = "Json"\n\nat `tests/raw_coverage/todos_lifecycle_e2e.rs:768`. Restored, 5/5 green.\n\nThe neighbouring `todos_replace_rejects_the_card_shape_its_own_schema_implies`\nkeeps its three refusals — they are the handler's behaviour and are\nunchanged — but its doc comment is refreshed, since the catalog no longer\n"names no field of a card anywhere".\n\nCloses #6087\n

M3gA-Mind887922c68d4e
diff --git a/src/openhuman/threads/todos/schemas_part_01.rs b/src/openhuman/threads/todos/schemas_part_01.rs
index dfeee31e0a..ae1b393593 100644
--- a/src/openhuman/threads/todos/schemas_part_01.rs
+++ b/src/openhuman/threads/todos/schemas_part_01.rs
@@ -236,15 +236,7 @@ pub fn schemas(function: &str) -> ControllerSchema {
namespace: "todos",
function: "replace",
description: "Wholesale-replace the todo list for a thread.",
- inputs: vec![
- thread_id_input(),
- FieldSchema {
- name: "cards",
- ty: TypeSchema::Json,
- comment: "Array of card objects (id may be empty — server generates).",
- required: true,
- },
- ],
+ inputs: vec![thread_id_input(), replace_cards_input()],
outputs: vec![snapshot_output()],
},
"clear" => ControllerSchema {
diff --git a/src/openhuman/threads/todos/schemas_part_02.rs b/src/openhuman/threads/todos/schemas_part_02.rs
index 9d575605d9..211b8233d8 100644
--- a/src/openhuman/threads/todos/schemas_part_02.rs
+++ b/src/openhuman/threads/todos/schemas_part_02.rs
@@ -1,4 +1,3 @@
-
fn handle_reclaim_stale(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let p = parse::<ReclaimStaleParams>(params)?;
@@ -82,6 +81,102 @@ fn string_array_input(name: &'static str, comment: &'static str) -> FieldSchema
}
}
+/// The `cards` input of `todos.replace`, spelled out field by field.
+///
+/// This was a bare `TypeSchema::Json` commented "Array of card objects (id may
+/// be empty — server generates)", which is not enough to construct one and was
+/// actively misleading in two ways (#6087):
+///
+/// * `handle_replace` deserializes each entry into `TaskBoardCard`, whose
+/// `id`, `title` and `status` carry **no** `#[serde(default)]` — so all
+/// three keys are mandatory. "id may be empty" is true of the *string* and
+/// false of the *key*: omitting it fails with ``missing field `id` ``.
+/// * the text field is `title`, while the sibling `todos.add` / `todos.edit`
+/// inputs in this same namespace call it `content`. A caller who reached for
+/// the namespace's own vocabulary got ``missing field `title` ``.
+///
+/// Names below are the wire names: `TaskBoardCard` is
+/// `#[serde(rename_all = "camelCase")]` and `TaskCardStatus` is
+/// `#[serde(rename_all = "snake_case")]`, so the declaration must use
+/// `assignedAgent` (not `assigned_agent`) and `in_progress` (not `inProgress`).
+/// Every optional field carries `#[serde(default)]` upstream, so the optional
+/// markings here are load-bearing rather than decorative.
+fn replace_cards_input() -> FieldSchema {
+ FieldSchema {
+ name: "cards",
+ ty: TypeSchema::Array(Box::new(TypeSchema::Object {
+ fields: vec![
+ FieldSchema {
+ name: "id",
+ ty: TypeSchema::String,
+ comment: "Stable card id (`task-<n>`). The KEY is required; \
+ pass an empty string to have the server generate one.",
+ required: true,
+ },
+ FieldSchema {
+ name: "title",
+ ty: TypeSchema::String,
+ comment: "One-line title. NOTE: `todos.add` / `todos.edit` \
+ call this same field `content`; here it is `title`.",
+ required: true,
+ },
+ FieldSchema {
+ name: "status",
+ ty: TypeSchema::Enum {
+ variants: vec![
+ "todo",
+ "awaiting_approval",
+ "ready",
+ "in_progress",
+ "blocked",
+ "done",
+ "rejected",
+ ],
+ },
+ comment: "Lifecycle state. At most one card may be `in_progress`.",
+ required: true,
+ },
+ optional_string("objective", "Richer objective for the card."),
+ string_array_input("plan", "Ordered plan steps."),
+ optional_string("assignedAgent", "Agent assigned to run this card."),
+ string_array_input("allowedTools", "Tools the assigned agent may use."),
+ optional_string(
+ "approvalMode",
+ "Plan-approval mode, when the card is gated.",
+ ),
+ string_array_input(
+ "acceptanceCriteria",
+ "Acceptance criteria that define \"done\".",
+ ),
+ string_array_input("evidence", "Evidence gathered toward completion."),
+ optional_string("notes", "Free-form notes."),
+ optional_string("blocker", "Reason, when `status == blocked`."),
+ optional_string(
+ "sessionThreadId",
+ "Thread the card's own agent session runs in.",
+ ),
+ FieldSchema {
+ name: "sourceMetadata",
+ ty: TypeSchema::Option(Box::new(TypeSchema::Json)),
+ 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."),
+ ],
+ })),
+ comment: "Full replacement list. Each entry MUST carry `id`, `title` and \
+ `status`; every other field is optional. Note `title`, not \
+ `content` — see the field comments.",
+ required: true,
+ }
+}
+
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 173908633e..18f42694f8 100644
--- a/tests/raw_coverage/todos_lifecycle_e2e.rs
+++ b/tests/raw_coverage/todos_lifecycle_e2e.rs
@@ -220,6 +220,29 @@ async fn rpc(base: &str, id: i64, method: &str, params: Value) -> Value {
.unwrap_or_else(|err| panic!("json for {method}: {err}"))
}
+/// The `/schema` controller catalog, as the frontend and the CLI/RPC
+/// smoke-test generator consume it.
+async fn schema_catalog(base: &str) -> Value {
+ let url = format!("{}/schema", base.trim_end_matches('/'));
+ reqwest::get(&url)
+ .await
+ .unwrap_or_else(|err| panic!("GET {url}: {err}"))
+ .json::<Value>()
+ .await
+ .unwrap_or_else(|err| panic!("schema json: {err}"))
+}
+
+/// One method's declared entry from the catalog.
+fn catalog_entry<'a>(catalog: &'a Value, method: &str) -> &'a Value {
+ catalog
+ .get("methods")
+ .and_then(Value::as_array)
+ .unwrap_or_else(|| panic!("catalog has no methods array: {catalog}"))
+ .iter()
+ .find(|m| m.get("method").and_then(Value::as_str) == Some(method))
+ .unwrap_or_else(|| panic!("catalog does not advertise {method}"))
+}
+
fn ok<'a>(value: &'a Value, context: &str) -> &'a Value {
if let Some(error) = value.get("error") {
panic!("{context}: unexpected JSON-RPC error: {error}");
@@ -612,26 +635,26 @@ async fn todos_run_records_and_reclaim_report_an_honest_empty_state() {
harness.join.abort();
}
-/// `todos_replace`'s declared contract cannot be satisfied from the schema.
+/// `todos_replace` refuses a card missing any of the mandatory trio.
///
-/// The controller catalog declares one input — `cards: Json`, commented
-/// *"Array of card objects (id may be empty — server generates)"* — and names
-/// no field of a card anywhere. The handler deserializes each entry into
-/// `TaskBoardCard`, whose `id`, `title` and `status` all lack
-/// `#[serde(default)]`, so every one of them must be **present**. Two
-/// consequences a caller reading the schema walks straight into, both pinned
-/// below:
+/// These three refusals are the *handler's* behaviour and are unchanged by
+/// #6087, which corrected the schema rather than the handler. What changed is
+/// that they are now **documented**: the catalog spells `id`, `title` and
+/// `status` as required (see `replace_cards_input`), so a caller can no longer
+/// walk into them by reading the schema. They are pinned here because the
+/// refusals themselves are the contract — `TaskBoardCard`'s `id`, `title` and
+/// `status` carry no `#[serde(default)]`, so every one of them must be
+/// **present**. Two consequences, both pinned below:
///
/// 1. The obvious spelling — `content`, which is what the sibling `todos_add`
/// and `todos_edit` inputs call the very same text — is rejected outright.
/// 2. "id may be empty" is about the string, not the key: omitting `status`
/// fails even with a well-formed title.
///
-/// This is a documentation defect in the schema, not behaviour to change here.
-/// See `~/tinyhuman/bugs/e2e-wave-todos-replace-undocumented-card-shape.md`.
-/// The assertions are written against what the code *does*, so the day the
-/// schema and the handler are reconciled this case fails and gets updated
-/// deliberately rather than silently drifting.
+/// The assertions are written against what the code *does*. The companion
+/// case `todos_replace_accepts_a_card_built_only_from_its_declared_schema`
+/// proves the other half: that the catalog now carries enough to build a card
+/// that these refusals let through.
#[tokio::test]
async fn todos_replace_rejects_the_card_shape_its_own_schema_implies() {
let _lock = env_lock();
@@ -703,3 +726,123 @@ async fn todos_replace_rejects_the_card_shape_its_own_schema_implies() {
harness.join.abort();
}
+
+/// A card built **only** from what the catalog declares is accepted (#6087).
+///
+/// This is the regression test for the schema defect, and it is deliberately
+/// written so that it cannot pass by accident. Rather than hard-coding a card
+/// that happens to work, it *reads the declared schema* and constructs the card
+/// from it: every field the catalog marks `required` is populated, and the
+/// `status` value is taken from the declared enum's own variant list. If the
+/// declaration goes back to a bare `TypeSchema::Json`, or names a field the
+/// handler does not deserialize, or spells `title` as `content`, or offers a
+/// `status` variant `TaskCardStatus` will not parse, this fails — because the
+/// card it builds is only ever as correct as the schema it read.
+#[tokio::test]
+async fn todos_replace_accepts_a_card_built_only_from_its_declared_schema() {
+ let _lock = env_lock();
+ let harness = setup(Vec::new()).await;
+ let thread = "todos-e2e-thread-from-schema";
+
+ let catalog = schema_catalog(&harness.rpc_base).await;
+ let entry = catalog_entry(&catalog, "openhuman.todos_replace");
+
+ let cards_input = entry
+ .get("inputs")
+ .and_then(Value::as_array)
+ .unwrap_or_else(|| panic!("todos_replace declares no inputs: {entry}"))
+ .iter()
+ .find(|i| i.get("name").and_then(Value::as_str) == Some("cards"))
+ .unwrap_or_else(|| panic!("todos_replace declares no `cards` input: {entry}"));
+
+ // The declaration must describe an array of objects, not an opaque blob.
+ // `TypeSchema::Json` serialises as the bare string "Json", which is exactly
+ // what this controller used to publish and what made it unconstructible.
+ let card_fields = cards_input
+ .get("ty")
+ .and_then(|t| t.get("Array"))
+ .and_then(|a| a.get("Object"))
+ .and_then(|o| o.get("fields"))
+ .and_then(Value::as_array)
+ .unwrap_or_else(|| {
+ panic!(
+ "`cards` must declare an array of objects with named fields; \
+ an opaque type cannot be built from. Got ty = {}",
+ cards_input.get("ty").unwrap_or(&Value::Null)
+ )
+ });
+
+ // Build a card from the declaration alone.
+ let mut card = serde_json::Map::new();
+ let mut required_seen: Vec<String> = Vec::new();
+ for field in card_fields {
+ if field.get("required").and_then(Value::as_bool) != Some(true) {
+ continue;
+ }
+ let name = field
+ .get("name")
+ .and_then(Value::as_str)
+ .unwrap_or_else(|| panic!("declared field without a name: {field}"))
+ .to_string();
+ let ty = field.get("ty").unwrap_or(&Value::Null);
+ let value = if let Some(variants) = ty.get("Enum").and_then(|e| e.get("variants")) {
+ // Take the enum's own first variant — if the schema advertises a
+ // value the wire type cannot parse, the dispatch below fails.
+ variants
+ .as_array()
+ .and_then(|v| v.first())
+ .cloned()
+ .unwrap_or_else(|| panic!("declared enum with no variants: {field}"))
+ } else if name == "id" {
+ // The one documented special case: the key is required, the string
+ // may be empty, and the server then generates the id.
+ Value::String(String::new())
+ } else {
+ Value::String(format!("built from the schema: {name}"))
+ };
+ required_seen.push(name.clone());
+ card.insert(name, value);
+ }
+
+ 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:?}"
+ );
+
+ let replaced = rpc(
+ &harness.rpc_base,
+ 60,
+ "openhuman.todos_replace",
+ json!({ "thread_id": thread, "cards": [Value::Object(card)] }),
+ )
+ .await;
+ let result = ok(
+ &replaced,
+ "todos_replace with a card built from its own schema",
+ );
+
+ // It was accepted AND stored — a schema that merely deserializes but drops
+ // the card would be no better than the old one.
+ let titles = card_titles(result, "replace built from schema");
+ assert_eq!(
+ titles,
+ vec!["built from the schema: title".to_string()],
+ "the card built from the declared schema must land on the board: {result:?}"
+ );
+
+ // The server generated an id for the empty one, as the comment promises.
+ let stored = cards(result, "replace built from schema");
+ let id = stored[0]
+ .get("id")
+ .and_then(Value::as_str)
+ .unwrap_or_else(|| panic!("stored card carries no id: {stored:?}"));
+ assert!(
+ !id.is_empty(),
+ "an empty `id` must be server-generated, got an empty string back"
+ );
+
+ harness.join.abort();
+}