macOS: herdr integration install fails with EPERM (Operation not permitted) when the existing config file's group cannot be preserved
Summary
On macOS, herdr integration install codex failed with a bare:
Operation not permitted (os error 1)The hook script (~/.codex/herdr-agent-state.sh) was written, but ~/.codex/hooks.json was never updated, so the integration stayed unwired — while herdr integration status kept reporting codex: current (v8) (it only checks the script on disk). Same silent-broken-link class as #3680: nothing surfaces that the hook isn't actually registered.
Root cause
~/.codex/hooks.json was group-owned by wheel (gid 0), left behind by an earlier installer. The user's primary group is staff and they are not a member of wheel.
write_config_temporary in src/platform/macos.rs (v0.9.3, L147–L151) preserves the existing file's owner/group onto the staging file:
if (metadata.uid(), metadata.gid()) != (current.uid(), current.gid())
&& unsafe { libc::fchown(output.as_raw_fd(), metadata.uid(), metadata.gid()) } != 0
{
return Err(std::io::Error::last_os_error());
}fchown(fd, uid, wheel) returns EPERM for a non-root user who cannot assign that group, so the whole replacement aborts before the rename. The raw error carries no context — the user only sees Operation not permitted (os error 1).
Evidence
- Failing file:
-rw-r--r--@ 1 emir wheel ~/.codex/hooks.json— no ACLs, no file flags, no extra hard links;com.apple.provenancexattr present. herdr integration install codexfailed repeatedly with the identical error (same machine, multiple attempts, incl. after updating to 0.9.3).- Replacing
hooks.jsonwith a byte-identical copy ownedemir:staff(copy + rename) made the exact same command succeed immediately: SessionStart hook added,[features] hooks = trueensured — no other changes needed. - In isolation on the same file everything else in the path works for this user (open O_RDWR, rename-replace, chmod 755, append writes).
fchownto a group the user cannot assign is the onlyEPERMsource here — likely reproducible for any user whose config file carries a foreign group.
Expected / suggestions
- Treat group preservation as best-effort: if
fchownfails withEPERMbutuidmatches and only the group cannot be assigned, proceed while keeping the current group (these are user-owned config files; group drift here is harmless). - At minimum, produce a descriptive error, e.g.
cannot preserve group 'wheel' for ~/.codex/hooks.json (EPERM). - Ideally,
herdr integration install/statusshould verify the hook is actually wired (entry present in the target config, enabled in e.g. Codexhooks.state) instead of reportingcurrentfrom the script alone.
Environment
- macOS 26.5.2 (build 25F84), arm64
- herdr 0.9.3 (stable channel)
- Codex CLI 0.159.2, config at
~/.codex - Resolved locally by re-owning the file to
emir:staff(content byte-identical).
Source: herdrdev/herdr