Skip to content

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

refactor(runtime): move welcome migration into runtime bootstrap

Steven Enamakel6fce25a0e7e8
diff --git a/crates/openhuman-core/src/core/runtime/bootstrap.rs b/crates/openhuman-core/src/core/runtime/bootstrap.rs
index c002ae98e8..fbd61b66fb 100644
--- a/crates/openhuman-core/src/core/runtime/bootstrap.rs
+++ b/crates/openhuman-core/src/core/runtime/bootstrap.rs
@@ -19,6 +19,7 @@ pub(crate) async fn bootstrap_core_runtime(
host_kind: crate::core::types::HostKind,
config: Option<crate::config::Config>,
domains: crate::core::runtime::DomainSet,
+ ctx: &DispatchCtx,
) {
use crate::platform::socket::{set_global_socket_manager, SocketManager};
use std::sync::Arc;
@@ -87,7 +88,7 @@ pub(crate) async fn bootstrap_core_runtime(
// meant to gate the first tool call of the first turn has to be loaded
// before any session exists, and the alternative — loading lazily on the
// first event — would let that first call through while the file is read.
- crate::hooks::init(&DispatchCtx::ambient(), &cfg).await;
+ crate::hooks::init(ctx, &cfg).await;
// --- Turn-state recovery -------------------------------------------
// Any per-thread turn snapshots left on disk from a previous process
@@ -97,7 +98,7 @@ pub(crate) async fn bootstrap_core_runtime(
//
// An installed host session store repairs itself, once; with none, the
// workspace default store is swept.
- let host_store = crate::agent::session_store::installed_in(&DispatchCtx::ambient());
+ let host_store = crate::agent::session_store::installed_in(ctx);
if let Some(provider) = &host_store {
match provider.recover() {
Ok(()) => log::info!("[runtime] host session store recovered"),
@@ -163,7 +164,7 @@ pub(crate) async fn bootstrap_core_runtime(
// completion log (`<workspace>/.openhuman/background_completions.jsonl`).
// Schedule its delivery turn through the normal idle-gated path.
let redelivering = crate::agent::orchestration::background_delivery::recover_on_boot(
- &DispatchCtx::ambient(),
+ ctx,
&workspace_dir,
);
if redelivering > 0 {
@@ -371,7 +372,7 @@ pub(crate) async fn bootstrap_core_runtime(
crate::web_chat::register_memory_activity_surface_subscriber();
// --- Workspace migrations --------------------------------------------
- crate::platform::startup::run_workspace_migrations(&workspace_dir);
+ crate::platform::startup::run_workspace_migrations(ctx, &workspace_dir);
// --- Socket manager bootstrap ---
let socket_mgr = Arc::new(SocketManager::new());
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index 63eb9e7425..e73da88d9b 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -305,7 +305,8 @@ impl CoreContext {
// background jobs start later, from CoreRuntime::start_services(), after a transport binds
// succeeds.
let runtime_config = config.clone();
- super::bootstrap::bootstrap_core_runtime(host_kind, config, domains).await;
+ super::bootstrap::bootstrap_core_runtime(host_kind, config, domains, &DispatchCtx::new(ctx.clone()))
+ .await;
Ok((ctx, has_operator_token, runtime_config))
}
diff --git a/crates/openhuman-core/src/platform/startup/ops.rs b/crates/openhuman-core/src/platform/startup/ops.rs
index c858a00230..0af0793fc4 100644
--- a/crates/openhuman-core/src/platform/startup/ops.rs
+++ b/crates/openhuman-core/src/platform/startup/ops.rs
@@ -4,8 +4,8 @@ use std::path::Path;
///
/// Failures are logged and do not abort startup. Individual migration helpers
/// remain responsible for their own idempotency markers.
-pub fn run_workspace_migrations(workspace_dir: &Path) {
- match crate::threads::migrate_welcome_agent_artifacts(workspace_dir) {
+pub fn run_workspace_migrations(ctx: &crate::core::runtime::DispatchCtx, workspace_dir: &Path) {
+ match crate::threads::migrate_welcome_agent_artifacts(ctx, workspace_dir) {
Ok(result) if result.already_done => {
log::debug!("[migration::welcome-to-orchestrator] already applied");
}
diff --git a/crates/openhuman-core/src/platform/startup/ops_tests.rs b/crates/openhuman-core/src/platform/startup/ops_tests.rs
index 1a7635d136..f050afbdaa 100644
--- a/crates/openhuman-core/src/platform/startup/ops_tests.rs
+++ b/crates/openhuman-core/src/platform/startup/ops_tests.rs
@@ -13,7 +13,7 @@ fn workspace_startup_migrates_transcripts_once() {
fs::create_dir_all(legacy.parent().unwrap()).unwrap();
fs::write(&legacy, "legacy transcript").unwrap();
- run_workspace_migrations(workspace);
+ run_workspace_migrations(&crate::core::runtime::DispatchCtx::ambient(), workspace);
let canonical = workspace.join("session_raw/1714000000_main.jsonl");
let marker = workspace.join("state/migrations/session_layout_v1.done");
@@ -24,7 +24,7 @@ fn workspace_startup_migrates_transcripts_once() {
// than re-running the migration on every process launch.
fs::create_dir_all(legacy.parent().unwrap()).unwrap();
fs::write(&legacy, "must remain legacy after marker").unwrap();
- run_workspace_migrations(workspace);
+ run_workspace_migrations(&crate::core::runtime::DispatchCtx::ambient(), workspace);
assert_eq!(fs::read_to_string(&canonical).unwrap(), "legacy transcript");
assert_eq!(
diff --git a/crates/openhuman-core/src/threads/welcome_migration.rs b/crates/openhuman-core/src/threads/welcome_migration.rs
index b9dffceb66..fbb0a845c6 100644
--- a/crates/openhuman-core/src/threads/welcome_migration.rs
+++ b/crates/openhuman-core/src/threads/welcome_migration.rs
@@ -52,7 +52,7 @@ pub fn migrate_welcome_agent_artifacts(
}
let mut result = WelcomeMigrationResult::default();
- let thread_result = migrate_welcome_thread_labels(workspace_dir)?;
+ let thread_result = migrate_welcome_thread_labels(ctx, workspace_dir)?;
result.threads_updated = thread_result.threads_updated;
let transcript_result = migrate_welcome_transcripts(workspace_dir)?;
result.transcripts_updated = transcript_result.transcripts_updated;
@@ -85,6 +85,7 @@ struct ThreadLabelMigrationResult {
}
fn migrate_welcome_thread_labels(
+ ctx: &DispatchCtx,
workspace_dir: &Path,
) -> Result<ThreadLabelMigrationResult, String> {
log::debug!(
@@ -93,7 +94,7 @@ fn migrate_welcome_thread_labels(
WELCOME_THREAD_LABEL
);
- let threads = conversations::list_threads(&DispatchCtx::ambient(), workspace_dir.to_path_buf())
+ let threads = conversations::list_threads(ctx, workspace_dir.to_path_buf())
.map_err(|e| format!("[migration::welcome-to-orchestrator] list_threads failed: {e}"))?;
let mut threads_updated = 0usize;
@@ -116,7 +117,7 @@ fn migrate_welcome_thread_labels(
let updated_at = chrono::Utc::now().to_rfc3339();
match conversations::update_thread_labels(
- &DispatchCtx::ambient(),
+ ctx,
workspace_dir.to_path_buf(),
&thread.id,
new_labels,
diff --git a/crates/openhuman-core/src/threads/welcome_migration_tests.rs b/crates/openhuman-core/src/threads/welcome_migration_tests.rs
index 9951a0a9de..3b57dabb3e 100644
--- a/crates/openhuman-core/src/threads/welcome_migration_tests.rs
+++ b/crates/openhuman-core/src/threads/welcome_migration_tests.rs
@@ -43,7 +43,7 @@ fn migration_updates_thread_labels_and_transcripts() {
fs::create_dir_all(md.parent().unwrap()).unwrap();
fs::write(&md, "# Session transcript — welcome_thread-abc\n").unwrap();
- let result = migrate_welcome_agent_artifacts(workspace).unwrap();
+ let result = migrate_welcome_agent_artifacts(&crate::core::runtime::DispatchCtx::ambient(), workspace).unwrap();
assert_eq!(result.threads_updated, 1);
assert_eq!(result.transcripts_updated, 1);
@@ -84,7 +84,7 @@ fn migration_is_idempotent_after_marker() {
fs::create_dir_all(workspace.join("state/migrations")).unwrap();
fs::write(workspace.join(MIGRATION_MARKER), b"done\n").unwrap();
- let result = migrate_welcome_agent_artifacts(workspace).unwrap();
+ let result = migrate_welcome_agent_artifacts(&crate::core::runtime::DispatchCtx::ambient(), workspace).unwrap();
assert!(result.already_done);
assert_eq!(result.threads_updated, 0);
assert_eq!(result.transcripts_updated, 0);
@@ -100,7 +100,7 @@ fn migration_returns_error_without_marker_when_destination_exists() {
let dest = workspace.join("session_raw/1715000000_orchestrator_thread-abc.jsonl");
write_transcript(&dest, "orchestrator_thread-abc", "thread-abc");
- let err = migrate_welcome_agent_artifacts(workspace).unwrap_err();
+ let err = migrate_welcome_agent_artifacts(&crate::core::runtime::DispatchCtx::ambient(), workspace).unwrap_err();
assert!(
err.contains("partial migration"),