diff --git a/codex-rs/app-server-client/src/lib.rs b/codex-rs/app-server-client/src/lib.rs index aefb35d4b4d9..004b7d1709fc 100644 --- a/codex-rs/app-server-client/src/lib.rs +++ b/codex-rs/app-server-client/src/lib.rs @@ -22,6 +22,7 @@ use std::fmt; use std::io::Error as IoError; use std::io::ErrorKind; use std::io::Result as IoResult; +use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -48,7 +49,11 @@ use codex_config::LoaderOverrides; use codex_config::NoopThreadConfigLoader; use codex_config::RemoteThreadConfigLoader; use codex_config::ThreadConfigLoader; +use codex_config::config_toml::ConfigToml; use codex_core::config::Config; +pub use codex_core::otel_init::build_provider as build_otel_provider; +use codex_core::personality_migration::PersonalityMigrationStatus; +use codex_core::personality_migration::maybe_migrate_personality; pub use codex_exec_server::EnvironmentManager; pub use codex_exec_server::ExecServerRuntimePaths; use codex_feedback::CodexFeedback; @@ -82,14 +87,6 @@ pub mod legacy_core { } } - pub mod otel_init { - pub use codex_core::otel_init::*; - } - - pub mod personality_migration { - pub use codex_core::personality_migration::*; - } - pub mod windows_sandbox { pub use codex_core::windows_sandbox::*; } @@ -97,6 +94,23 @@ pub mod legacy_core { const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(5); +/// Runs the embedded app-server personality migration. +/// +/// Returns `true` when the migration changed config and the caller should reload it. +pub async fn migrate_personality_if_needed( + codex_home: &Path, + config_toml: &ConfigToml, + state_db: Option, +) -> IoResult { + let status = maybe_migrate_personality(codex_home, config_toml, state_db).await?; + match status { + PersonalityMigrationStatus::Applied => Ok(true), + PersonalityMigrationStatus::SkippedMarker + | PersonalityMigrationStatus::SkippedExplicitPersonality + | PersonalityMigrationStatus::SkippedNoSessions => Ok(false), + } +} + /// Raw app-server request result for typed in-process requests. /// /// Even on the in-process path, successful responses still travel back through diff --git a/codex-rs/tui/src/lib.rs b/codex-rs/tui/src/lib.rs index 04633a803848..90409cad0577 100644 --- a/codex-rs/tui/src/lib.rs +++ b/codex-rs/tui/src/lib.rs @@ -1124,7 +1124,7 @@ pub async fn run_main( let otel_originator = originator().value; let otel = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - crate::legacy_core::otel_init::build_provider( + codex_app_server_client::build_otel_provider( &config, env!("CARGO_PKG_VERSION"), /*service_name_override*/ None, @@ -1147,26 +1147,25 @@ pub async fn run_main( None } }; - crate::legacy_core::otel_init::record_process_start(otel.as_ref(), otel_originator.as_str()); - crate::legacy_core::otel_init::install_sqlite_telemetry( - otel.as_ref(), - otel_originator.as_str(), - ); + if let Some(metrics) = otel.as_ref().and_then(codex_otel::OtelProvider::metrics) { + let _ = codex_otel::record_process_start_once(metrics, otel_originator.as_str()); + let telemetry = + codex_rollout::sqlite_telemetry_recorder(metrics.clone(), otel_originator.as_str()); + let _ = codex_state::install_process_db_telemetry(telemetry); + } let state_db = init_state_db_for_app_server_target(&config, &app_server_target).await?; let effective_toml = config.config_layer_stack.effective_config(); match effective_toml.try_into() { Ok(config_toml) => { - match crate::legacy_core::personality_migration::maybe_migrate_personality( + match codex_app_server_client::migrate_personality_if_needed( &config.codex_home, &config_toml, state_db.clone(), ) .await { - Ok( - crate::legacy_core::personality_migration::PersonalityMigrationStatus::Applied, - ) => { + Ok(true) => { config = load_config_or_exit( cli_kv_overrides.clone(), overrides.clone(), @@ -1176,11 +1175,7 @@ pub async fn run_main( ) .await; } - Ok( - crate::legacy_core::personality_migration::PersonalityMigrationStatus::SkippedMarker - | crate::legacy_core::personality_migration::PersonalityMigrationStatus::SkippedExplicitPersonality - | crate::legacy_core::personality_migration::PersonalityMigrationStatus::SkippedNoSessions, - ) => {} + Ok(false) => {} Err(err) => { tracing::warn!(error = %err, "failed to run personality migration"); }