mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Let administrators disable Codex daemon updates (#62690)
## Why The daemon's automatic update preference still permits manual updates. Administrators need a policy that covers both paths. ## What changed Set `features.daemon_updates = false` in managed `requirements.toml` or local MDM policy to block scheduled updates and manual daemon package replacements. Updates are allowed by default. User configuration cannot override the policy, and cloud-delivered requirements reject the setting. When policy blocks updates, the TUI hides update actions in `/daemon`, suppresses update offers in version notices, and directs users to their administrator where a newer daemon is required. ## Testing Add coverage for the default, disabled, and invalid policy cases, rejection of the setting in cloud requirements, and the TUI with daemon updates disabled. GitOrigin-RevId: de9e50c4acc4dc8e83bbd2b9a5e902deb8c6f477
This commit is contained in:
Generated
+2
@@ -2263,6 +2263,8 @@ dependencies = [
|
||||
"blake3",
|
||||
"codex-app-server-protocol",
|
||||
"codex-app-server-transport",
|
||||
"codex-config",
|
||||
"codex-exec-server",
|
||||
"codex-features",
|
||||
"codex-http-client",
|
||||
"codex-install-context",
|
||||
|
||||
@@ -16,6 +16,8 @@ workspace = true
|
||||
anyhow = { workspace = true }
|
||||
codex-app-server-protocol = { workspace = true }
|
||||
codex-app-server-transport = { workspace = true }
|
||||
codex-config = { workspace = true }
|
||||
codex-exec-server = { workspace = true }
|
||||
codex-features = { workspace = true }
|
||||
codex-http-client = { workspace = true }
|
||||
codex-install-context = { workspace = true }
|
||||
|
||||
@@ -58,7 +58,14 @@ default. Edit `CODEX_HOME/app-server-daemon/settings.json` to change this:
|
||||
|
||||
Positive minute intervals have no configured cap. `daemon restart` applies the
|
||||
enabled state; the next updater wait reads a new interval. The preference does
|
||||
not affect an explicit `codex update` command or `daemon update`.
|
||||
not affect an explicit `codex update` command or `daemon update`. Administrators
|
||||
can prohibit both automatic and explicit daemon updates through managed
|
||||
`requirements.toml` (or local MDM policy; cloud-delivered requirements cannot set this flag):
|
||||
|
||||
```toml
|
||||
[features]
|
||||
daemon_updates = false
|
||||
```
|
||||
|
||||
`daemon update` selects the latest stable release, even with automatic updates
|
||||
disabled. It also returns pinned or local managed packages to production update
|
||||
|
||||
@@ -25,6 +25,7 @@ mod settings;
|
||||
pub mod telemetry;
|
||||
mod thread_recovery;
|
||||
mod update_loop;
|
||||
mod update_policy;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Write;
|
||||
@@ -319,13 +320,20 @@ pub fn maintain_stderr_log() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks the current locally managed daemon update policy.
|
||||
pub async fn ensure_updates_allowed() -> Result<()> {
|
||||
update_policy::ensure_allowed(&Daemon::from_environment()?).await
|
||||
}
|
||||
|
||||
pub async fn update(
|
||||
http_client_factory: codex_http_client::HttpClientFactory,
|
||||
) -> Result<UpdateOutput> {
|
||||
ensure_supported_platform()?;
|
||||
#[cfg(windows)]
|
||||
backend::windows::ensure_not_elevated()?;
|
||||
update_loop::request_manual_update(&Daemon::from_environment()?, http_client_factory).await
|
||||
let daemon = Daemon::from_environment()?;
|
||||
crate::update_policy::ensure_allowed(&daemon).await?;
|
||||
update_loop::request_manual_update(&daemon, http_client_factory).await
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows))]
|
||||
@@ -1016,9 +1024,14 @@ impl Daemon {
|
||||
|
||||
async fn ensure_managed_updater(&self, settings: &DaemonSettings) -> Result<bool> {
|
||||
let updater = backend::pid_update_loop_backend(self.backend_paths(settings));
|
||||
if !settings.auto_update_enabled {
|
||||
let allowed = if settings.auto_update_enabled {
|
||||
crate::update_policy::allowed(self).await
|
||||
} else {
|
||||
Ok(false)
|
||||
};
|
||||
if !matches!(&allowed, Ok(true)) {
|
||||
updater.stop().await?;
|
||||
return Ok(false);
|
||||
return allowed;
|
||||
}
|
||||
if !self.is_stable_standalone_release()? {
|
||||
// An installer publishes current and the latest marker separately.
|
||||
@@ -1088,6 +1101,7 @@ impl Daemon {
|
||||
|
||||
async fn is_bootstrapped(&self, settings: &DaemonSettings) -> Result<bool> {
|
||||
if !settings.auto_update_enabled
|
||||
|| !crate::update_policy::allowed(self).await.unwrap_or(false)
|
||||
|| !self.is_stable_standalone_release()?
|
||||
|| !managed_install::supports_daemon_update_loop(&self.managed_codex_bin).await
|
||||
{
|
||||
|
||||
@@ -59,6 +59,7 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
|
||||
.any(|window| window == b"CODEX_INSTALL_DEFER_SELECTION"),
|
||||
"the published installer does not support daemon migration yet; the legacy installation was left unchanged"
|
||||
);
|
||||
crate::update_policy::ensure_allowed(legacy).await?;
|
||||
eprintln!("Preparing the daemon update in {}...", root.display());
|
||||
#[cfg(unix)]
|
||||
{
|
||||
@@ -123,6 +124,7 @@ pub(super) async fn run(http: &impl InstallerHttp, legacy: &Daemon) -> Result<Up
|
||||
if cancellation.as_mut().now_or_never().is_some() {
|
||||
return Err(std::io::Error::from(std::io::ErrorKind::Interrupted).into());
|
||||
}
|
||||
crate::update_policy::ensure_allowed(legacy).await?;
|
||||
let cutover = async {
|
||||
backend::pid_update_loop_backend(legacy.backend_paths(&settings))
|
||||
.stop()
|
||||
|
||||
@@ -51,6 +51,7 @@ pub async fn update_from_cli(
|
||||
#[cfg(windows)]
|
||||
crate::backend::windows::ensure_not_elevated()?;
|
||||
let daemon = Daemon::from_environment()?;
|
||||
crate::update_policy::ensure_allowed(&daemon).await?;
|
||||
let settings = daemon.load_settings().await?;
|
||||
let source = InstallContext::current().package_layout.as_ref();
|
||||
if !Box::pin(prepare_from_package(
|
||||
@@ -203,6 +204,7 @@ async fn prepare_from_package(
|
||||
None // Initial startup already holds the operation lock.
|
||||
};
|
||||
let current_settings = if mode == InstallMode::Replace {
|
||||
crate::update_policy::ensure_allowed(daemon).await?;
|
||||
Some(daemon.load_settings().await?)
|
||||
} else {
|
||||
None
|
||||
@@ -341,6 +343,7 @@ async fn prepare_from_package(
|
||||
#[cfg(windows)]
|
||||
windows::validate_selection(&root)?;
|
||||
if mode == InstallMode::Replace {
|
||||
crate::update_policy::ensure_allowed(daemon).await?;
|
||||
let stopped = async {
|
||||
crate::backend::pid_update_loop_backend(daemon.backend_paths(settings))
|
||||
.stop()
|
||||
|
||||
@@ -198,6 +198,15 @@ async fn run_with_http(
|
||||
if restore_release.is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
match crate::update_policy::allowed(daemon).await {
|
||||
Ok(false) => return Ok(()),
|
||||
Err(_) => {
|
||||
daemon.diagnostic(format_args!("warning: daemon update policy is unavailable; retrying"));
|
||||
next_check = Instant::now() + Duration::from_secs(60);
|
||||
continue;
|
||||
}
|
||||
Ok(true) => {}
|
||||
}
|
||||
match UpdaterSettings::load(&daemon.settings_file).await {
|
||||
Ok(settings) if !settings.auto_update_enabled => return Ok(()),
|
||||
Err(_) => {
|
||||
@@ -338,6 +347,7 @@ async fn update_once(
|
||||
terminate: &mut Signal,
|
||||
trigger: UpdateTrigger<'_>,
|
||||
) -> Result<(UpdateLoopControl, Option<RestartIfRunningOutcome>)> {
|
||||
crate::update_policy::ensure_allowed(daemon).await?;
|
||||
if trigger == UpdateTrigger::Scheduled
|
||||
&& !UpdaterSettings::load(&daemon.settings_file)
|
||||
.await?
|
||||
@@ -404,6 +414,7 @@ async fn update_once(
|
||||
crate::managed_install::package_root(codex_home) == package_root,
|
||||
"daemon package root changed during the update; retry the command"
|
||||
);
|
||||
crate::update_policy::ensure_allowed(daemon).await?;
|
||||
let started = std::time::Instant::now();
|
||||
#[cfg(unix)]
|
||||
if matches!(
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//! Enforces managed daemon update policy independently of daemon preferences.
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_config::loader::load_managed_requirements_state;
|
||||
use codex_config::loader::refresh_managed_preferences;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_features::Feature;
|
||||
|
||||
use crate::Daemon;
|
||||
|
||||
pub(crate) async fn allowed(daemon: &Daemon) -> Result<bool> {
|
||||
let home = daemon
|
||||
.settings_file
|
||||
.parent()
|
||||
.and_then(std::path::Path::parent)
|
||||
.context("daemon settings path has no Codex home")?;
|
||||
updates_allowed(home, LoaderOverrides::default()).await
|
||||
}
|
||||
|
||||
pub(crate) async fn ensure_allowed(daemon: &Daemon) -> Result<()> {
|
||||
anyhow::ensure!(
|
||||
allowed(daemon).await?,
|
||||
"Daemon updates are disabled by managed policy (features.daemon_updates = false)."
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn updates_allowed(home: &std::path::Path, overrides: LoaderOverrides) -> Result<bool> {
|
||||
refresh_managed_preferences(&overrides).await?;
|
||||
let requirements = load_managed_requirements_state(LOCAL_FS.as_ref(), home, overrides)
|
||||
.await
|
||||
.context("failed to load managed daemon update policy")?;
|
||||
Ok(requirements
|
||||
.feature_requirements
|
||||
.as_ref()
|
||||
.and_then(|features| features.entries.get(Feature::DaemonUpdates.key()))
|
||||
.copied()
|
||||
.unwrap_or(true))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "update_policy_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,17 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn managed_policy_controls_daemon_updates_and_rejects_invalid_policy() -> Result<()> {
|
||||
let home = tempfile::tempdir()?;
|
||||
let path = home.path().join("requirements.toml");
|
||||
let mut overrides = LoaderOverrides::without_managed_config_for_tests();
|
||||
overrides.system_requirements_path = Some(path.clone());
|
||||
assert!(updates_allowed(home.path(), overrides.clone()).await?);
|
||||
tokio::fs::write(&path, "[features]\ndaemon_updates = false\n").await?;
|
||||
assert!(!updates_allowed(home.path(), overrides.clone()).await?);
|
||||
tokio::fs::write(&path, "[features]\ndaemon_updates = 'invalid'\n").await?;
|
||||
assert!(updates_allowed(home.path(), overrides).await.is_err());
|
||||
Ok(())
|
||||
}
|
||||
@@ -1904,15 +1904,21 @@ writable_roots = [{}]
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn config_value_write_replaces_value() -> Result<()> {
|
||||
async fn config_value_write_replaces_value_despite_stale_daemon_update_setting() -> Result<()> {
|
||||
let temp_dir = TempDir::new()?;
|
||||
let codex_home = temp_dir.path().canonicalize()?;
|
||||
write_config(
|
||||
&temp_dir,
|
||||
r#"
|
||||
model = "gpt-old"
|
||||
[features]
|
||||
daemon_updates = true
|
||||
"#,
|
||||
)?;
|
||||
std::fs::write(
|
||||
codex_home.join("requirements.toml"),
|
||||
"[features]\ndaemon_updates = false\n",
|
||||
)?;
|
||||
|
||||
let mut mcp = TestAppServer::builder()
|
||||
.with_codex_home(&codex_home)
|
||||
|
||||
@@ -57,11 +57,7 @@ pub async fn load_local_application_requirements(
|
||||
.flatten();
|
||||
#[cfg(target_os = "macos")]
|
||||
let mdm = {
|
||||
if overrides.macos_managed_config_requirements_base64.is_none() {
|
||||
tokio::task::spawn_blocking(super::macos::synchronize_managed_preferences)
|
||||
.await
|
||||
.map_err(io::Error::other)??;
|
||||
}
|
||||
super::refresh_managed_preferences(overrides).await?;
|
||||
super::macos::load_managed_admin_requirements_layer(
|
||||
overrides
|
||||
.macos_managed_config_requirements_base64
|
||||
|
||||
@@ -73,6 +73,19 @@ pub use local::LocalTomlLayerStack;
|
||||
pub use local::load_local_config_layers;
|
||||
pub use managed_requirements::load_guardian_policy_snapshot;
|
||||
pub use managed_requirements::load_managed_requirements_state;
|
||||
|
||||
/// Refreshes local managed preferences before enforcing policy in a long-lived process.
|
||||
pub async fn refresh_managed_preferences(overrides: &LoaderOverrides) -> std::io::Result<()> {
|
||||
#[cfg(target_os = "macos")]
|
||||
if overrides.macos_managed_config_requirements_base64.is_none() {
|
||||
tokio::task::spawn_blocking(macos::synchronize_managed_preferences)
|
||||
.await
|
||||
.map_err(std::io::Error::other)??;
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let _ = overrides;
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub use windows::WindowsSystemConfigNamespaceProbe;
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -112,6 +112,20 @@ impl ComposableRequirementsLayer {
|
||||
});
|
||||
}
|
||||
|
||||
if matches!(source, RequirementSource::EnterpriseManaged { .. })
|
||||
&& ["features", "feature_requirements"].into_iter().any(|key| {
|
||||
regular_toml
|
||||
.get(key)
|
||||
.and_then(|features| features.get("daemon_updates"))
|
||||
.is_some()
|
||||
})
|
||||
{
|
||||
return Err(RequirementsCompositionError::Parse {
|
||||
layer_source: source.clone(),
|
||||
message: "features.daemon_updates may only be configured in local managed requirements".into(),
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(otel) = regular_toml.get("otel")
|
||||
&& (otel.get("headers_helper").is_some()
|
||||
|| otel.get("headers_helper_refresh_interval_ms").is_some())
|
||||
|
||||
@@ -522,6 +522,21 @@ exporter = { otlp-http = { endpoint = "", protocol = "binary" } }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cloud_requirements_cannot_configure_daemon_updates() {
|
||||
for table in ["features", "feature_requirements"] {
|
||||
let err = compose(vec![layer(
|
||||
"cloud",
|
||||
"Cloud",
|
||||
&format!("[{table}]\ndaemon_updates = false"),
|
||||
)])
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
matches!(err, RequirementsCompositionError::Parse { message, .. } if message.contains("local managed requirements"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn otel_cloud_requirements_cannot_install_or_reschedule_a_helper() {
|
||||
for setting in [
|
||||
|
||||
@@ -1003,6 +1003,9 @@
|
||||
"daemon_auto_start": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"daemon_updates": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"daybreak_program_propagation": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -8371,6 +8374,9 @@
|
||||
"daemon_auto_start": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"daemon_updates": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"daybreak_program_propagation": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -1486,12 +1486,18 @@ personality = true
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn system_requirements_control_in_app_updates() -> anyhow::Result<()> {
|
||||
async fn system_requirements_control_update_features() -> anyhow::Result<()> {
|
||||
let tmp = tempdir()?;
|
||||
let codex_home = tmp.path().join("home");
|
||||
tokio::fs::create_dir_all(&codex_home).await?;
|
||||
let cwd = AbsolutePathBuf::from_absolute_path(tmp.path())?;
|
||||
|
||||
tokio::fs::write(
|
||||
codex_home.join("config.toml"),
|
||||
"[features]\ndaemon_updates = false\n",
|
||||
)
|
||||
.await?;
|
||||
|
||||
let default_config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.clone())
|
||||
.fallback_cwd(Some(cwd.to_path_buf()))
|
||||
@@ -1499,6 +1505,7 @@ async fn system_requirements_control_in_app_updates() -> anyhow::Result<()> {
|
||||
.build()
|
||||
.await?;
|
||||
assert!(default_config.features.enabled(Feature::InAppUpdates));
|
||||
assert!(default_config.features.enabled(Feature::DaemonUpdates));
|
||||
|
||||
let requirements_path = tmp.path().join("requirements.toml");
|
||||
tokio::fs::write(
|
||||
@@ -1506,6 +1513,7 @@ async fn system_requirements_control_in_app_updates() -> anyhow::Result<()> {
|
||||
r#"
|
||||
[features]
|
||||
in_app_updates = false
|
||||
daemon_updates = false
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
@@ -1519,6 +1527,7 @@ in_app_updates = false
|
||||
.await?;
|
||||
|
||||
assert!(!managed_config.features.enabled(Feature::InAppUpdates));
|
||||
assert!(!managed_config.features.enabled(Feature::DaemonUpdates));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -383,6 +383,10 @@ pub enum Feature {
|
||||
///
|
||||
/// Requirements-only gate: this should be set from requirements, not user config.
|
||||
InAppUpdates,
|
||||
/// Allow automatic and explicit daemon updates.
|
||||
///
|
||||
/// Requirements-only gate: this should be set from requirements, not user config.
|
||||
DaemonUpdates,
|
||||
/// Allow Browser Use agent integration in desktop apps.
|
||||
///
|
||||
/// Requirements-only gate: this should be set from requirements, not user config.
|
||||
@@ -1039,6 +1043,7 @@ impl Features {
|
||||
impl FeaturesToml {
|
||||
pub fn entries(&self) -> BTreeMap<String, bool> {
|
||||
let mut entries = self.entries.clone();
|
||||
entries.remove(Feature::DaemonUpdates.key());
|
||||
if let Some(enabled) = self
|
||||
.async_compaction
|
||||
.as_ref()
|
||||
@@ -2032,6 +2037,12 @@ pub const FEATURES: &[FeatureSpec] = &[
|
||||
stage: Stage::Stable,
|
||||
default_enabled: true,
|
||||
},
|
||||
FeatureSpec {
|
||||
id: Feature::DaemonUpdates,
|
||||
key: "daemon_updates",
|
||||
stage: Stage::Stable,
|
||||
default_enabled: true,
|
||||
},
|
||||
FeatureSpec {
|
||||
id: Feature::BrowserUse,
|
||||
key: "browser_use",
|
||||
|
||||
@@ -41,7 +41,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn open_daemon_menu(&mut self) {
|
||||
pub(super) fn open_daemon_menu(&mut self, policy_error: Option<&str>) {
|
||||
let status = self
|
||||
.chat_widget
|
||||
.remote_connection
|
||||
@@ -67,6 +67,10 @@ impl App {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let updates_allowed = policy_error.is_none();
|
||||
if let Some(error) = policy_error {
|
||||
header.push(Line::from(error.to_owned().dim()));
|
||||
}
|
||||
if let Some(guidance) = unavailable {
|
||||
header.push(Line::from(guidance.dim()));
|
||||
}
|
||||
@@ -87,6 +91,7 @@ impl App {
|
||||
(DaemonUpdateSource::ThisCli, "Use this CLI build"),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|_| updates_allowed)
|
||||
.map(|(source, name)| SelectionItem {
|
||||
name: name.to_string(),
|
||||
is_disabled: unavailable.is_some(),
|
||||
|
||||
@@ -100,7 +100,7 @@ async fn daemon_menu_is_read_only_and_confirmation_can_cancel_or_handoff() {
|
||||
(100, DaemonUpdateSource::ThisCli, "daemon_cli_confirmation"),
|
||||
] {
|
||||
app.daemon_cli_executable = executable.clone();
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
if source == DaemonUpdateSource::PublicStable {
|
||||
insta::assert_snapshot!(
|
||||
"daemon_menu",
|
||||
@@ -141,7 +141,7 @@ async fn daemon_menu_is_read_only_and_confirmation_can_cancel_or_handoff() {
|
||||
}
|
||||
|
||||
app.daemon_cli_executable = executable.clone();
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
let mut terminal = crate::custom_terminal::Terminal::with_options(
|
||||
crate::test_backend::VT100Backend::new(/*width*/ 120, /*height*/ 30),
|
||||
)
|
||||
@@ -219,7 +219,7 @@ async fn daemon_menu_is_read_only_and_confirmation_can_cancel_or_handoff() {
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.is_managed_daemon = false;
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
insta::assert_snapshot!(
|
||||
"daemon_unmanaged",
|
||||
render_bottom_popup(&app.chat_widget, /*width*/ 80)
|
||||
@@ -242,7 +242,7 @@ async fn daemon_menu_is_read_only_and_confirmation_can_cancel_or_handoff() {
|
||||
DaemonUpdateSource::PublicStable,
|
||||
DaemonUpdateSource::ThisCli,
|
||||
] {
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
if source == DaemonUpdateSource::PublicStable {
|
||||
insta::assert_snapshot!(
|
||||
"daemon_disconnected",
|
||||
@@ -272,7 +272,7 @@ async fn daemon_menu_is_read_only_and_confirmation_can_cancel_or_handoff() {
|
||||
// The full CLI can have any filename; capability comes from its entry point.
|
||||
app.daemon_cli_executable =
|
||||
Some(AbsolutePathBuf::from_absolute_path(package.path().join("bin/codex-tui")).unwrap());
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
insta::assert_snapshot!(
|
||||
"daemon_unpackaged_cli",
|
||||
render_bottom_popup(&app.chat_widget, /*width*/ 80)
|
||||
@@ -284,7 +284,7 @@ async fn daemon_menu_is_read_only_and_confirmation_can_cancel_or_handoff() {
|
||||
));
|
||||
|
||||
app.daemon_cli_executable = None;
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
insta::assert_snapshot!(
|
||||
"daemon_no_cli_handoff",
|
||||
render_bottom_popup(&app.chat_widget, /*width*/ 80)
|
||||
@@ -312,7 +312,7 @@ async fn unavailable_daemon_menu_offers_guidance_without_update_actions() {
|
||||
is_local_daemon: false,
|
||||
is_managed_daemon: false,
|
||||
});
|
||||
app.open_daemon_menu();
|
||||
app.open_daemon_menu(/*policy_error*/ None);
|
||||
insta::assert_snapshot!(
|
||||
"daemon_remote_guidance",
|
||||
render_bottom_popup(&app.chat_widget, /*width*/ 80)
|
||||
@@ -321,3 +321,17 @@ async fn unavailable_daemon_menu_offers_guidance_without_update_actions() {
|
||||
assert!(rx.try_recv().is_err());
|
||||
assert_eq!(app.pending_update_action, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn managed_policy_removes_daemon_update_actions() {
|
||||
let mut app = make_test_app().await;
|
||||
app.daemon_cli_executable =
|
||||
Some(AbsolutePathBuf::from_absolute_path(std::env::current_exe().unwrap()).unwrap());
|
||||
app.open_daemon_menu(Some(
|
||||
"Daemon updates are disabled by managed policy (features.daemon_updates = false).",
|
||||
));
|
||||
insta::assert_snapshot!(
|
||||
"daemon_updates_disabled",
|
||||
render_bottom_popup(&app.chat_widget, /*width*/ 80)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -230,7 +230,16 @@ impl App {
|
||||
event => (event, None),
|
||||
};
|
||||
match event {
|
||||
AppEvent::OpenDaemonMenu => self.open_daemon_menu(),
|
||||
AppEvent::OpenDaemonMenu => {
|
||||
let policy_error = if self.daemon_cli_executable.is_some()
|
||||
&& !matches!(self.app_server_target, AppServerTarget::Remote { .. } | AppServerTarget::Cloud)
|
||||
{
|
||||
codex_app_server_daemon::ensure_updates_allowed().await.err().map(|error| error.to_string())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.open_daemon_menu(policy_error.as_deref());
|
||||
}
|
||||
AppEvent::RemoteControl(_) | AppEvent::RemoteControlForBackend { .. } | AppEvent::RemoteControlFinished { .. } => {}
|
||||
AppEvent::ConfirmDaemonRestart => self.confirm_daemon_restart(),
|
||||
AppEvent::RunDaemonRestart => {
|
||||
@@ -244,8 +253,17 @@ impl App {
|
||||
)));
|
||||
}
|
||||
}
|
||||
AppEvent::ConfirmDaemonUpdate(source) => self.confirm_daemon_update(source),
|
||||
AppEvent::ConfirmDaemonUpdate(source) => {
|
||||
match codex_app_server_daemon::ensure_updates_allowed().await {
|
||||
Ok(()) => self.confirm_daemon_update(source),
|
||||
Err(error) => self.chat_widget.add_error_message(error.to_string()),
|
||||
}
|
||||
}
|
||||
AppEvent::RunDaemonUpdate(source) => {
|
||||
if let Err(error) = codex_app_server_daemon::ensure_updates_allowed().await {
|
||||
self.chat_widget.add_error_message(error.to_string());
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
self.pending_update_action = Some(UpdateAction::Daemon(source));
|
||||
return Ok(self.handle_exit_mode(app_server, ExitMode::Immediate).await);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use codex_app_server_protocol::ThreadBackgroundTerminalsListResponse as ListResp
|
||||
pub(super) fn background_terminals_blocker(
|
||||
result: Result<ListResponse, TypedRequestError>,
|
||||
target: &AppServerTarget,
|
||||
features: &codex_features::Features,
|
||||
) -> Option<&'static str> {
|
||||
match result {
|
||||
Ok(response) if response.data.is_empty() => None,
|
||||
@@ -24,9 +25,11 @@ pub(super) fn background_terminals_blocker(
|
||||
&& (source.message.contains("unknown variant")
|
||||
|| source.message.contains("unknown method"))) =>
|
||||
{
|
||||
Some(
|
||||
"The local Codex service cannot check background terminals. Run `codex app-server daemon update`, then restart Codex.",
|
||||
)
|
||||
Some(if features.enabled(Feature::DaemonUpdates) {
|
||||
"The local Codex service cannot check background terminals. Run `codex app-server daemon update`, then restart Codex."
|
||||
} else {
|
||||
"The local Codex service cannot check background terminals. Contact your administrator to update it."
|
||||
})
|
||||
}
|
||||
_ => Some("Active background terminals block /cd."),
|
||||
}
|
||||
@@ -35,6 +38,7 @@ pub(super) fn background_terminals_blocker(
|
||||
pub(super) async fn check_background_terminals(
|
||||
app_server: &mut AppServerSession,
|
||||
target: &AppServerTarget,
|
||||
features: &codex_features::Features,
|
||||
thread_ids: impl IntoIterator<Item = ThreadId>,
|
||||
) -> Option<&'static str> {
|
||||
for thread_id in thread_ids {
|
||||
@@ -50,7 +54,7 @@ pub(super) async fn check_background_terminals(
|
||||
.request_handle()
|
||||
.request_typed::<ListResponse>(request)
|
||||
.await;
|
||||
if let Some(message) = background_terminals_blocker(result, target) {
|
||||
if let Some(message) = background_terminals_blocker(result, target, features) {
|
||||
return Some(message);
|
||||
}
|
||||
}
|
||||
@@ -153,8 +157,13 @@ impl App {
|
||||
.iter()
|
||||
.filter_map(|(id, agent)| (!agent.is_closed).then_some(*id)),
|
||||
);
|
||||
if let Some(message) =
|
||||
check_background_terminals(app_server, &self.app_server_target, ids).await
|
||||
if let Some(message) = check_background_terminals(
|
||||
app_server,
|
||||
&self.app_server_target,
|
||||
&self.config.features,
|
||||
ids,
|
||||
)
|
||||
.await
|
||||
{
|
||||
return self.working_directory_error(message);
|
||||
}
|
||||
|
||||
@@ -705,6 +705,7 @@ impl App {
|
||||
if let Some((notice, key)) = crate::status::remote_connection::pending_server_version_notice(
|
||||
&self.local_settings.tui,
|
||||
&self.app_server_target,
|
||||
self.config.features.enabled(Feature::DaemonUpdates),
|
||||
app_server.server_codex_home(),
|
||||
client_version,
|
||||
app_server.server_version(),
|
||||
|
||||
@@ -12,9 +12,12 @@ use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::RemoteControlConnectionStatus;
|
||||
use codex_app_server_protocol::RemoteControlPairingStartParams;
|
||||
use codex_app_server_protocol::RemoteControlPairingStartResponse;
|
||||
use codex_features::Feature;
|
||||
use std::time::Duration;
|
||||
|
||||
const OPERATION_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 30);
|
||||
const ADMIN_UPDATE_GUIDANCE: &str =
|
||||
"Contact your administrator to update the background server for persistent remote control.";
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) enum Action {
|
||||
@@ -188,9 +191,10 @@ pub(super) fn handle(app: &mut App, backends: &BackendSessions, event: AppEvent)
|
||||
app.remote_control_pending = true;
|
||||
let backend_id = daemon.backend_id();
|
||||
let tx = app.app_event_tx.app_event_tx.clone();
|
||||
let updates_allowed = app.config.features.enabled(Feature::DaemonUpdates);
|
||||
tokio::spawn(async move {
|
||||
let operation = async {
|
||||
match verified_daemon_session(endpoint.as_path(), backend_id).await {
|
||||
match verified_daemon_session(endpoint.as_path(), backend_id, updates_allowed).await {
|
||||
Ok((session, settings_file)) => {
|
||||
let mut result = run(session, action).await;
|
||||
let expected = match (&action, &result) {
|
||||
@@ -244,6 +248,7 @@ async fn bounded(action: Action, operation: impl std::future::Future<Output = Ou
|
||||
async fn verified_daemon_session(
|
||||
endpoint: &std::path::Path,
|
||||
backend_id: BackendId,
|
||||
updates_allowed: bool,
|
||||
) -> Result<(AppServerSession, std::path::PathBuf), String> {
|
||||
let status = codex_app_server_daemon::run(codex_app_server_daemon::LifecycleCommand::Version)
|
||||
.await
|
||||
@@ -285,9 +290,12 @@ async fn verified_daemon_session(
|
||||
|| semver::Version::parse("0.163.0-alpha.2").is_ok_and(|minimum| v >= minimum)
|
||||
});
|
||||
if !supported {
|
||||
return Err(
|
||||
"Update the background server with /daemon to use persistent remote control.".into(),
|
||||
);
|
||||
return Err(if updates_allowed {
|
||||
"Update the background server with /daemon to use persistent remote control."
|
||||
} else {
|
||||
ADMIN_UPDATE_GUIDANCE
|
||||
}
|
||||
.into());
|
||||
}
|
||||
let home = status
|
||||
.socket_path
|
||||
|
||||
@@ -68,6 +68,8 @@ async fn rc_menu_snapshot() {
|
||||
);
|
||||
chat.show_selection_view(pairing("ABCD-EFGH".into()));
|
||||
views.push(render_bottom_popup(&chat, /*width*/ 80));
|
||||
chat.show_selection_view(menu(/*connection*/ None, ADMIN_UPDATE_GUIDANCE));
|
||||
views.push(render_bottom_popup(&chat, /*width*/ 80));
|
||||
insta::assert_snapshot!("rc_menu", views.join("\n\n"));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ impl App {
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.server_version_notice = server_version.and_then(|server| {
|
||||
let guidance = if matches!(self.app_server_target, AppServerTarget::LocalDaemon { .. })
|
||||
&& self.config.features.enabled(Feature::DaemonUpdates)
|
||||
{
|
||||
" · /daemon"
|
||||
} else {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
---
|
||||
source: tui/src/app/daemon_menu_tests.rs
|
||||
expression: "render_bottom_popup(&app.chat_widget, 80)"
|
||||
---
|
||||
Daemon
|
||||
Not connected to the local background server.
|
||||
Daemon updates are disabled by managed policy (features.daemon_updates =
|
||||
false).
|
||||
|
||||
|
||||
› Restart background server
|
||||
|
||||
enter select · esc back
|
||||
@@ -46,3 +46,12 @@ expression: "views.join(\"\\n\\n\")"
|
||||
› 1. Done
|
||||
|
||||
enter select · esc back
|
||||
|
||||
Remote control
|
||||
Contact your administrator to update the background server for persistent
|
||||
remote control.
|
||||
|
||||
|
||||
› Enable (disabled)
|
||||
|
||||
enter select · esc back
|
||||
|
||||
@@ -498,6 +498,7 @@ impl App {
|
||||
crate::status::remote_connection::pending_server_version_notice(
|
||||
&local_settings.tui,
|
||||
&app_server_target,
|
||||
config.features.enabled(Feature::DaemonUpdates),
|
||||
app_server.server_codex_home(),
|
||||
CODEX_CLI_VERSION,
|
||||
app_server.server_version(),
|
||||
|
||||
@@ -112,6 +112,7 @@ async fn reconnect_restores_history_permissions_and_resumes_unsent_input() -> Re
|
||||
let (notice, key) = crate::status::remote_connection::pending_server_version_notice(
|
||||
&app.local_settings.tui,
|
||||
&app.app_server_target,
|
||||
app.config.features.enabled(Feature::DaemonUpdates),
|
||||
/*server_home*/ None,
|
||||
"2.1.0",
|
||||
Some("2.0.0"),
|
||||
|
||||
@@ -21,9 +21,11 @@ fn old_local_daemon_worktree_error_suggests_update() -> Result<()> {
|
||||
},
|
||||
})
|
||||
};
|
||||
let mut features = codex_features::Features::with_defaults();
|
||||
let message = managed_worktree_creation::background_terminals_blocker(
|
||||
missing_method(-32601, "method not found"),
|
||||
&target,
|
||||
&features,
|
||||
)
|
||||
.expect("unsupported daemon must block worktree creation");
|
||||
let cell = crate::history_cell::new_error_event(message.to_string());
|
||||
@@ -38,6 +40,7 @@ fn old_local_daemon_worktree_error_suggests_update() -> Result<()> {
|
||||
"Invalid request: unknown variant `thread/backgroundTerminals/list`"
|
||||
),
|
||||
&target,
|
||||
&features,
|
||||
),
|
||||
Some(message),
|
||||
);
|
||||
@@ -45,6 +48,7 @@ fn old_local_daemon_worktree_error_suggests_update() -> Result<()> {
|
||||
managed_worktree_creation::background_terminals_blocker(
|
||||
missing_method(-32600, "Invalid request: unknown variant `another/method`"),
|
||||
&target,
|
||||
&features,
|
||||
),
|
||||
Some("Active background terminals block /cd."),
|
||||
);
|
||||
@@ -52,6 +56,7 @@ fn old_local_daemon_worktree_error_suggests_update() -> Result<()> {
|
||||
managed_worktree_creation::background_terminals_blocker(
|
||||
missing_method(-32601, "method not found"),
|
||||
&AppServerTarget::Embedded,
|
||||
&features,
|
||||
),
|
||||
Some("Active background terminals block /cd."),
|
||||
);
|
||||
@@ -62,8 +67,21 @@ fn old_local_daemon_worktree_error_suggests_update() -> Result<()> {
|
||||
next_cursor: None,
|
||||
}),
|
||||
&target,
|
||||
&features,
|
||||
),
|
||||
None,
|
||||
);
|
||||
features.disable(Feature::DaemonUpdates);
|
||||
let message = managed_worktree_creation::background_terminals_blocker(
|
||||
missing_method(-32601, "method not found"),
|
||||
&target,
|
||||
&features,
|
||||
)
|
||||
.expect("unsupported daemon must block worktree creation");
|
||||
let cell = crate::history_cell::new_error_event(message.to_string());
|
||||
insta::assert_snapshot!(
|
||||
lines_to_single_string(&cell.display_lines(/*width*/ 120)),
|
||||
@"■ The local Codex service cannot check background terminals. Contact your administrator to update it."
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@ impl App {
|
||||
if let Some(message) = check_background_terminals(
|
||||
app_server,
|
||||
&self.app_server_target,
|
||||
&self.config.features,
|
||||
tracked_ids.iter().copied(),
|
||||
)
|
||||
.await
|
||||
@@ -442,8 +443,13 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(message) =
|
||||
check_background_terminals(app_server, &self.app_server_target, tracked_ids).await
|
||||
if let Some(message) = check_background_terminals(
|
||||
app_server,
|
||||
&self.app_server_target,
|
||||
&self.config.features,
|
||||
tracked_ids,
|
||||
)
|
||||
.await
|
||||
{
|
||||
return self.working_directory_error(message);
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tui/src/history_cell/tests.rs
|
||||
expression: "render_lines(&cell.transcript_lines(100)).join(\"\\n\")"
|
||||
---
|
||||
⚠ A background Codex service is running v0.152.1, older than your Codex CLI v0.153.0.
|
||||
@@ -53,6 +53,7 @@ fn connected_server_version_notice_snapshot() {
|
||||
let (notice, _) = crate::status::remote_connection::pending_server_version_notice(
|
||||
&settings,
|
||||
&target,
|
||||
/*daemon_updates_allowed*/ true,
|
||||
/*server_home*/ None,
|
||||
"0.153.0",
|
||||
Some("0.152.1"),
|
||||
@@ -78,14 +79,26 @@ fn local_daemon_version_notice_snapshot() {
|
||||
show_server_version_notice: true,
|
||||
..Default::default()
|
||||
};
|
||||
for (client, server, snapshot) in [
|
||||
("0.153.0", "0.152.1", "local_daemon_version_notice_snapshot"),
|
||||
("0.155.0-alpha.12", "0.156.0", "local_daemon_alpha_mismatch"),
|
||||
("0.0.0", "0.156.0", "local_daemon_source_mismatch"),
|
||||
for (client, server, updates_allowed, snapshot) in [
|
||||
(
|
||||
"0.153.0",
|
||||
"0.152.1",
|
||||
true,
|
||||
"local_daemon_version_notice_snapshot",
|
||||
),
|
||||
(
|
||||
"0.155.0-alpha.12",
|
||||
"0.156.0",
|
||||
true,
|
||||
"local_daemon_alpha_mismatch",
|
||||
),
|
||||
("0.0.0", "0.156.0", true, "local_daemon_source_mismatch"),
|
||||
("0.153.0", "0.152.1", false, "local_daemon_updates_disabled"),
|
||||
] {
|
||||
let (notice, _) = crate::status::remote_connection::pending_server_version_notice(
|
||||
&settings,
|
||||
&target,
|
||||
updates_allowed,
|
||||
/*server_home*/ None,
|
||||
client,
|
||||
Some(server),
|
||||
|
||||
@@ -147,6 +147,7 @@ pub(crate) fn server_version_notice_key(
|
||||
pub(crate) fn pending_server_version_notice(
|
||||
settings: &codex_config::types::Tui,
|
||||
target: &AppServerTarget,
|
||||
daemon_updates_allowed: bool,
|
||||
server_home: Option<&str>,
|
||||
client: &str,
|
||||
server: Option<&str>,
|
||||
@@ -155,7 +156,8 @@ pub(crate) fn pending_server_version_notice(
|
||||
let message = server_version_notice_for_tui(settings, client, server)?;
|
||||
let notice = ServerVersionNotice {
|
||||
message,
|
||||
offer_update: matches!(target, AppServerTarget::LocalDaemon { .. }),
|
||||
offer_update: daemon_updates_allowed
|
||||
&& matches!(target, AppServerTarget::LocalDaemon { .. }),
|
||||
};
|
||||
let key = server_version_notice_key(target, server_home, client, server)?;
|
||||
(last_shown != Some(key.as_str())).then_some((notice, key))
|
||||
@@ -278,6 +280,7 @@ mod tests {
|
||||
pending_server_version_notice(
|
||||
&settings,
|
||||
target,
|
||||
/*daemon_updates_allowed*/ true,
|
||||
/*server_home*/ None,
|
||||
"0.153.0-alpha.10.1",
|
||||
Some("0.153.0-alpha.9.2"),
|
||||
|
||||
Reference in New Issue
Block a user