Index | Thread | Search

From:
David Uhden Collado <daviduhden@gmail.com>
Subject:
Re: [IMPROVEMENT] Integrate the app server daemon into devel/codex.
To:
ports@openbsd.org, kirill@korins.ky, stu@spacehopper.org
Date:
Wed, 14 Oct 2026 20:41:00 +0000

Download raw body.

Thread
Kirill A. Korinsky wrote:
> On Wed, 14 Oct 2026 21:56:00 +0200,
> David Uhden Collado <daviduhden@gmail.com> wrote:
>>
>> + #[cfg(unix)]
>> + async fn read_process_details(pid: u32) -> Result<(String, String)> {
>> +-    let output = Command::new("ps")
>> +-        .args(["-p", &pid.to_string(), "-o", "stat=", "-o", "lstart="])
>> ++    let mut command = Command::new("ps");
>> ++    command.args(["-p", &pid.to_string(), "-o", "stat=", "-o", "lstart="]);
>> ++    #[cfg(target_os = "openbsd")]
>> ++    command.env("LC_ALL", "C").env("TZ", "UTC");
>> ++    let output = command
>> +         .output()
>> +         .await
>> +         .context("failed to invoke ps for pid-managed app server")?;
> 
> Why this patch is specific for OpenBSD?
> 
>> ++/// A distributor-owned executable has no managed package or internal updater.
>> ++/// This is a build-time choice, so the runtime environment cannot redirect it.
>> ++pub(crate) fn system_codex_bin() -> Option<&'static Path> {
>> ++    option_env!("CODEX_SYSTEM_DAEMON_PATH")
>> ++        .filter(|path| !path.is_empty())
>> ++        .map(Path::new)
>> ++}
> 
> It is the same codex binary. Why do you need CODEX_SYSTEM_DAEMON_PATH?
> 
> Codex already uses path to itself.
> 
>> + /// Prepare a missing package while the caller holds the daemon operation lock.
>> + pub(super) async fn prepare(daemon: &Daemon, settings: &DaemonSettings) -> Result<()> {
>> ++    if let Some(path) = managed_install::system_codex_bin() {
>> ++        daemon.ensure_managed_codex_bin()?;
>> ++        let context = InstallContext::from_exe(
>> ++            cfg!(target_os = "macos"),
>> ++            Some(path),
>> ++            /*method_override*/ None,
>> ++        );
> 
> I very supprised to see target_os = "macos" in OpenBSD patch.
> 
>> ++        let expected = env!("CARGO_PKG_VERSION");
>> ++        anyhow::ensure!(
>> ++            manifest.version.to_string() == expected,
>> ++            "system Codex package version {} differs from CLI version {expected}; update the codex package with pkg_add -u",
>> ++            manifest.version
>> ++        );
>> ++        let version = tokio::time::timeout(
>> ++            std::time::Duration::from_secs(5),
>> ++            managed_install::managed_codex_version(path),
>> ++        )
>> ++        .await
>> ++        .context("timed out checking the system Codex executable version")??;
>> ++        anyhow::ensure!(
>> ++            version == expected,
>> ++            "system Codex executable version {version} differs from CLI version {expected}; update the codex package with pkg_add -u"
>> ++        );
>> ++        return Ok(());
> 
> Why have you invented version comparison?
> 
>> @@ -1,15 +0,0 @@
>> -Disable daemon auto start by default
>> -https://github.com/openai/codex/issues/48050
>> -
>> -Index: codex-rs/features/src/lib.rs
>> ---- codex-rs/features/src/lib.rs.orig
>> -+++ codex-rs/features/src/lib.rs
>> -@@ -992,7 +992,7 @@ pub const FEATURES: &[FeatureSpec] = &[
>> -         id: Feature::DaemonAutoStart,
>> -         key: "daemon_auto_start",
>> -         stage: Stage::Stable,
>> --        default_enabled: true,
>> -+        default_enabled: false,
>> -     },
>> -     FeatureSpec {
>> -         id: Feature::TranscriptV2,
> 
> Are you sure that switch it on by default is good idea?
> 
> You run codex and it spawn some background daemon which lay around.
> 

The ps change addresses process identification. OpenBSD uses the generic 
ps-based backend, which compares formatted lstart strings. Different 
timezone settings can produce different timestamps for the same process, 
causing incorrect PID validation. TZ=UTC ensures consistency, while 
LC_ALL=C keeps the environment predictable.

CODEX_SYSTEM_DAEMON_PATH identifies the package-owned executable at 
build time. Although it is the same binary, upstream expects a 
separately managed installation under CODEX_HOME. This avoids duplicate 
installations and prevents internal updates from bypassing pkg_add.

The macOS check is simply an argument to the existing cross-platform 
InstallContext API. It evaluates to false on OpenBSD.

The version checks ensure consistency between the package manifest, 
executable, and CLI. A separate check detects an outdated running daemon 
after pkg_add -u.

Finally, automatic startup is already the upstream default. The existing 
OpenBSD patch disables it because daemon installation was unsupported.

The daemon runs under the invoking user, not as an rc.d service, and can 
be stopped explicitly. I prefer preserving upstream behavior rather than 
introducing unnecessary OpenBSD-specific restrictions.