Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions apps/codex-plus-launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ fn should_recover_stale_launcher(debug_port: u16) -> bool {

async fn activate_existing_codex_app(options: &LaunchOptions) -> anyhow::Result<()> {
let hooks = LauncherHooks::default();
let helper_port = hooks.select_helper_port(options.helper_port);
let settings = hooks.load_settings().await?;
let app_dir = hooks.resolve_app_dir(options.app_dir.as_deref(), &settings)?;
let has_pending_recovery = hooks.has_pending_remote_control_session_recoveries();
Expand All @@ -184,9 +183,6 @@ async fn activate_existing_codex_app(options: &LaunchOptions) -> anyhow::Result<
&settings.codex_extra_args,
)
.await;
if settings.enhancements_enabled {
hooks.start_helper(helper_port).await?;
}
let process_ids = codex_plus_core::watcher::find_codex_processes();
let mut activated = false;
#[cfg(windows)]
Expand All @@ -198,31 +194,14 @@ async fn activate_existing_codex_app(options: &LaunchOptions) -> anyhow::Result<
}
}
}
let injection_ready = if settings.enhancements_enabled {
hooks
.ensure_injection(options.debug_port, helper_port, &app_dir)
.await
} else {
false
};
if injection_ready {
hooks
.start_bridge_watchdog(options.debug_port, helper_port)
.await?;
hooks.write_status("running").await;
} else if settings.enhancements_enabled {
hooks.write_status("running_degraded").await;
}
let _ = codex_plus_core::diagnostic_log::append_diagnostic_log(
"launcher.activate_existing_codex",
json!({
"app_dir": app_dir.to_string_lossy(),
"debug_port": options.debug_port,
"helper_port": helper_port,
"requested_helper_port": options.helper_port,
"process_ids": process_ids,
"activated": activated,
"injection_ready": injection_ready,
"launch_ok": launch_result.is_ok(),
"launch_error": launch_result.as_ref().err().map(|error| error.to_string())
}),
Expand Down Expand Up @@ -1051,6 +1030,20 @@ mod tests {
assert!(source.contains("launcher.already_running"));
}

#[test]
fn repeated_launcher_does_not_recreate_the_bridge() {
let source = include_str!("main.rs");
let existing_instance_path = source
.split_once("async fn activate_existing_codex_app")
.and_then(|(_, source)| source.split_once("fn log_launcher_already_running"))
.map(|(path, _)| path)
.expect("existing-instance launcher path should be present");

assert!(!existing_instance_path.contains("start_helper"));
assert!(!existing_instance_path.contains("ensure_injection"));
assert!(!existing_instance_path.contains("start_bridge_watchdog"));
}

#[test]
fn existing_launcher_path_drains_pending_remote_control_recovery_before_activation() {
let source = include_str!("main.rs");
Expand Down