Make app-server daemon automatic updates configurable (#43542)

## Why

The managed daemon's updater used a fixed hourly cadence with no saved preference to disable automatic updates.

## What changed

- Read `updater.autoUpdateEnabled` and `updater.updateIntervalMinutes` from `CODEX_HOME/app-server-daemon/settings.json`, defaulting to enabled with a 60-minute interval. Keep the initial five-minute delay and require a positive interval.
- Apply the enabled preference during daemon lifecycle operations and re-read settings before updates and recurring waits. Preserve updater preferences and unknown fields when saving remote-control settings, using atomic file replacement.
- Signal the updater's process group on Unix so stopping it also terminates installer children. Allow daemon shutdown even when settings are malformed.
- Document updater configuration and remote-control preference behavior. Manual `codex update` remains unaffected.

## Testing

Add tests for settings preservation, interval validation, recurring waits, enabling and disabling updates across restart and bootstrap, Unix installer termination, and shutdown with malformed settings.

GitOrigin-RevId: 5dbb72c5939e9ced2390b3760a7265608c8b61a0
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-07 18:26:04 +00:00
1 parent cc737efd65
commit 7d8e2dd6c5
9 files changed
+441 -63

No files matched your search

@@ -0,0 +1,73 @@
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use super::DaemonSettings;
#[tokio::test]
async fn remote_control_save_preserves_updater_settings() {
let temp = TempDir::new().expect("temp dir");
let path = temp.path().join("settings.json");
tokio::fs::write(&path, r#"{"remoteControlEnabled":true}"#)
.await
.expect("write legacy settings");
let settings = DaemonSettings::load(&path).await.expect("load settings");
assert_eq!(
settings,
DaemonSettings {
remote_control_enabled: true,
..DaemonSettings::default()
}
);
tokio::fs::write(
&path,
r#"{"remoteControlEnabled":true,"updater":{"autoUpdateEnabled":false,"updateIntervalMinutes":17},"futureSetting":42}"#,
)
.await
.expect("write settings");
let updated = DaemonSettings {
remote_control_enabled: false,
..DaemonSettings::load(&path)
.await
.expect("load updater settings")
};
updated.save(&path).await.expect("save remote control");
assert_eq!(
serde_json::from_slice::<serde_json::Value>(
&tokio::fs::read(&path).await.expect("read settings")
)
.expect("parse settings"),
serde_json::json!({
"remoteControlEnabled": false,
"updater": {"autoUpdateEnabled": false, "updateIntervalMinutes": 17},
"futureSetting": 42,
})
);
}
#[tokio::test]
async fn update_interval_accepts_long_values_and_rejects_zero() {
let temp = TempDir::new().expect("temp dir");
let path = temp.path().join("settings.json");
for minutes in [u32::MAX, 0] {
tokio::fs::write(
&path,
serde_json::to_vec(&serde_json::json!({
"updater": {"updateIntervalMinutes": minutes},
}))
.expect("serialize invalid settings"),
)
.await
.expect("write invalid settings");
let loaded = DaemonSettings::load(&path).await;
if minutes == 0 {
assert!(loaded.is_err());
} else {
assert_eq!(
loaded.expect("load long interval").update_interval_minutes,
minutes
);
}
}
}