Skip to content

fix(uninstall): reorder uninstall_codex_at — AGENTS.md before file deletes (#26) - #65

Merged
thehoff merged 1 commit into
developfrom
fix/uninstall-codex-ordering-26
May 18, 2026
Merged

thehoff merged 1 commit into
developfrom
fix/uninstall-codex-ordering-26

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #26 — uninstall_codex_at deleted CONTEXTCRAWLER.md before patching AGENTS.md. If the patch failed, the user was left with files gone but AGENTS.md still importing them → Codex warned on every load AND re-running uninstall failed (delete-of-missing-file).

Fix

  1. Reorder: patch AGENTS.md FIRST, delete files SECOND.
  2. Collapse mutations: both AGENTS.md edits (block removal + @-reference strip) now happen in ONE read + ONE atomic_write instead of two separate writes (close the smaller half-mutated window).
  3. Inline orphan helper: remove_rtk_reference_from_agents had no other callers; body moved into the orchestrator.

New failure shapes

  • patch fails → nothing removed, safe to rerun
  • patch succeeds → both phases complete (file deletes after atomic_write are nearly always trivial)

Pinning test

test_uninstall_codex_at_patches_agents_md_before_deleting_files — fixture has both a block AND a separate @-ref + the file; asserts all 3 mutations land and the file gets deleted. The 5 pre-existing test_uninstall_codex_at_* tests still pass alongside.

Verified

  • cargo build clean, 0 warnings
  • cargo test --bin contextcrawler — 2117 pass, 0 fail
  • All 9 integration suites green

Closes #26.

…deleting files (#26)

The previous `delete-then-patch` order left users in an inconsistent
state if the AGENTS.md patch failed (filesystem full, permission flip,
signal during write): CONTEXTCRAWLER.md / RTK.md was already gone but
AGENTS.md still imported the deleted path. Codex then warned on every
load AND re-running `uninstall` failed because the helper tried to
delete files that no longer existed.

## Fix

Two changes in `uninstall_codex_at`:

1. **Reorder**: patch AGENTS.md FIRST, delete files SECOND. The new
   failure shapes are clean:
   - patch fails    -> nothing removed, safe to rerun
   - patch succeeds -> both phases complete (file deletes after the
                       atomic_write are nearly always trivial; AGENTS.md
                       is the contended step)

2. **Collapse mutations**: the block-removal and @-reference-strip
   were two separate atomic_writes, leaving a tiny window where the
   block was gone but the @-reference remained. Both now happen in
   one read + one atomic_write — single point of failure with clean
   rollback semantics.

The standalone `remove_rtk_reference_from_agents` helper had no other
callers; its body was inlined into `uninstall_codex_at` and the helper
was removed. The same tests that covered it now cover the inlined
logic via the orchestrator.

## Pinning test

`test_uninstall_codex_at_patches_agents_md_before_deleting_files`:
- Sets up AGENTS.md with both a `<rtk-instructions>` block AND a
  separate `@CONTEXTCRAWLER.md` line + the actual CONTEXTCRAWLER.md
  file.
- Runs uninstall.
- Asserts: AGENTS.md is fully clean (both mutations applied),
  CONTEXTCRAWLER.md is deleted, and the `removed` Vec contains
  entries for all three operations.

## Verified

- cargo build clean: 0 warnings
- cargo test --bin contextcrawler: 2117 pass / 0 fail
- 5/5 existing test_uninstall_codex_at_* still pass alongside the new pin
- All 9 integration suites green

Closes #26.
@thehoff
thehoff merged commit 0eb0d99 into develop May 18, 2026
3 checks passed
@thehoff
thehoff deleted the fix/uninstall-codex-ordering-26 branch May 18, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant