The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(cron): declare cron_run's real output shape
Shanu141ec1e314f7
diff --git a/src/openhuman/cron/ops_tests.rs b/src/openhuman/cron/ops_tests.rsindex 63b1e3327d..a865fb5639 100644--- a/src/openhuman/cron/ops_tests.rs+++ b/src/openhuman/cron/ops_tests.rs@@ -457,6 +457,60 @@ async fn cron_run_returns_queued_immediately_for_valid_job() {assert!(out.logs.iter().any(|l| l.contains("enqueued")));}+/// Guards the divergence reported in #6070: the controller schema declared+/// `status: ok|error` plus `duration_ms` and `output`, none of which the+/// handler can produce. Nothing validates a controller's *outputs* at runtime+/// (`validate_params` covers inputs only), so a mismatch is silent — it only+/// shows up in a generated client, the `/schema` catalog or the tool registry.+/// This asserts the two against each other so drift on either side fails here.+#[tokio::test]+async fn cron_run_response_conforms_to_its_declared_schema() {+ use crate::core::TypeSchema;+ use crate::openhuman::cron::cron_schemas;++ let tmp = TempDir::new().unwrap();+ let config = test_config(&tmp);+ let job = make_job(&config, "*/5 * * * *", None, "echo hello");++ let out = cron_run(&config, &job.id).await.unwrap();+ let result = out.value.as_object().expect("result payload is an object");++ let schema = cron_schemas("run");+ let TypeSchema::Object { fields } = &schema.outputs[0].ty else {+ panic!("cron_run must declare an object result");+ };++ for field in fields.iter().filter(|f| f.required) {+ assert!(+ result.contains_key(field.name),+ "schema declares required field '{}' that cron_run never returns; got {:?}",+ field.name,+ result.keys().collect::<Vec<_>>()+ );+ }++ for key in result.keys() {+ assert!(+ fields.iter().any(|f| f.name == key),+ "cron_run returns '{key}' but the schema does not declare it"+ );+ }++ for field in fields {+ let TypeSchema::Enum { variants } = &field.ty else {+ continue;+ };+ let Some(value) = result.get(field.name).and_then(|v| v.as_str()) else {+ continue;+ };+ assert!(+ variants.contains(&value),+ "cron_run returned '{value}' for '{}', not among the declared variants {variants:?}",+ field.name+ );+ }+}+#[tokio::test]async fn cron_run_rejects_duplicate_concurrent_execution() {let tmp = TempDir::new().unwrap();diff --git a/src/openhuman/cron/schemas.rs b/src/openhuman/cron/schemas.rsindex 8759c240fb..8557593110 100644--- a/src/openhuman/cron/schemas.rs+++ b/src/openhuman/cron/schemas.rs@@ -201,10 +201,17 @@ pub fn schemas(function: &str) -> ControllerSchema {required: true,}],},+ // The handler enqueues the execution on a background task and returns+ // as soon as the job is queued, so the declared output describes the+ // enqueue acknowledgement — not the terminal outcome. Declaring+ // `ok`/`error`, `duration_ms` or `output` here would promise a shape+ // this controller cannot produce; those live in `cron_runs`."run" => ControllerSchema {namespace: "cron",function: "run",- description: "Run a cron job immediately and record run metadata.",+ description: "Enqueue a cron job for immediate background execution and return once it \+ is queued. The terminal outcome (ok/error, duration, output) is recorded \+ in the run history — read it with `cron_runs`.",inputs: vec![job_id_input("Identifier of the cron job to execute immediately.",)],@@ -215,32 +222,21 @@ pub fn schemas(function: &str) -> ControllerSchema {FieldSchema {name: "job_id",ty: TypeSchema::String,- comment: "Executed cron job identifier.",+ comment: "Enqueued cron job identifier.",required: true,},FieldSchema {name: "status",ty: TypeSchema::Enum {- variants: vec!["ok", "error"],+ variants: vec!["queued"],},- comment: "Execution status.",- required: true,- },- FieldSchema {- name: "duration_ms",- ty: TypeSchema::I64,- comment: "Execution duration in milliseconds.",- required: true,- },- FieldSchema {- name: "output",- ty: TypeSchema::String,- comment: "Captured command output (possibly truncated).",+ comment: "Always \"queued\" — the job runs in the background; poll \+ `cron_runs` for the terminal status.",required: true,},],},- comment: "Immediate execution result payload.",+ comment: "Enqueue acknowledgement payload.",required: true,}],},diff --git a/src/openhuman/cron/schemas_tests.rs b/src/openhuman/cron/schemas_tests.rsindex 43e5df049e..e265a59dd8 100644--- a/src/openhuman/cron/schemas_tests.rs+++ b/src/openhuman/cron/schemas_tests.rs@@ -31,18 +31,34 @@ fn schemas_remove_has_job_id_input_and_result_output() {}#[test]-fn schemas_run_result_contains_status_and_duration_fields() {+fn schemas_run_result_declares_only_the_enqueue_acknowledgement() {let s = schemas("run");- // Status is an enum with ok/error — clients rely on this shape.- if let TypeSchema::Object { fields } = &s.outputs[0].ty {- let names: Vec<_> = fields.iter().map(|f| f.name).collect();- assert!(names.contains(&"status"));- assert!(names.contains(&"duration_ms"));- assert!(names.contains(&"output"));- assert!(names.contains(&"job_id"));- } else {+ // `cron_run` spawns the execution and returns immediately, so the declared+ // output is the enqueue acknowledgement — `job_id` plus a `status` that is+ // always "queued". `duration_ms` / `output` belong to the terminal record+ // in `cron_runs` and must not be promised here.+ let TypeSchema::Object { fields } = &s.outputs[0].ty else {panic!("expected object output type");- }+ };+ let names: Vec<_> = fields.iter().map(|f| f.name).collect();+ assert_eq!(names, vec!["job_id", "status"]);++ let status = fields.iter().find(|f| f.name == "status").unwrap();+ assert!(+ matches!(&status.ty, TypeSchema::Enum { variants } if variants.as_slice() == ["queued"]),+ "status must declare exactly the variant the handler emits, got {:?}",+ status.ty+ );+}++#[test]+fn schemas_run_description_points_at_cron_runs_for_the_terminal_record() {+ let s = schemas("run");+ assert!(+ s.description.contains("cron_runs"),+ "the description must tell a client where the terminal outcome lives, got: {}",+ s.description+ );}#[test]