Skip to content

fix(uninstall): never hide a post-preflight safety rejection under --trust-lockfile - #4828

Closed
Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
danielmeppiel-4295-uninstall-consentfrom
danielmeppiel-4815-safety-rejection
Closed

Daniel Meppiel (danielmeppiel) wants to merge 2 commits into
danielmeppiel-4295-uninstall-consentfrom
danielmeppiel-4815-safety-rejection

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Closes the post-preflight race class from the #4650 review, in which a change on disk between apm uninstall preflight and cleanup was hidden by the consent-kept filter:

  1. A safety rejection after preflight is a failure. Cleanup records the current pass's path-safety rejections (failed path validation, a member replaced since the scan, a refused directory entry) in CleanupResult.unsafe. consent_outcome (hook sync) and SelectedCleanupOutcome.observer (selected cleanup) report them as failures that consent never waives, so uninstall fails and keeps the lock tracking the file instead of releasing ownership.
  2. A link that replaced a file after preflight is kept: under --trust-lockfile, cleanup checks the current file kind and keeps any symbolic link, whatever the earlier verdict.
  3. Kept-members warning names every file under consent: the five-name cap applies only without the flag.
  4. A consent-kept final link pointing outside is retention, not a failure, in selected cleanup, once its parent passes validate_deploy_path(allow_final_symlink=True). Symlinked ancestors are still rejected.

Deferred: a hook-sync failure after Step 9 drops the removed row (predates #4815, applies to any late sync failure) is tracked in #4851.

Stacked on #4650 (base danielmeppiel-4295-uninstall-consent). Merge order: lands after #4650, then retarget to main.

Issue and approved scope

Issue: Fixes #4815

Human scope-approval comment: #4815 (apm-scope:v1 record in the issue comments, plus the scope extension with 3 more items)

Does this PR complete the issue, or what remains? It completes it. The related late hook-sync claim gap is #4851.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Red-first cells in tests/spec_conformance/test_deletion_evidence_reqs.py (each fails on the base, passes here):

  • test_consent_reports_a_safety_rejection_after_preflight_as_a_failure (before: assert 0 >= 1, the error hidden)
  • test_selected_cleanup_never_releases_a_path_a_safety_gate_rejected (before: failed_paths == set())
  • test_uninstall_fails_and_keeps_tracking_a_path_a_safety_gate_rejected (before: DID NOT RAISE SystemExit): exit 1, outside content unchanged, the claim still in apm.lock.yaml
  • test_consent_keeps_a_file_replaced_by_a_link_after_preflight (before: the link was unlinked)
  • test_consent_names_every_kept_member_of_a_skill_directory (before: "(and 2 more)")
  • test_selected_cleanup_keeps_an_unchanged_consent_kept_link_without_failing (red at 0db9c25: the link was in failed_paths)

Bug-ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4815.json (tests/quality/test_lifecycle_bug_ledger.py: 2 passed).

Targeted run at the final head: pytest tests/spec_conformance/test_deletion_evidence_reqs.py tests/unit/install/test_target_contraction_logging.py tests/unit/core/test_remediation_block_proofs.py tests/unit/install/test_architecture_invariants.py tests/unit/integration/test_hook_integrator.py tests/unit/integration/test_cleanup*.py tests/unit/test_uninstall*.py: 1272 passed. The lint mirror (ruff 0.15.12, R0801, architecture boundaries, auth signals, complexity ratchet, assertion ratchet, taxonomy, changelog fragments) is clean.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Cleanup now records path-safety rejections of the current pass in
CleanupResult.unsafe. Hook sync and selected cleanup treat them as
failures that --trust-lockfile consent never waives, so a parent swapped
for a symlink after preflight fails the uninstall instead of releasing
ownership.

Refs #4815

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Late symlink rejections can still discard consent-kept hooks’ ownership claims during final reconciliation, and current regression tests do not verify that those claims remain persisted.

3 open issues
What changed in this PR

This PR follows #4650 by distinguishing current cleanup safety rejections from files intentionally kept under --trust-lockfile. It addresses #4815 by making those rejections visible as failures that consent cannot waive.

Changes:

  • Records path-safety rejections separately in CleanupResult.unsafe.
  • Propagates those rejections through hook-sync and selected-cleanup outcomes.
  • Adds regressions for a parent replaced by a symlink after preflight.
File Description
tests/​spec_conformance/​test_deletion_evidence_reqs.py Adds post-preflight symlink-race checks for both cleanup outcomes.
src/​apm_cli/​integration/​cleanup.py Tracks current safety rejections and excludes them from consent waivers.
src/​apm_cli/​install/​selected_cleanup.py Includes safety rejections in selected cleanup’s failed paths.

Review effort: Balanced

Comment thread src/apm_cli/integration/cleanup.py Resolved
Comment thread src/apm_cli/integration/cleanup.py Resolved
…eep consent-kept outside links

- under --trust-lockfile, cleanup judges the current file kind: a file
  replaced by a symbolic link after preflight is kept, never unlinked
- a consent-kept final link whose parent passes path validation is
  retention, not a safety failure, in selected cleanup
- under consent the kept-members warning names every file (no 5-name cap)
- command-level cell: a post-preflight safety rejection exits 1 and the
  lock keeps claiming the file
- bug-ledger row 4815, changelog fragment, CONFORMANCE regenerated

Fixes #4815

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A skill member replaced by a final symlink after scanning causes uninstall to fail even with --trust-lockfile instead of receiving consent-kept retention when its ancestors are safe.

1 open issue
3 resolved since last review

Review effort: Balanced

for member_rel, member in proven:
if not _member_still_safe(skill_dir, member):
result.skipped_unmanaged.append(member_rel)
result.unsafe.append(member_rel)
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Closing in favour of #4844, which covers #4815 (PGM decision). This branch keeps red-first cells for the scope extension that #4844 does not have (see tests/spec_conformance/test_deletion_evidence_reqs.py at 1b7812a): test_consent_keeps_a_file_replaced_by_a_link_after_preflight, test_consent_names_every_kept_member_of_a_skill_directory, test_selected_cleanup_keeps_an_unchanged_consent_kept_link_without_failing, and test_uninstall_fails_and_keeps_tracking_a_path_a_safety_gate_rejected.

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Red on #4844: a file replaced by a link after preflight is unlinked, the kept-members warning caps at five names under consent, and a consent-kept final link is reported as a safety rejection.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Red on #4844: a file replaced by a link after preflight is unlinked, the kept-members warning caps at five names under consent, and a consent-kept final link is reported as a safety rejection.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Red on #4844: a file replaced by a link after preflight is unlinked, the kept-members warning caps at five names under consent, and a consent-kept final link is reported as a safety rejection.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Red on #4844: a file replaced by a link after preflight is unlinked, the kept-members warning caps at five names under consent, and a consent-kept final link is reported as a safety rejection.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
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.

2 participants