Codex project install mutates skill and AGENTS.md before validating hooks.json
Summary
On graphifyy==0.9.32, a project-scoped Codex install is not atomic when an existing .codex/hooks.json is invalid.
graphify install --project --platform codex copies the Graphify skill and writes the Graphify section to AGENTS.md before _install_codex_hook() parses the existing hook configuration. The command then exits 1 as intended, but leaves the earlier mutations in place.
The hook file itself is correctly preserved. The problem is that validation occurs after other installation writes.
Affected version
- PyPI:
graphifyy==0.9.32 - Tag:
v0.9.32 - Commit:
00efd6e7969837ae4a9f11d8d504dcd3b20b09df - Reproduced with a project-scoped Codex install in a disposable Git repository and disposable home/config roots
Reproduce
$ git init disposable-repo
$ cd disposable-repo
$ printf '# Existing instructions\n' > AGENTS.md
$ mkdir -p .codex
$ printf '{ not valid json\n' > .codex/hooks.json
$ graphify install --project --platform codex
references -> .codex/skills/graphify/references
skill installed -> .codex/skills/graphify/SKILL.md
graphify section written to .../AGENTS.md
[graphify] refusing to modify .codex/hooks.json: not valid JSON (fix or move it and re-run)
$ echo $?
1
Observed
After the failed command:
.codex/hooks.jsonremains byte-identical, which is correct..codex/skills/graphify/**has already been installed.AGENTS.mdhas already received the Graphify section.- No automatic rollback occurs.
- An explicit
graphify uninstall --project --platform codexremoves the partial install and restores the tested fixture, but the failed install itself is not fail-closed.
The ordering is visible in _project_install(): it calls _copy_skill_file(), then _agents_install(); only inside _agents_install() does _install_codex_hook() call _read_settings_for_merge().
The existing invalid-JSON unit test exercises the hook installer directly, so it proves that the hook file is preserved but does not catch the preceding end-to-end mutations.
Expected
Before writing any project file, the Codex project installer should preflight every existing configuration file it will need to parse.
Either approach would satisfy the safety property:
- validate
.codex/hooks.jsonbefore copying the skill or editingAGENTS.md; or - make the complete project install transactional and roll back every Graphify-created mutation on failure.
An end-to-end regression test should assert that the repository file manifest and contents are byte-identical after this failure.
Related backup-retention behavior
A successful Codex install intentionally writes the rolling backup .codex/hooks.json.graphify-bak added for #2167. A normal Codex uninstall removes the Graphify hook but retains that backup.
That retention may be the correct recovery policy rather than a bug. It would still help to document it in install/uninstall output and define whether project-scoped uninstall offers a safe, explicit cleanup path. The backup can otherwise remain as an unexpected untracked copy of repository hook configuration.
Related: #2167, #2164, #401.
I can follow up with a focused test and PR if this preflight-first direction fits the project’s intended lifecycle semantics.