Skip to content

fix(uninstall): repair kept lock rows the way install records them (#4804) - #4811

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-4804-uninstall-lock-metadata
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-4804-uninstall-lock-metadata

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

When apm uninstall keeps a dependency because a surviving package still needs it, the repaired lock metadata now matches what a fresh apm install records:

  • Nearest-parent tie rule (deps/reachability.py): the walk keeps the first edge only until a later edge at the same depth and dev status offers a lower parent key, the same rule as APMDependencyResolver._select_nearest_parent.
  • Chained rescued roots (install/orphans.py): depths are computed over the repaired parent graph, parents before children, so for d -> e -> f with e and f both removed, f lands at depth 3, below e.
  • Dev status (install/orphans.py, applied in commands/uninstall/cli.py): the decision returns graph-wide dev status for the rescued subtree from the walk's dev_only. An entry stays production while any surviving production path reaches it. A partial walk only ever proves production.

Review follow-ups: the tie rule ranks by depth then parent key regardless of dev status (red-first cell test_uninstall_tie_rule_spans_production_and_dev_parents); dev status comes only from proven rescued_dev; the reinstall oracles pass --no-frozen so they are real under CI=true (module passes locally with CI=true). Deferred (metadata only): #4823 (virtual sibling identity), #4833 (graph-wide descendant parent/depth/dev).

No file is deleted and no lock row is kept by this change. The lockfile format and dependency resolution are unchanged.

Issue and approved scope

Issue: Fixes #4804

Human scope-approval comment: #4804 (comment)

Does this PR complete the issue, or what remains? It completes the issue.

apm-spec-waiver: uninstall lock-metadata repair mirrors existing install resolver rules; no OpenAPM-observable behaviour changes

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
promise: P-INV-I2 -- repeating a converged command changes no bytes: the lock after uninstall equals what a full install then writes (source: .agents/skills/apm-lifecycle-tests/SKILL.md)
cell: OP=uninstall SRC=git LOCK=consistent GRAPH={tie at equal depth, chained rescued roots, prod child under dev-only parent}   owner: src/apm_cli/install/orphans.py (decide_orphan_removal) + deps/reachability.py
instrument: today test -> tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py::{test_uninstall_reparents_to_the_nearest_parent_by_lowest_key, test_uninstall_of_chained_still_needed_roots_derives_depth_parent_first, test_uninstall_under_a_dev_only_parent_moves_the_subtree_to_dev} (extends the #4749 module)
oracles: [I2, I1]  decisive: lock bytes after uninstall == lock bytes after a following `apm install`; plus resolved_by == test/a, (e, f) depths (2, 3), f is_dev
failing-before: pytest <module> -k "nearest_parent or chained or dev_only_parent" -n 2 -> 3 failed
passing-after: same cells + tests/unit/test_deps_reachability.py, test_uninstall_shared_diamond_dependency.py, test_uninstall_transitive_cleanup.py, install/test_orphan_removal_owner.py -n 2 -> 48 passed
guard+mutation: n/a (no new owner, no guard change)     ledger: 4804
hints executed: none printed

Lint chain (local), all clean:

  • ruff check / format --check (0.15.12)
  • lint_architecture_boundaries.py --root .
  • pylint R0801: 10.00
  • lint-auth-signals
  • complexity ratchet
  • tests.quality.taxonomy --changed
  • check_test_assertions.py

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.

After apm uninstall keeps a dependency a surviving package still needs
(#4749), the repaired lock metadata now matches a fresh install:
- the reachability walk applies install's nearest-parent tie rule
  (lowest parent key at equal depth),
- depths are computed over the repaired parent graph, parents first,
  so chained rescued roots nest correctly,
- dev-only status is repaired across the rescued subtree while any
  surviving production path keeps an entry production.
Lifecycle cells assert the lock after uninstall is byte-identical to
what a following full apm install writes.

Fixes #4804

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) changed the base branch from danielmeppiel-4749-uninstall-keep-transitive-lock-row to main November 22, 2026 20:23

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

Unresolved reachability and parent-repair defects can incorrectly mark retained dependencies as dev-only and produce parent/depth metadata that changes on reinstall.

3 open issues
What changed in this PR

Extends the retained-dependency fix from #4765 to address #4804, aiming to make uninstall’s repaired lock metadata match what a fresh install records.

Changes:

  • Adds equal-depth parent tie-breaking to the reachability walk.
  • Computes rescued-subtree depths and dev status, then applies them during uninstall.
  • Adds three lifecycle regressions checking byte-identical lockfiles after reinstall, plus ledger and changelog entries.
File Description
tests/​integration/​test_uninstall_shared_direct_dependency_lifecycle.py Adds parent-tie, chained-depth, and dev-subtree regression cases.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4804.json Records the bug and links its regression tests.
src/​apm_cli/​install/​orphans.py Derives depth and dev-status repairs for rescued subtrees.
src/​apm_cli/​deps/​reachability.py Adds parent ranking for competing reachability edges.
src/​apm_cli/​commands/​uninstall/​cli.py Carries and applies the owner’s subtree metadata repairs.
changelog.d/​4811.fixed.md Describes the intended lock-metadata consistency fix.

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/deps/reachability.py Resolved
Comment thread src/apm_cli/install/orphans.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.

🟡 Changes recommended

Uninstall can leave incorrect dependency parents, depths, and production status in the lockfile, while the CI comparison can pass without verifying full-install consistency.

6 open issues

Review effort: Balanced

Comment thread src/apm_cli/commands/uninstall/cli.py Resolved
Comment thread src/apm_cli/install/orphans.py Resolved
… only from proof

Review follow-ups on #4811:
- The walk's nearest-parent rule ranks by depth then parent key,
  regardless of each path's dev status, as the resolver does; a
  lifecycle cell with production b and dev a both needing e asserts a
  byte-identical reinstall (red before: install rewrote resolved_by).
- Still-needed rows take dev status only from the decision's proven
  rescued_dev, never from the first edge's flag.
Virtual-sibling identity depth: #4823.

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.

Comment thread src/apm_cli/deps/reachability.py Resolved
Comment thread src/apm_cli/install/orphans.py Resolved
…esolves

Under CI=true an install with an existing lockfile defaults to frozen
and withholds lockfile writes, which made the byte-identical reinstall
oracle vacuous in CI.

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.

🟢 Approval recommended

The review identifies no active issues with the retained-dependency lock metadata repair.

No open issues 🎉

5 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 61f9d2a into main Nov 22, 2026
75 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4804-uninstall-lock-metadata branch November 22, 2026 23:24
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
… regenerate

Keeps #4843's native observation (a root half plus the enabledPlugins declaration half, native_gaps). Builds _surface_hits on train 5's entry-aware surfaces (JsonEntry, MergedHooks) and _observable. projected_cells keeps #4843's native projection plus the shared-root loose skill (#4559). #4751 fixed #4744, so the user-scope bin target-change cell drops its strict known and is required (known 9 -> 8, L15).

Co-authored-by: Copilot App <[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.

uninstall: re-derive parent, depth and dev status like install after a declaration-only removal

2 participants