Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 61 additions & 11 deletions apps/codex-plus-launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ async fn main() -> Result<()> {
Ok(())
}

async fn launcher_main(
args: Vec<String>,
helper_only: bool,
options: LaunchOptions,
) -> Result<()> {
async fn launcher_main(args: Vec<String>, helper_only: bool, options: LaunchOptions) -> Result<()> {
if helper_only {
let hooks = LauncherHooks::default();
hooks.start_helper(options.helper_port).await?;
Expand Down Expand Up @@ -132,13 +128,15 @@ fn acquire_single_instance_guard_with_retry(
}
Ok(Some(guard))
}
Err(error) if error.kind() == std::io::ErrorKind::WouldBlock => {
log_launcher_already_running(debug_port);
Ok(None)
}
Err(error) if error.kind() == std::io::ErrorKind::AddrInUse => {
Err(error)
if matches!(
error.kind(),
std::io::ErrorKind::WouldBlock | std::io::ErrorKind::AddrInUse
) =>
{
log_launcher_already_running(debug_port);
if allow_stale_recovery && should_recover_stale_launcher(debug_port) {
let stale = allow_stale_recovery && should_recover_stale_launcher(debug_port);
if should_retry_stale_launcher_guard(error.kind(), allow_stale_recovery, stale) {
codex_plus_core::watcher::stop_launcher_processes();
std::thread::sleep(std::time::Duration::from_millis(250));
return acquire_single_instance_guard_with_retry(debug_port, false);
Expand All @@ -156,6 +154,19 @@ fn acquire_single_instance_guard_with_retry(
}
}

fn should_retry_stale_launcher_guard(
error_kind: std::io::ErrorKind,
allow_stale_recovery: bool,
stale_launcher: bool,
) -> bool {
allow_stale_recovery
&& stale_launcher
&& matches!(
error_kind,
std::io::ErrorKind::WouldBlock | std::io::ErrorKind::AddrInUse
)
}

fn try_acquire_single_instance_guard() -> std::io::Result<codex_plus_core::ports::LoopbackPortGuard>
{
codex_plus_core::ports::acquire_resilient_loopback_port_guard(
Expand Down Expand Up @@ -513,6 +524,15 @@ impl LaunchHooks for LauncherHooks {
self.core.apply_active_relay_profile(settings).await
}

async fn ensure_active_protocol_proxy_config(
&self,
settings: &codex_plus_core::settings::BackendSettings,
) -> anyhow::Result<()> {
self.core
.ensure_active_protocol_proxy_config(settings)
.await
}

async fn ensure_plugin_marketplace_config(
&self,
settings: &codex_plus_core::settings::BackendSettings,
Expand Down Expand Up @@ -1125,6 +1145,30 @@ mod tests {
assert!(source.contains("status: \"failed\".to_string()"));
}

#[test]
fn stale_launcher_recovery_covers_port_and_fallback_lock_conflicts() {
assert!(should_retry_stale_launcher_guard(
std::io::ErrorKind::WouldBlock,
true,
true
));
assert!(should_retry_stale_launcher_guard(
std::io::ErrorKind::AddrInUse,
true,
true
));
assert!(!should_retry_stale_launcher_guard(
std::io::ErrorKind::WouldBlock,
false,
true
));
assert!(!should_retry_stale_launcher_guard(
std::io::ErrorKind::PermissionDenied,
true,
true
));
}

#[test]
fn existing_launcher_path_drains_pending_remote_control_recovery_before_activation() {
let source = include_str!("main.rs");
Expand Down Expand Up @@ -1197,13 +1241,19 @@ mod tests {
#[test]
fn launcher_hooks_forward_runtime_watchdog_and_marketplace_methods() {
let source = include_str!("main.rs");
let compact_source = source.split_whitespace().collect::<String>();

assert!(source.contains("async fn start_bridge_watchdog"));
assert!(source.contains("self.watchdog_bridge_context()?"));
assert!(source.contains("set_bridge_reinjector(reinjector)"));
assert!(source.contains("inject_with_context(debug_port, helper_port, ctx, runtime)"));
assert!(source.contains("async fn ensure_plugin_marketplace_config"));
assert!(source.contains("self.core.ensure_plugin_marketplace_config(settings).await"));
assert!(source.contains("async fn ensure_active_protocol_proxy_config"));
assert!(
compact_source
.contains("self.core.ensure_active_protocol_proxy_config(settings).await")
);
}

#[tokio::test]
Expand Down
Loading
Loading