Skip to content

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

feat(cron): add policy module for cron scheduling

Steven Enamakelf868a48a8311
diff --git a/crates/openhuman-core/src/cron/policy.rs b/crates/openhuman-core/src/cron/policy.rs
index f66803305d..217c87f562 100644
--- a/crates/openhuman-core/src/cron/policy.rs
+++ b/crates/openhuman-core/src/cron/policy.rs
@@ -23,9 +23,11 @@ pub use tinyflows_schedule::JobPolicy;
use crate::config::Config;
-/// Whether `error` is the store's "no such job".
-fn is_missing(error: &anyhow::Error) -> bool {
- format!("{error:#}").contains("not found")
+/// Whether `error` is the store's "no such job" for `job_id`: its exact
+/// outermost message, so a backend error that merely mentions "not found"
+/// (a missing collection, say) stays on the fail-closed path.
+fn is_missing(error: &anyhow::Error, job_id: &str) -> bool {
+ error.to_string() == format!("Cron job '{job_id}' not found")
}
/// The policy stored for `job_id`; the default when there is no such job.
@@ -36,7 +38,7 @@ fn is_missing(error: &anyhow::Error) -> bool {
pub fn get_policy(config: &Config, job_id: &str) -> Result<JobPolicy> {
match super::store::get_job(config, job_id) {
Ok(job) => Ok(job.policy),
- Err(error) if is_missing(&error) => Ok(JobPolicy::default()),
+ Err(error) if is_missing(&error, job_id) => Ok(JobPolicy::default()),
Err(_) => {
tracing::warn!(job_id, "[cron:policy] policy unreadable; refusing to run");
Err(anyhow::anyhow!(
@@ -68,7 +70,7 @@ pub fn set_policy(config: &Config, job_id: &str, policy: JobPolicy) -> Result<()
/// revert.
pub fn clear_policy(config: &Config, job_id: &str) -> Result<()> {
match set_policy(config, job_id, JobPolicy::default()) {
- Err(error) if is_missing(&error) => Ok(()),
+ Err(error) if is_missing(&error, job_id) => Ok(()),
other => other,
}
}
diff --git a/crates/openhuman-core/src/flows/tinyflows/README.md b/crates/openhuman-core/src/flows/tinyflows/README.md
index 5069ecc952..13f8a72a48 100644
--- a/crates/openhuman-core/src/flows/tinyflows/README.md
+++ b/crates/openhuman-core/src/flows/tinyflows/README.md
@@ -24,8 +24,8 @@ security model); this README covers only the host seam.
`shell` and `approvals` as `None` (no host shell adapter yet; approvals
reuse the engine's pause/`flows_resume` fallback).
- `ops.rs`: `build_capabilities` (assembles the `Capabilities` bundle for
- one run), `open_flow_checkpointer` (opens the durable SQLite checkpointer
- at `<workspace_dir>/flows/checkpoints.db`), Composio curation/preflight
+ one run), `open_flow_checkpointer` (a `DriverCheckpointer` on the flow
+ catalog's storage), Composio curation/preflight
(`is_curated_flow_tool`, `preflight_composio_args`), and the
`OpenHumanTools` / `PreflightToolInvoker` tool-call adapters.
- `agent.rs`: `OpenHumanAgentRunner` (`AgentRunner`): resolves an `agent`
diff --git a/crates/openhuman-core/src/storage/import/tinyflows.rs b/crates/openhuman-core/src/storage/import/tinyflows.rs
index 7265223137..de25844593 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows.rs
@@ -49,12 +49,14 @@ pub fn legacy_jobs_db(scope_dir: &Path) -> PathBuf {
/// Runs `body` unless the marker for `domain` says it already finished, then
/// records the marker. `body` returns `None` when there is nothing to import
/// (no marker is written then, so a file that appears later is still seen) and
-/// otherwise `(found, written)`.
+/// otherwise `(found, written, skipped)`. A run that skipped records writes no
+/// marker, so the import is retried at the next boot once the operator has
+/// repaired them (records already written are counted, not duplicated).
fn marked(
backend: &Arc<dyn StorageBackend>,
workspace: &Path,
domain: &str,
- body: impl FnOnce() -> Result<Option<(usize, usize)>>,
+ body: impl FnOnce() -> Result<Option<(usize, usize, usize)>>,
) -> Result<Outcome> {
let marker = marker_id(domain, workspace);
let markers = Repo::on(backend, &Scope::local(), "storage::import", marker_spec)?;
@@ -65,9 +67,18 @@ fn marked(
if done {
return Ok(Outcome::AlreadyDone);
}
- let Some((found, written)) = body()? else {
+ let Some((found, written, skipped)) = body()? else {
return Ok(Outcome::NoSource);
};
+ if skipped > 0 {
+ tracing::warn!(
+ target: "openhuman::storage_import",
+ domain,
+ skipped,
+ "[storage::import] legacy records were skipped; the import stays open for retry"
+ );
+ return Ok(Outcome::Imported { found, written });
+ }
let body = json!({
"version": MARKER_VERSION,
"domain": domain,
@@ -89,10 +100,10 @@ fn marked(
Ok(Outcome::Imported { found, written })
}
-/// `(found, written)` of a `tinyflows-import` report; problems are logged by
+/// `(found, written, skipped)` of a `tinyflows-import` report; problems are logged by
/// id only, never with record content.
#[cfg(feature = "flows")]
-fn counts(domain: &str, report: &tinyflows_import::ImportReport) -> (usize, usize) {
+fn counts(domain: &str, report: &tinyflows_import::ImportReport) -> (usize, usize, usize) {
for problem in report.problems() {
tracing::warn!(
target: "openhuman::storage_import",
@@ -105,7 +116,8 @@ fn counts(domain: &str, report: &tinyflows_import::ImportReport) -> (usize, usiz
.kinds()
.map(|(_, tally)| tally.written + tally.existing + tally.invalid)
.sum();
- (found, report.total_written())
+ let skipped = report.kinds().map(|(_, tally)| tally.invalid).sum();
+ (found, report.total_written(), skipped)
}
/// Copies the flow catalog and its checkpoints from `<workspace>/flows` into
@@ -152,9 +164,13 @@ pub fn import_flows(
Ok((catalog_report, checkpoint_report))
}
})?;
- let (found_a, written_a) = counts(FLOWS_DOMAIN, &catalog_report);
- let (found_b, written_b) = counts(FLOWS_DOMAIN, &checkpoint_report);
- Ok(Some((found_a + found_b, written_a + written_b)))
+ let (found_a, written_a, skipped_a) = counts(FLOWS_DOMAIN, &catalog_report);
+ let (found_b, written_b, skipped_b) = counts(FLOWS_DOMAIN, &checkpoint_report);
+ Ok(Some((
+ found_a + found_b,
+ written_a + written_b,
+ skipped_a + skipped_b,
+ )))
})
}
diff --git a/crates/openhuman-core/src/storage/local.rs b/crates/openhuman-core/src/storage/local.rs
index 43f8159e43..f672f90772 100644
--- a/crates/openhuman-core/src/storage/local.rs
+++ b/crates/openhuman-core/src/storage/local.rs
@@ -360,7 +360,12 @@ fn open_standing_local(
Some(backend) => Arc::clone(backend),
None => {
let dir = db_path.with_extension("files");
- let url = format!("file:{}", dir.display());
+ let Some(dir_str) = dir.to_str() else {
+ return Err(anyhow!(
+ "[{domain}] the store path is not valid UTF-8 and cannot be named by a file: URL"
+ ));
+ };
+ let url = format!("file:{dir_str}");
let backend = super::block_on_anyhow(async move { Ok(super::open(&url).await?) })
.with_context(|| format!("[{domain}] open {}", dir.display()))?;
import(&backend, &Scope::local(), config).with_context(|| {
diff --git a/docs/gitbooks/en/developing/architecture/storage.md b/docs/gitbooks/en/developing/architecture/storage.md
index 56abbc5882..1ab02be65d 100644
--- a/docs/gitbooks/en/developing/architecture/storage.md
+++ b/docs/gitbooks/en/developing/architecture/storage.md
@@ -78,7 +78,7 @@ On a shared backend (MongoDB) other processes may write the same records, so boo
| `file:<dir>` | `<dir>/scopes/<scope>/docs/<collection>/<id>.json` for documents, with collection metadata in `<dir>/_meta/collections/<collection>.json`. Streams are JSONL and blobs are raw files under the same scope directory. |
| `mongodb://…/<db>` | One database. Each named database is a collection prefix, and every record carries its scope. |
-Without a URL, the classic layout is unchanged: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Records written to a configured backend are not copied back to those files. The domain stores do not import their files either, with one exception: credentials. On first read with a backend installed, the auth-profile and HTTP-credential stores copy the records in their files into the backend, and the keyring adopts a secret it finds in the process backend. The source files are left untouched.
+Without a URL, the classic layout holds for the other domains: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Cron jobs and the flow catalog are the exception: they live in the document databases `cron/schedule.db` and `flows/catalog.db`, beside the retained legacy `cron/jobs.db`, `flows/flows.db` and `flows/checkpoints.db`, which are no longer read after the one-time import. Records written to a configured backend are not copied back to those files. The domain stores do not import their files either, with one exception: credentials. On first read with a backend installed, the auth-profile and HTTP-credential stores copy the records in their files into the backend, and the keyring adopts a secret it finds in the process backend. The source files are left untouched.
Secrets with a backend installed are encrypted documents in the current storage scope: the acting agent's scope on a desktop or CLI host, and the profile's scope under SaaS, where every agent in one profile shares the profile's credentials and data key. Each scope's data key is derived with HKDF-SHA256 from the keyring master key (`OPENHUMAN_KEYRING_MASTER_KEY` or `_FILE`, else the OS keychain), and with no master key they fail closed. The config encryption key stays on the process keyring because `config.toml` is loaded before any agent acts.
diff --git a/gitbooks/developing/architecture/storage.md b/gitbooks/developing/architecture/storage.md
index fdad9905a6..c61ffa402b 100644
--- a/gitbooks/developing/architecture/storage.md
+++ b/gitbooks/developing/architecture/storage.md
@@ -103,7 +103,7 @@ On a shared backend (MongoDB) other processes may write the same records, so boo
| `file:<dir>` | `<dir>/scopes/<scope>/docs/<collection>/<id>.json` for documents, with collection metadata in `<dir>/_meta/collections/<collection>.json`. Streams are JSONL and blobs are raw files under the same scope directory. |
| `mongodb://…/<db>` | One database. Each named database is a collection prefix, and every record carries its scope. |
-Without a URL, the classic layout is unchanged: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Records written to a configured backend are not copied back to those files. On first read with a backend installed, the auth-profile and HTTP-credential stores copy the records in their files into the backend, and the keyring adopts a secret it finds in the process backend. The source files are left untouched.
+Without a URL, the classic layout holds for the other domains: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Cron jobs and the flow catalog are the exception: they live in the document databases `cron/schedule.db` and `flows/catalog.db`, beside the retained legacy `cron/jobs.db`, `flows/flows.db` and `flows/checkpoints.db`, which are no longer read after the one-time import. Records written to a configured backend are not copied back to those files. On first read with a backend installed, the auth-profile and HTTP-credential stores copy the records in their files into the backend, and the keyring adopts a secret it finds in the process backend. The source files are left untouched.
### Importing the legacy small stores