mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Offer explicit recovery for incompatible background servers (#47318)
## Why Automatic daemon launches could silently fall back to embedded mode when shared feature settings differed from the session's requirements. Changing those settings affects other clients, and restarting the server may interrupt active or queued work. ## What changed - Offer interactive choices to run without the daemon, restart with the required settings, or cancel. Default to cancel and require explicit confirmation for restart. - Allow restart only for managed daemons with a feature mismatch, then recheck compatibility once. Noninteractive required-daemon failures return an error with `--no-daemon` guidance; optional attachment retains its fallback behavior. - Preserve saved feature overrides on startup and require confirmation before applying requested shared-feature disables, including on fresh starts. - Merge confirmed settings under the lifecycle lock, persist changes after the old process stops, and avoid restarting when the saved overrides already match. ## Testing Add recovery-menu snapshots and confirmation tests, compatibility tests for required and optional attachment, daemon ownership and settings-preservation tests, and CLI terminal tests for cancellation, embedded fallback, confirmed restart, and disabling shared features. GitOrigin-RevId: d50a6cf7e476b9647237431e8fc0fc6041ed17db
This commit is contained in:
@@ -617,6 +617,74 @@ async fn daemon_start_and_restart_preserve_launch_features() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn confirmed_feature_restart_preserves_ownership_and_skips_matching_settings() {
|
||||
use crate::LifecycleStatus;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
for managed in [true, false] {
|
||||
let home = TempDir::new().unwrap();
|
||||
let (daemon, _) = manual_update_daemon(&home);
|
||||
std::fs::write(&daemon.settings_file,
|
||||
r#"{"featureOverrides":{"auth_elicitation":true,"api_key_model_discovery":true},"updater":{"autoUpdateEnabled":false},"shutdownGraceSeconds":0}"#
|
||||
).unwrap();
|
||||
let original = daemon.load_settings().await.unwrap();
|
||||
if managed {
|
||||
daemon.start_managed_backend(&original).await.unwrap();
|
||||
}
|
||||
let server = test_control_server(&daemon, home.path()).await;
|
||||
let _lock = daemon.acquire_operation_lock().await.unwrap();
|
||||
let requested = BTreeMap::from([
|
||||
("api_key_model_discovery".to_string(), false),
|
||||
("mcp_oauth_refresh_coordination".to_string(), true),
|
||||
]);
|
||||
if managed {
|
||||
// Hide the selection without removing the script the spawned shell still needs.
|
||||
let selected_package = daemon.managed_codex_bin.parent().unwrap();
|
||||
let saved_package = selected_package.with_extension("saved");
|
||||
std::fs::rename(selected_package, &saved_package).unwrap();
|
||||
let error = daemon
|
||||
.restart_with_features_locked(&requested)
|
||||
.await
|
||||
.unwrap_err();
|
||||
std::fs::rename(saved_package, selected_package).unwrap();
|
||||
assert!(
|
||||
error.to_string().contains("daemon executable not found"),
|
||||
"{error:#}"
|
||||
);
|
||||
assert_eq!(daemon.load_settings().await.unwrap(), original);
|
||||
}
|
||||
let result = daemon.restart_with_features_locked(&requested).await;
|
||||
if managed {
|
||||
assert_eq!(result.unwrap().status, LifecycleStatus::Restarted);
|
||||
let pid = std::fs::read(&daemon.pid_file).unwrap();
|
||||
let mut expected = original;
|
||||
expected.feature_overrides.extend(requested.clone());
|
||||
assert_eq!(daemon.load_settings().await.unwrap(), expected);
|
||||
assert_eq!(
|
||||
daemon
|
||||
.restart_with_features_locked(&requested)
|
||||
.await
|
||||
.unwrap()
|
||||
.status,
|
||||
LifecycleStatus::AlreadyRunning
|
||||
);
|
||||
assert_eq!(std::fs::read(&daemon.pid_file).unwrap(), pid);
|
||||
daemon.stop().await.unwrap();
|
||||
} else {
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("no running managed daemon")
|
||||
);
|
||||
assert_eq!(daemon.load_settings().await.unwrap(), original);
|
||||
}
|
||||
server.abort();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn manual_update_restarts_local_daemon_with_automatic_updates_disabled() {
|
||||
|
||||
Reference in New Issue
Block a user