Skip to content

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

fix(cron): run schema migration before starting scheduler

Steven Enamakeladb0e3c03d78
diff --git a/crates/openhuman-core/src/cron/client.rs b/crates/openhuman-core/src/cron/client.rs
index 04fb5eaa3d..69a6a28b09 100644
--- a/crates/openhuman-core/src/cron/client.rs
+++ b/crates/openhuman-core/src/cron/client.rs
@@ -1,7 +1,7 @@
//! Typed calls to the `tinyflows` module's `Schedule` object.
//!
//! The scheduler runtime, the cron job and run store and the schedule maths
-//! all run in the module (`tinyflows_bus::schedule`, contract v3). This file is
+//! all run in the module (`tinyflows_bus::schedule`, contract v6). This file is
//! the only place core builds those requests: it turns a [`Config`] and a
//! [`StoreOperation`] into a `ScheduleStore` request bound to the acting
//! scope's document port ([`super::documents_port`]), and wraps every pure
@@ -9,8 +9,10 @@
//! function. Members are named through the contract constants; nothing here
//! parses a cron expression or computes a next run.
//!
-//! Every call logs `[cron:bus]` with the member (never a payload) so a failing
-//! call is greppable.
+//! Every store operation first asks the module to perform its idempotent,
+//! module-owned migration. Direct scheduler lifecycle entry points must do the
+//! same before bypassing this store wrapper. Every call logs `[cron:bus]` with
+//! the member (never a payload) so a failing call is greppable.
use anyhow::{anyhow, Result};
use chrono::{DateTime, Duration, Utc};
diff --git a/crates/openhuman-core/src/cron/scheduler/dispatcher.rs b/crates/openhuman-core/src/cron/scheduler/dispatcher.rs
index afd91d288a..d765d83dd2 100644
--- a/crates/openhuman-core/src/cron/scheduler/dispatcher.rs
+++ b/crates/openhuman-core/src/cron/scheduler/dispatcher.rs
@@ -214,6 +214,15 @@ impl JobDispatcher {
.binding
.within(async { DocScope::current(config) })
.await?;
+ // StartScheduler bypasses the ScheduleStore wrapper in client.rs.
+ // Run the module-owned schema migration on its exact document scope
+ // before the first scheduler request can observe or claim jobs.
+ let _: serde_json::Value = crate::cron::client::store_in(
+ config,
+ &scope,
+ tinyflows_bus::schedule::StoreOperation::Migrate,
+ )
+ .await?;
let storage = StoreConfig {
backend: StoreBackend::Documents {
callback: crate::cron::documents_port::address(&scope).await?,