Skip to content

fix(uninstall): report a safety rejection after consent as a failure (#4815) - #4844

Merged
Daniel Meppiel (danielmeppiel) merged 20 commits into
mainfrom
cloud-4815-safety-rejection-reported
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 20 commits into
mainfrom
cloud-4815-safety-rejection-reported

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

During apm uninstall --trust-lockfile, a file the preflight kept under consent could have its parent swapped for a symlink before cleanup. Cleanup's path-safety gate then refused it into skipped_unmanaged, and the historical consent-kept filter hid that refusal: hook sync reported no failure, and selected cleanup in commands/uninstall/cli.py released the file's ownership and finished with exit 0.

Fix (owner: integration/cleanup.py):

  • CleanupResult.rejected maps each path a safety gate refused in this cleanup to its reason (traversal, prefix, path safety check, directory entry, replaced since checked). Still also listed in skipped_unmanaged.
  • consent_outcome always reports rejected paths as failures and unsafe paths, whatever consent kept earlier.
  • SelectedCleanupOutcome.observer carries rejected_paths; _abort_if_retained_target_cleanup_paths never waives a failed or rejected path (nor the directories holding it), and names the reason in the error list.

Only current evidence-based retention stays exempt; consent semantics are unchanged.

Added scope (from #4815's follow-up comments, folded from closed #4828 and the #4650 review):

  • A file authorized at preflight and then replaced by a link is kept: consent_kept_link judges the current file kind, whatever the earlier verdict.
  • A consent-kept final link whose parent passes validate_deploy_path(allow_final_symlink=True) is retention, not a safety rejection. Symlinked ancestors are still rejected.
  • Under --trust-lockfile the kept-members warning names every file (the five-name cap stays without the flag).
  • test_consent_reads_case_variant_spellings_as_one_file moved into tests/unit/integration/test_cleanup_spelling_windows_compat.py (windows_compat, Windows lane), keeping its req-lk-024 link.
  • Copilot thread: under consent, a skill-directory member replaced by a final link after the scan is now kept (safe ancestors), not rejected. Red-first: test_consent_keeps_a_member_replaced_by_a_link_after_the_scan.
  • _consented is keyed by self._key(claim) (root-relative), so a user-scope lock listing one file both absolute and relative reports one deletion. Red-first: test_consent_reports_one_deletion_for_absolute_and_relative_spellings (before: two entries).
  • Copilot (ancestor above the skill directory): the member-link exception requires validate_deploy_path(..., allow_final_symlink=True) from the deploy root. The strict pre-unlink recheck now also runs the canonical gate, so a proven member reached through a skills root swapped for a link after the scan is never unlinked outside the root. Red-first: test_consent_rejects_a_member_link_under_a_symlinked_skills_root and test_consent_never_unlinks_a_member_moved_under_a_symlinked_skills_root (before: the outside file was deleted).
  • Case-variant cowork:// spellings under an external Cowork root (APM_COPILOT_COWORK_SKILLS_DIR outside the deploy root) are pooled through SpellingAliasIndex.aliases against the resolved Cowork root, so a conflicting hash under another spelling blocks consent. Red-first: test_consent_reads_case_variant_cowork_spellings_as_one_file (a hard link stands in for a case-insensitive filesystem; before the fix, consent was granted).
  • New architecture guard install-deployment-cleanup-spelling-aliases: DeploymentEvidence._equivalent_keys must call SpellingAliasIndex.aliases, and cleanup.py may not call samefile/normcase/casefold/physical_alias/stored_spelling. It has a mutation case and an entry in the runner's rule-id list.

Ported red-first cells (tests/spec_conformance/test_deletion_evidence_reqs.py), run on the earlier #4844 head (commit acaea08) before the fix:

  • test_consent_keeps_a_file_replaced_by_a_link_after_preflight: FAILED, path.is_symlink() False (the link was unlinked)
  • test_consent_names_every_kept_member_of_a_skill_directory: FAILED, "(and 2 more)"
  • test_selected_cleanup_keeps_an_unchanged_consent_kept_link_without_failing: FAILED, the link was reported in rejected_paths
  • test_consent_reports_a_safety_rejection_after_preflight_as_a_failure and test_selected_cleanup_never_releases_a_path_a_safety_gate_rejected: already green on fix(uninstall): report a safety rejection after consent as a failure (#4815) #4844, because its first fix covers them. They are ported as spec-level req-lk-024 cells.

Stacked on #4650 (base danielmeppiel-4295-uninstall-consent, rebased onto 9e63ec1): the consent code only exists there. Will retarget to main once #4650 lands.

Issue and approved scope

Issue: Fixes #4815

Human scope-approval comment: #4815 (apm-scope:v1 comment by Daniel Meppiel (@danielmeppiel))

Completes the approved scope. The other two deferred findings in the second issue comment (final-symlink kind recheck at cleanup.py ~431, kept-files warning cap) are out of the approved scope and not touched.

Type of change

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

Testing

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

Regression cell (swaps the kept file's parent for a symlink between preflight and cleanup). It is an in-process component test, like test_uninstall_hook_cleanup_failure.py, because the race must be injected between preflight and cleanup, which a subprocess binary cannot expose.

promise: P-OWN-file-level-deploy-sync-cleanup -- uninstall never reports a refused deletion as success and never drops ownership of a file left on disk
cell: OP=uninstall PRIM=skill SCOPE=project LOCK=present GATE=trust-lockfile-consent DEPLOYED=parent-symlinked-after-preflight
owner: src/apm_cli/integration/cleanup.py
instrument: today test -> tests/integration/test_uninstall_consent_safety_rejection.py::test_safety_rejection_after_consent_fails_and_keeps_ownership (new)
           + tests/unit/integration/test_cleanup_helper.py::test_safety_rejection_of_a_consent_kept_file_is_always_a_failure (hook-sync path, consent_outcome)
oracles: I1, I7, I8  decisive: exit_code == 1; "  - .agents/skills/alpha/SKILL.md" in output; lockfile still tracks it; outside file bytes unchanged; apm.yml still declares the package
failing-before (commit 8a3cc39, src reverted): uv run --extra dev pytest tests/integration/test_uninstall_consent_safety_rejection.py -> FAILED: assert 0 == 1 (output ended "[*] Uninstall complete: removed 1 package")
passing-after: same command -> 1 passed
guard+mutation: n/a     ledger: 4815
hints executed: none printed beyond "Resolve or remove the listed files, then retry uninstall."

Validation evidence (local; this PR targets a non-main base, so PR CI does not run until it is retargeted):

Command Result
uv run --extra dev pytest -n 4 tests/unit/integration/test_cleanup_helper.py tests/integration/test_uninstall_consent_safety_rejection.py tests/integration/test_uninstall_hook_cleanup_failure.py tests/unit/test_deployment_materialization_receipts.py tests/spec_conformance/test_deletion_evidence_reqs.py tests/unit/install/test_target_contraction_logging.py 166 passed, 2 skipped
uv run --extra dev pytest -n 8 tests/unit tests/spec_conformance -k "uninstall or cleanup or hook or consent or selected" 1794 passed; 36 failed only in tests/unit/install/test_unix_install_ownership.py, which also fails on the unmodified base in this sandbox (install-script environment)
uv run --extra dev pytest -n 8 tests/quality 635 passed
ruff check / ruff format --check (src, tests, architecture linter) clean
pylint R0801 10.00/10
bash scripts/lint-auth-signals.sh clean
scripts/check_complexity_ratchet.py --base-ref origin/danielmeppiel-4295-uninstall-consent clean
python -m tests.quality.taxonomy --changed tm006 clean
tests/spec_conformance/mode_b_detector.sh no critical-path diff
python -m tests.spec_conformance.gen_statement regenerated and committed (moved req cell)
pytest tests/integration/test_architecture_owner_rule_mutations.py -k spelling-aliases + scripts/lint_architecture_boundaries.py --root . 3 passed; linter exit 0
pytest -n 8 tests/unit/integration tests/spec_conformance + neighbours 3891 passed; 9 failed only from sandbox gpg commit signing in temp repos (test_mode_b_detector, test_resolution_reqs), unrelated
scripts/check_obligation_status_ratchet.py 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
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

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.

🟢 Approval recommended

No active review issues are reported for the fix preventing prior consent from masking cleanup safety rejections during uninstall.

No open issues 🎉

What changed in this PR

This PR fixes #4815 in the --trust-lockfile uninstall flow introduced by #4650. A cleanup safety rejection now remains a failure even if preflight consent previously kept the file, preventing a successful exit and loss of lockfile ownership.

Changes:

  • Record current safety-rejection reasons and propagate them through cleanup outcomes.
  • Make uninstall retain ownership and report rejected paths without applying the consent exemption.
  • Add regression coverage for a parent-symlink swap, a bug-ledger entry, and a changelog fragment.
File Description
tests/​unit/​integration/​test_cleanup_helper.py Tests that safety rejection overrides earlier consent-based retention.
tests/​integration/​test_uninstall_consent_safety_rejection.py Checks uninstall failure, preserved ownership, and unchanged file contents after a symlink swap.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4815.json Records the bug and its regression tests.
src/​apm_cli/​integration/​cleanup.py Records rejection reasons and includes rejected paths in failure outcomes.
src/​apm_cli/​install/​selected_cleanup.py Carries rejection reasons into selected-cleanup outcomes.
src/​apm_cli/​commands/​uninstall/​cli.py Prevents consent from hiding rejections and reports their reasons.
changelog.d/​4844.fixed.md Documents the corrected uninstall behavior.

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the cloud-4815-safety-rejection-reported branch from 489d5dc to 4bdacfb Compare November 23, 2026 08:05
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
apm-spec-waiver: bug fix inside the existing #4295 consent contract; a safety rejection is reported as a failure, no new normative behaviour

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

🔵 Needs a closer look

Safety-sensitive deletion outcomes depend on stacked PR #4650, and CI has not covered the final main-based merge state, so a maintainer should confirm race regressions and cleanup validation after retargeting.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the cloud-4815-safety-rejection-reported branch from 4bdacfb to e6d0413 Compare November 23, 2026 08:30
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
apm-spec-waiver: bug fix inside the existing #4295 consent contract; a safety rejection is reported as a failure, no new normative behaviour

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]>

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 remaining cleanup issue causes uninstall with --trust-lockfile to reject a safely replaced final symlink instead of preserving it under consent, and a directory-member replacement regression test is needed.

1 open issue

Review effort: Balanced

Comment thread src/apm_cli/integration/cleanup.py Resolved
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the cloud-4815-safety-rejection-reported branch from e6d0413 to 0421533 Compare November 23, 2026 08:43
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
apm-spec-waiver: bug fix inside the existing #4295 consent contract; a safety rejection is reported as a failure, no new normative behaviour

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]>

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 critical symlink-safety gap in cleanup can misclassify an unsafe path as consent retention, allowing selected uninstall to release ownership and exit successfully without revalidating the full ancestor chain.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/integration/cleanup.py Resolved

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.

🔵 Needs a closer look

Human assessment is needed because a post-scan symlink change can bypass ancestor validation and cause cleanup to delete a file outside the deploy root.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

…pt under consent (#4815)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ent (#4815)

A member whose ancestors are safe but which became a symbolic link after the scan is consent retention, not a safety rejection. Symlinked ancestors stay rejections.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…report one deletion (#4815)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
#4815)

A user-scope lock listing one file both as an absolute path and root-relative now reports one deletion after a single unlink.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…cal path gate (#4815)

A skill member that became a final link is consent retention only when validate_deploy_path with allow_final_symlink passes from the deploy root to its parent; a symlinked ancestor above the skill directory stays a rejection.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…te before unlinking (#4815)

The pre-unlink recheck stopped at the skill directory, so a proven member under a skills root swapped for a link after the scan could be unlinked outside the deploy root. Every member now also passes validate_deploy_path from the deploy root immediately before its unlink.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…re one file (#4815)

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…owork root (#4815)

Under an external Cowork root, cowork:// claims naming one file in another case now share hashes and owners through SpellingAliasIndex.aliases, so a conflicting hash under another spelling blocks --trust-lockfile consent.

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

🟢 Approval recommended

No active review issues were identified in the uninstall cleanup safety changes.

No open issues 🎉

Review effort: Balanced

Base automatically changed from danielmeppiel-4295-uninstall-consent to main November 23, 2026 12:48

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

The Cowork path validator ignores allow_final_symlink, incorrectly failing trusted-lockfile cleanup when a proven skill member is replaced by an external symlink despite safe ancestors, and needs a fix with regression coverage.

1 open issue

Review effort: Balanced

Comment thread src/apm_cli/integration/cleanup.py Resolved
…4815)

The quality ratchet (AQ003) needs each component test to observe a
user-visible outcome: a consent verdict never deletes the file, every
kept skill member keeps the user's bytes, and a refused Cowork claim
keeps its file.

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

🔵 Needs a closer look

Human assessment is needed because a critical symlink race can allow cleanup to delete files outside the deployment root after an earlier safety check has passed.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 958debd into main Nov 23, 2026
75 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the cloud-4815-safety-rejection-reported branch November 23, 2026 14:59
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.

uninstall: a safety rejection after preflight consent is reported as kept, not failed

2 participants