mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve standalone release pins during daemon updates (#43521)
## Why Bootstrapping the app-server daemon should preserve an explicitly selected release, even when that version is currently `latest`. Older managed binaries should also be able to serve app-server without supporting the updater command. ## What changed - Record `latest` selections in `auto-update-version` in both standalone installers and clear the marker for explicit releases. - Start the daemon updater only for a marked stable release whose binary supports `pid-update-loop`. Existing installs without a marker require a new `latest` installation to enable automatic updates. - Recheck the selected release under the install lock so an in-flight update cannot overwrite a new pin, including installer calls from older updaters. Recheck selection before restarting app-server or replacing the updater. - Cancel Unix installer process groups and clean up their owned fallback locks when the updater stops. ## Testing Add coverage for channel markers, explicit pins of the current latest version, older updater guards, updater command support, and Unix installer cancellation with child-process and lock cleanup. GitOrigin-RevId: 4d275237bd77d896bf64dc1b85a5bca3608142c7
This commit is contained in:
1 parent
b1205c12d5
commit
adee0b04fa
9 files changed
+608
-33
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
@@ -10,6 +12,7 @@ use sha2::Digest;
|
||||
use sha2::Sha256;
|
||||
use tokio::fs;
|
||||
use tokio::process::Command;
|
||||
use tokio::time::timeout;
|
||||
|
||||
/// Returns the packaged executable when present, otherwise an existing legacy executable.
|
||||
/// If neither exists, returns the expected packaged path on Windows and preserves the
|
||||
@@ -30,6 +33,64 @@ pub(crate) fn managed_codex_bin(codex_home: &Path) -> PathBuf {
|
||||
}
|
||||
}
|
||||
|
||||
/// Only latest-channel stable releases may run the public latest-version updater.
|
||||
pub(crate) fn is_stable_standalone_release(codex_home: &Path, codex_bin: &Path) -> bool {
|
||||
let standalone = codex_home.join("packages/standalone");
|
||||
let Ok(releases) = std::fs::canonicalize(standalone.join("releases")) else {
|
||||
return false;
|
||||
};
|
||||
let Ok(release) = std::fs::canonicalize(standalone.join("current")) else {
|
||||
return false;
|
||||
};
|
||||
if release.parent() != Some(releases.as_path()) {
|
||||
return false;
|
||||
}
|
||||
let Some(release_name) = release.file_name().and_then(|name| name.to_str()) else {
|
||||
return false;
|
||||
};
|
||||
let targets = [
|
||||
"aarch64-apple-darwin",
|
||||
"x86_64-apple-darwin",
|
||||
"aarch64-unknown-linux-musl",
|
||||
"x86_64-unknown-linux-musl",
|
||||
"aarch64-pc-windows-msvc",
|
||||
"x86_64-pc-windows-msvc",
|
||||
];
|
||||
let Some(version) = targets
|
||||
.iter()
|
||||
.find_map(|target| release_name.strip_suffix(&format!("-{target}")))
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let components: Vec<_> = version.split('.').collect();
|
||||
components.len() == 3
|
||||
&& components.iter().all(|component| {
|
||||
!component.is_empty() && component.bytes().all(|byte| byte.is_ascii_digit())
|
||||
})
|
||||
&& std::fs::read_to_string(standalone.join("auto-update-version"))
|
||||
.is_ok_and(|selected| selected == release_name)
|
||||
&& std::fs::canonicalize(codex_bin).is_ok_and(|bin| bin.starts_with(&release))
|
||||
}
|
||||
|
||||
/// Older managed binaries can serve app-server requests without owning an updater.
|
||||
pub(crate) async fn supports_daemon_update_loop(codex_bin: &Path) -> bool {
|
||||
let mut command = Command::new(codex_bin);
|
||||
#[cfg(windows)]
|
||||
command.creation_flags(windows_sys::Win32::System::Threading::CREATE_NO_WINDOW);
|
||||
timeout(
|
||||
Duration::from_secs(5),
|
||||
command
|
||||
.args(["app-server", "daemon", "pid-update-loop", "--help"])
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.kill_on_drop(true)
|
||||
.status(),
|
||||
)
|
||||
.await
|
||||
.is_ok_and(|result| result.is_ok_and(|status| status.success()))
|
||||
}
|
||||
|
||||
pub(crate) async fn resolved_managed_codex_bin(codex_bin: &Path) -> Result<PathBuf> {
|
||||
fs::canonicalize(codex_bin).await.with_context(|| {
|
||||
format!(
|
||||
|
||||
Reference in new issue
Block a user