Repository navigation
fix(uninstall): repair kept lock rows the way install records them (#4804) - #4811
Daniel Meppiel (danielmeppiel) merged 6 commits into
Conversation
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]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 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
…ppiel-4804-uninstall-lock-metadata
There was a problem hiding this comment.
🟡 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
Apply parent repairs to affected descendants · New Preserve production status when partial walks cannot prove reachability · New Disable frozen mode in lifecycle install comparisons · New Disambiguate legacy parent edges for sibling virtual packages Preserve shortest parent paths across mixed production and dev installs Avoid marking roots dev-only when production parents are unreadable
Review effort: Balanced
… 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]>
There was a problem hiding this comment.
🟡 Changes recommended
Dependency removal still mishandles shortest-path propagation and shared-descendant dev-status repairs, causing reinstall lock inconsistencies and potentially incorrect plugin exports.
5 open issues
3 resolved since last review
Review effort: Balanced
…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]>
…eppiel-4804-uninstall-lock-metadata
… 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]>

Description
When
apm uninstallkeeps a dependency because a surviving package still needs it, the repaired lock metadata now matches what a freshapm installrecords: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 asAPMDependencyResolver._select_nearest_parent.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.install/orphans.py, applied incommands/uninstall/cli.py): the decision returns graph-wide dev status for the rescued subtree from the walk'sdev_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 provenrescued_dev; the reinstall oracles pass--no-frozenso they are real underCI=true(module passes locally withCI=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
Testing
Lint chain (local), all clean:
ruff check/format --check(0.15.12)lint_architecture_boundaries.py --root .lint-auth-signalstests.quality.taxonomy --changedcheck_test_assertions.pyChangelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated