#4809·herdr

macOS: herdr integration install fails with EPERM (Operation not permitted) when the existing config file's group cannot be preserved

Author: emirrtopalogluCreated Sep 30, 2026Updated Sep 30, 2026
Labelsmaintainer-neededp2macosintegrationstriaged

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:

rust
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.provenance xattr present.
  • herdr integration install codex failed repeatedly with the identical error (same machine, multiple attempts, incl. after updating to 0.9.3).
  • Replacing hooks.json with a byte-identical copy owned emir:staff (copy + rename) made the exact same command succeed immediately: SessionStart hook added, [features] hooks = true ensured — 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). fchown to a group the user cannot assign is the only EPERM source here — likely reproducible for any user whose config file carries a foreign group.

Expected / suggestions

  1. Treat group preservation as best-effort: if fchown fails with EPERM but uid matches and only the group cannot be assigned, proceed while keeping the current group (these are user-owned config files; group drift here is harmless).
  2. At minimum, produce a descriptive error, e.g. cannot preserve group 'wheel' for ~/.codex/hooks.json (EPERM).
  3. Ideally, herdr integration install/status should verify the hook is actually wired (entry present in the target config, enabled in e.g. Codex hooks.state) instead of reporting current from 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).