Skip to content

ux/safety: uninstall_codex_at deletes RTK.md before patching AGENTS.md — half-mutated state on second-step failure #26

Closed

Description

@thehoff

Summary

uninstall_codex_at() (src/hooks/init.rs:870-922) removes the canonical/legacy markdown files first (~lines 880-898), then patches AGENTS.md (~lines 900+). If the second step fails (filesystem full, permission flip, signal during the write), the user is left with AGENTS.md still importing @CONTEXTCRAWLER.md or @RTK.md while the actual file is gone — Codex will then log warnings on every load.

Caught by adversarial codex review of today's commit range, independently confirmed.

Severity

Low. Correctness/UX bug, not a security boundary cross — no privilege escalation, no data exposure. But it leaves the user in a state where init --show reports an inconsistent install and uninstall cannot easily be re-run to recover (the file it needed to delete is already gone).

Fix (proposed)

Reorder the operations so AGENTS.md mutation happens first and the file deletes only happen if the AGENTS.md write succeeded:

  1. Read AGENTS.md, compute the desired new content
  2. atomic_write AGENTS.md (succeeds or fails atomically)
  3. Only on success, delete the on-disk md files
  4. If AGENTS.md write fails, return the error with the on-disk files still intact — user can re-run uninstall and we'll detect the same state again

Idempotency is already a goal of this function; this just makes the failure mode also recoverable.

Out of scope

The reverse ordering question (atomic across both ops) — we don't have a transactional fs primitive, but at least the proposed ordering puts the irreversible step last.

Test plan

  • Existing test_uninstall_codex_at_is_idempotent still passes
  • New test: inject an AGENTS.md write error (e.g. read-only fixture dir), verify the md file was NOT deleted
  • Regression-check: AGENTS.md mutation visible BEFORE md file deleted in the happy path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions