mirror of
https://github.com/openai/codex.git
synced 2026-11-20 23:08:21 +00:00
Support managed daemon updates on Windows (#42392)
## What changed - Run the daemon update loop on Windows using the non-interactive PowerShell installer. - Restart the managed app server after updates and hand updater ownership to a changed managed executable through a readiness handshake. - Contain installer descendants in a Windows job while allowing app-server and successor updater processes to break away. - Preserve or restore PID ownership when successor startup fails, without terminating a process that reused the PID. ## Testing - Cover non-interactive installer success and script failure on Windows. - Cover updater handoff, readiness, rollback, inaccessible processes, and PID reuse. GitOrigin-RevId: 5178c01124b4dd86b507b53f5093ec9a9d48e12c
This commit is contained in:
1 parent
fe140d4c8e
commit
91608236ea
9 files changed
+469
-90
No files matched your search
@@ -16,7 +16,15 @@ use windows_sys::Win32::Foundation::WAIT_TIMEOUT;
|
||||
use windows_sys::Win32::Storage::FileSystem::LOCKFILE_EXCLUSIVE_LOCK;
|
||||
use windows_sys::Win32::Storage::FileSystem::LOCKFILE_FAIL_IMMEDIATELY;
|
||||
use windows_sys::Win32::Storage::FileSystem::LockFileEx;
|
||||
use windows_sys::Win32::System::JobObjects::AssignProcessToJobObject;
|
||||
use windows_sys::Win32::System::JobObjects::CreateJobObjectW;
|
||||
use windows_sys::Win32::System::JobObjects::IsProcessInJob;
|
||||
use windows_sys::Win32::System::JobObjects::JOB_OBJECT_LIMIT_BREAKAWAY_OK;
|
||||
use windows_sys::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
||||
use windows_sys::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
|
||||
use windows_sys::Win32::System::JobObjects::JobObjectExtendedLimitInformation;
|
||||
use windows_sys::Win32::System::JobObjects::SetInformationJobObject;
|
||||
use windows_sys::Win32::System::Threading::GetCurrentProcess;
|
||||
use windows_sys::Win32::System::Threading::GetProcessId;
|
||||
use windows_sys::Win32::System::Threading::GetProcessTimes;
|
||||
use windows_sys::Win32::System::Threading::OpenProcess;
|
||||
@@ -156,6 +164,33 @@ pub(crate) fn try_lock_file(file: &tokio::fs::File) -> Result<bool> {
|
||||
Err(err).context("failed to lock daemon state")
|
||||
}
|
||||
|
||||
// Keep installer descendants bounded by the updater's lifetime, while allowing
|
||||
// app-server launches and successor updaters to break away from this job.
|
||||
pub(crate) fn updater_job() -> Result<OwnedHandle> {
|
||||
let job = unsafe { CreateJobObjectW(std::ptr::null(), std::ptr::null()) };
|
||||
if job == 0 {
|
||||
return Err(io::Error::last_os_error()).context("failed to create updater job");
|
||||
}
|
||||
let owned = unsafe { OwnedHandle::from_raw_handle(job as _) };
|
||||
let mut limits: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = unsafe { std::mem::zeroed() };
|
||||
limits.BasicLimitInformation.LimitFlags =
|
||||
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_BREAKAWAY_OK;
|
||||
if unsafe {
|
||||
SetInformationJobObject(
|
||||
job,
|
||||
JobObjectExtendedLimitInformation,
|
||||
(&limits as *const JOBOBJECT_EXTENDED_LIMIT_INFORMATION).cast(),
|
||||
std::mem::size_of_val(&limits) as u32,
|
||||
)
|
||||
} == 0
|
||||
|| unsafe { AssignProcessToJobObject(job, GetCurrentProcess()) } == 0
|
||||
{
|
||||
return Err(io::Error::last_os_error())
|
||||
.context("failed to contain updater installer processes");
|
||||
}
|
||||
Ok(owned)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "windows_tests.rs"]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user