Skip to content

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

refactor(migrations): update migration runner behavior and add tests

Steven Enamakeleb4702857e21
diff --git a/crates/openhuman-core/src/config/migrations/README.md b/crates/openhuman-core/src/config/migrations/README.md
index 6e06878ab3..bf1b06bbac 100644
--- a/crates/openhuman-core/src/config/migrations/README.md
+++ b/crates/openhuman-core/src/config/migrations/README.md
@@ -1,12 +1,12 @@
# migrations
-Startup data-migration runner gated by `Config::schema_version`. Each migration is a one-shot, idempotent transformation of on-disk data (the persisted `config.toml` and session transcripts). The runner, `run_pending`, is invoked from `Config::load_or_init` and is a fast no-op for workspaces whose `schema_version` already matches `CURRENT_SCHEMA_VERSION`. Failures are logged but never block startup; the next launch retries from the same starting version.
+Startup data-migration runner gated by `Config::schema_version`. Each migration is a one-shot, idempotent transformation of on-disk data (the persisted `config.toml` and session transcripts). The runner, `run_pending`, is invoked from `Config::load_or_init`; schema steps are skipped for current configs, but registered host normalizers still run on every load. Failures are logged but never block startup; schema steps retry from the same starting version on the next launch.
> Not to be confused with the sibling `crates/openhuman-core/src/config/migration_helpers/` (singular), which is a **user-triggered RPC** (`migrate.openclaw` / `migrate.hermes`) that imports memory from another assistant's workspace. This module (`migrations`, plural) is the **automatic schema-version runner** that fires once per workspace on the first launch of a new build.
## Responsibilities
-- Maintain `CURRENT_SCHEMA_VERSION` (currently `11`) as the target schema version, bumped alongside every new migration.
+- Maintain `CURRENT_SCHEMA_VERSION` (currently `14`) as the target schema version, bumped alongside every new migration.
- Run pending migrations in order, each guarded by an exact `schema_version ==` check so a failed earlier step is never skipped (the 0→1 step uses `< 1`).
- Run registered host config normalization for brand-new and already-versioned configs; bare core has no provider normalizer.
- Persist each version bump via `Config::save()` **only after** the migration reports success; on a save failure, roll the in-memory `schema_version` back so the next launch retries the same gate.
diff --git a/crates/openhuman-core/src/config/migrations/config_normalizer_tests.rs b/crates/openhuman-core/src/config/migrations/config_normalizer_tests.rs
index 6b8c678d6d..7b627da626 100644
--- a/crates/openhuman-core/src/config/migrations/config_normalizer_tests.rs
+++ b/crates/openhuman-core/src/config/migrations/config_normalizer_tests.rs
@@ -31,3 +31,36 @@ async fn registered_normalizer_runs_at_current_schema_and_retries_failed_save()
let on_disk = fs::read_to_string(&config.config_path).unwrap();
assert!(on_disk.contains("normalized-value"));
}
+
+#[tokio::test]
+async fn recovered_current_config_is_normalized_in_memory_without_persisting() {
+ let tmp = TempDir::new().unwrap();
+ fs::create_dir_all(tmp.path().join("workspace")).unwrap();
+ let mut config = config_in(&tmp);
+ config.schema_version = CURRENT_SCHEMA_VERSION;
+ config.default_model = Some("recover-me".to_string());
+ config.save().await.unwrap();
+ config.recovered_from_corruption = true;
+
+ crate::inference::registry::register_config_normalizer(
+ "recovered-migration-test",
+ std::sync::Arc::new(|config| {
+ if config.default_model.as_deref() == Some("recover-me") {
+ config.default_model = Some("recovered-normalized".to_string());
+ true
+ } else {
+ false
+ }
+ }),
+ );
+
+ run_pending(&mut config).await;
+
+ assert_eq!(
+ config.default_model.as_deref(),
+ Some("recovered-normalized")
+ );
+ let on_disk = fs::read_to_string(&config.config_path).unwrap();
+ assert!(on_disk.contains("recover-me"));
+ assert!(!on_disk.contains("recovered-normalized"));
+}
diff --git a/crates/openhuman-core/src/config/migrations/mod.rs b/crates/openhuman-core/src/config/migrations/mod.rs
index 6398b6f03e..52f11d3d28 100644
--- a/crates/openhuman-core/src/config/migrations/mod.rs
+++ b/crates/openhuman-core/src/config/migrations/mod.rs
@@ -2,9 +2,9 @@
//!
//! Each migration is a one-shot, idempotent transformation of on-disk
//! data. The runner is invoked from [`Config::load_or_init`] and is a
-//! fast no-op for workspaces whose `schema_version` already matches
-//! [`CURRENT_SCHEMA_VERSION`]. Failures are logged but never block
-//! startup — the next launch retries.
+//! schema steps are a fast no-op for current workspaces; registered host
+//! normalizers still run regardless of version. Failures are logged but never
+//! block startup — the next launch retries.
//!
//! ## Adding a new migration
//!
@@ -56,17 +56,15 @@ pub async fn run_pending(config: &mut Config) {
// Provider-owned normalization is independent of the schema version. It
// must still run when an unhosted core already advanced the generic schema,
// so a later hosted boot can repair provider-specific legacy values.
- if !config.recovered_from_corruption {
- let before_normalization = config.clone();
- if crate::inference::registry::normalize_config(config) {
- if let Err(err) = config.save().await {
- *config = before_normalization;
- log::warn!(
- "[migrations] provider config normalization ran but config.save failed: \
- {err:#} — restored the in-memory config; it will retry on next launch"
- );
- return;
- }
+ let before_normalization = config.clone();
+ if crate::inference::registry::normalize_config(config) && !config.recovered_from_corruption {
+ if let Err(err) = config.save().await {
+ *config = before_normalization;
+ log::warn!(
+ "[migrations] provider config normalization ran but config.save failed: \
+ {err:#} — restored the in-memory config; it will retry on next launch"
+ );
+ return;
}
}
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index 7c90fe24f6..79e9c6db32 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -114,7 +114,7 @@ pub(super) async fn run_agent_job_for_run(
model = %m,
"[cron] resolved Hint via workload factory"
);
- m
+ Some(m)
}
Err(e) => {
tracing::warn!(
diff --git a/crates/openhuman-core/src/inference/model_context.rs b/crates/openhuman-core/src/inference/model_context.rs
index 5862b19b0c..d45d3fdb4b 100644
--- a/crates/openhuman-core/src/inference/model_context.rs
+++ b/crates/openhuman-core/src/inference/model_context.rs
@@ -45,6 +45,18 @@ pub(crate) fn static_context_window_for_model(model: &str) -> Option<u64> {
return Some(window);
}
+ // These generic estimates predate the hosted tier policy and apply to
+ // concrete model ids regardless of which provider owns them.
+ if normalized == "chat" {
+ return Some(1_000_000);
+ }
+ if normalized.starts_with("gemma")
+ || normalized.contains(":1b")
+ || normalized.contains("270m")
+ {
+ return Some(8_192);
+ }
+
if let Some(price) = tinyagents_registry::pricing::lookup(normalized) {
tracing::debug!(
model = normalized,
diff --git a/crates/openhuman-core/src/inference/model_context_tests.rs b/crates/openhuman-core/src/inference/model_context_tests.rs
index 8339c825cc..c28fe9c746 100644
--- a/crates/openhuman-core/src/inference/model_context_tests.rs
+++ b/crates/openhuman-core/src/inference/model_context_tests.rs
@@ -1,31 +1,11 @@
use super::*;
#[test]
-fn tier_aliases_resolve() {
- assert_eq!(context_window_for_model("reasoning-v1"), Some(1_000_000));
- assert_eq!(context_window_for_model("agentic-v1"), Some(200_000));
- // chat-v1 is backed by DeepSeek v4 Flash (~1M), the same model as
- // summarization-v1 — not a 128K model (issue #4706).
- assert_eq!(context_window_for_model("chat-v1"), Some(1_000_000));
- // Burst tier — 128k on the managed backend. Matched on the alias, not
- // the local-gemma 8k substring arm.
- assert_eq!(context_window_for_model("burst-v1"), Some(128_000));
- // reasoning-quick-v1 is the legacy alias of chat-v1 (backend renamed it
- // 2026-05), so it resolves to the same ~1M flash window.
- assert_eq!(
- context_window_for_model("reasoning-quick-v1"),
- Some(1_000_000)
- );
- // summarization-v1 maps to a ~1M-token flash model so the extractor can
- // single-shot whole oversized payloads.
- assert_eq!(
- context_window_for_model("summarization-v1"),
- Some(1_000_000)
- );
- // The three flash-backed tiers share one window and must not drift.
- assert_eq!(
- context_window_for_model("chat-v1"),
- context_window_for_model("summarization-v1")
- );
+fn generic_model_window_patterns_retain_conservative_estimates() {
+ assert_eq!(context_window_for_model("chat"), Some(1_000_000));
+ assert_eq!(context_window_for_model("gemma-3n-e2b"), Some(8_192));
+ assert_eq!(context_window_for_model("custom-mini:1b"), Some(8_192));
+ assert_eq!(context_window_for_model("llama3:1b"), Some(8_192));
+ assert_eq!(context_window_for_model("custom-model-270m"), Some(8_192));
}
#[test]
diff --git a/crates/openhuman-tinyhumans/src/inference/tiers_tests.rs b/crates/openhuman-tinyhumans/src/inference/tiers_tests.rs
index 119208d32e..9bc60c6775 100644
--- a/crates/openhuman-tinyhumans/src/inference/tiers_tests.rs
+++ b/crates/openhuman-tinyhumans/src/inference/tiers_tests.rs
@@ -153,3 +153,21 @@ fn hosted_vision_capabilities_cover_managed_aliases_and_media_models() {
assert!(!supports_vision(model), "{model} should remain text-only");
}
}
+
+#[test]
+fn hosted_tier_context_windows_retain_the_legacy_alias_metadata() {
+ for (model, expected) in [
+ ("reasoning-v1", 1_000_000),
+ ("hint:reasoning", 1_000_000),
+ ("chat-v1", 1_000_000),
+ ("hint:chat", 1_000_000),
+ ("reasoning-quick-v1", 1_000_000),
+ ("summarization-v1", 1_000_000),
+ ("agentic-v1", 200_000),
+ ("hint:coding", 200_000),
+ ("burst-v1", 128_000),
+ ] {
+ assert_eq!(super::context_window(model), Some(expected), "{model}");
+ }
+ assert_eq!(super::context_window("chat"), None);
+}