The `codexupdate` launchd job cannot find the binary it installs when `bun pm bin -g` differs from `{{BUN_DIR}}` (verified on Homebrew bun)
What LifeOS does here
LIFEOS/TOOLS/com.lifeos.codexupdate.plist.template is the launchd job that keeps the Codex
CLI current. It runs LIFEOS/TOOLS/CodexUpdate.ts under bun on a schedule.
Current behavior
CodexUpdate.ts performs the update with
spawnSync("bun", ["install", "-g", `${PKG}@latest`], ...)
and reads the resulting version with
spawnSync("codex", ["--version"], ...)
Both are bare binary names, so both resolve through the job's PATH, which the plist defines
as:
<key>PATH</key>
<string>{{BUN_DIR}}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
bun install -g writes executables into bun's global bin directory, which is reported by
bun pm bin -g and defaults to ~/.bun/bin. {{BUN_DIR}} is a different thing: the directory
holding the bun binary itself.
Whether they coincide depends on how bun was installed. Bun's own installer places the binary
in ~/.bun/bin, so the two are the same path and the job works. Homebrew does not: {{BUN_DIR}}
expands to /opt/homebrew/bin while bun pm bin -g remains ~/.bun/bin, and the plist grants
only the former. Homebrew is the case we verified; other package managers may or may not
diverge the same way, and we did not test them.
On such an install the job therefore installs codex into a directory it cannot
search, and the subsequent spawnSync("codex", ["--version"]) fails to resolve: the job
cannot confirm what it just installed, and cannot read the installed version on any later run.
A bun globalBinDir override pointing at a directory already on the job's PATH, or a codex
binary independently present in /opt/homebrew/bin or /usr/local/bin from another package
manager, would also make resolution succeed on a Homebrew machine. Neither is guaranteed on a
default Homebrew bun installation, which is why the template should not depend on them. Note
that an independently installed codex masks the failure while making the reported version
refer to a different installation than the one the job just wrote.
Reproduction
On a macOS machine with Homebrew-installed bun, where the Codex CLI was installed by this job:
$ bun pm bin -g
/Users/<user>/.bun/bin
$ ls ~/.bun/bin/codex
/Users/<user>/.bun/bin/codex -> ../install/global/node_modules/@openai/codex/bin/codex.js
$ env -i PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin" sh -c 'command -v codex || echo NOT FOUND'
NOT FOUND
The third command uses the exact PATH the plist grants the job, with {{BUN_DIR}} expanded to
the Homebrew prefix. The binary the job installed is not on it.
Scope
We checked the other launchd templates in the payload before generalizing, and did not
generalize. Of the other fifteen *.plist* files shipped, only com.lifeos.commitmentsweep invokes bare
binaries from its payload (id, launchctl), and both resolve from /usr/bin and /bin,
which the templates already grant. codexupdate is the only job we found that installs a
binary with bun install -g and then invokes it by name.
Suggested direction
Add bun's global bin directory to the job PATH. The robust source for it is bun pm bin -g
evaluated at install time rather than a hardcoded ~/.bun/bin, since bun honors a configured
override. Adding ~/.local/bin would cover payloads that shell out to tooling installed by other
package managers; no shipped job needs it today, so that part is a suggestion rather than
part of the defect.
A suggested acceptance test: after the job runs its install step, command -v <installed binary> must succeed under the job's own PATH, not merely under an interactive login shell.
Affected versions
Present in v7.40.4, the current release at the time of writing. Not verified before that tag.
Landed: the installer resolves bun pm bin -g and puts it on the job's PATH via a new template token, so a bun-installed codex is found on Homebrew bun. Next release. Thanks.