Skip to content

fix(uninstall): resolve repaired parents by exact lock key for virtual siblings (#4823) - #4848

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-4823-virtual-sibling-depth
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-4823-virtual-sibling-depth

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Stacked on #4811 (Fixes #4804): it contains #4811's commits until that lands, so review only the last commit (d68b449) and its changelog fragment. Land after #4811.

Sibling virtual packages from one repository (for example test/mono/d and test/mono/e) share the legacy parent identity test/mono, their repo_url. When apm uninstall test/mono/e kept e because d still needs it, the depth repair looked parents up by that shared identity, could take e as its own parent, and recorded depth 3 instead of 2. The next full install then rewrote the lock.

  • deps/reachability.py: the walk records each node's exact parent lock key (ReachabilityResult.parent_keys), which is also the nearest-parent tie key, as in install's _select_nearest_parent.
  • install/orphans.py: a rescued root resolves its parent by that exact key. Recorded legacy edges go through the lock parent placement owner (deps/lock_parent_placement.py) with installed-manifest evidence. An entry is never its own parent; an unresolved parent keeps the recorded depth.

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 #4823

Human scope-approval comment: #4823 (apm-scope:v1 record, first comment)

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

apm-spec-waiver: uninstall lock-metadata repair resolves parents by exact lock key; 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 -- the lock after uninstall equals what a following full install (--no-frozen) writes (source: .agents/skills/apm-lifecycle-tests/SKILL.md)
cell: OP=uninstall SRC=git(virtual subdirectory) LOCK=legacy(no replacements) GRAPH=sibling d -> e, both direct   owner: install/orphans.py (decide_orphan_removal) + deps/reachability.py
instrument: today test -> tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py::test_uninstall_of_a_virtual_sibling_never_parents_it_to_itself (extends the #4749/#4804 module)
oracles: [I2]  decisive: e row depth == 2 and lock bytes unchanged by `apm install --no-frozen`
failing-before: pytest <node> -n 0 -> 1 failed (assert 3 == 2)
passing-after: module + test_deps_reachability + test_uninstall_shared_diamond_dependency + test_uninstall_transitive_cleanup + install/test_orphan_removal_owner + deps/test_lock_parent_placement, CI=true, -n 2 -> 55 passed
guard+mutation: n/a     ledger: 4823
hints executed: none printed

Lint chain (local), all clean:

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

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]>
… 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]>
…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]>
…l siblings

Sibling virtual packages from one repository share the legacy parent
identity (their repo_url), so the depth repair could take a rescued
package as its own parent. The reachability walk now records each
node's exact parent lock key (also the nearest-parent tie key, as in
install), rescued roots resolve their parent by it, and recorded legacy
edges go through the lock parent placement owner; an entry is never its
own parent. A lifecycle cell with test/mono/d declaring test/mono/e
asserts a byte-identical reinstall after uninstalling test/mono/e.

Fixes #4823

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 23:07

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 local-parent fallback records an absolute path instead of its lock key, preventing parent resolution and leaving a rescued dependency at the wrong depth after uninstall.

1 open issue
What changed in this PR

This PR addresses #4823 by resolving repaired parents through exact lock keys, preventing virtual sibling packages from being mistaken for their own parents during uninstall. It builds on #4811's lock-metadata repairs without changing the lockfile format or dependency resolution.

Changes:

  • Carry exact parent keys through the reachability walk.
  • Resolve legacy parent edges through the existing placement owner, preserving depth when a parent cannot be resolved.
  • Add a virtual-sibling lifecycle regression that checks lockfile stability after a full reinstall.
File Description
tests/​integration/​test_uninstall_shared_direct_dependency_lifecycle.py Adds metadata-repair regressions and full-reinstall stability checks.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4823.json Records the virtual-sibling regression and its test.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4804.json Records the stacked parent, depth, and dev-status regressions.
src/​apm_cli/​install/​orphans.py Resolves repaired parents and computes retained-subtree metadata.
src/​apm_cli/​deps/​reachability.py Tracks exact parent keys and nearest-parent ranking.
src/​apm_cli/​commands/​uninstall/​cli.py Applies the stacked depth and dev-status repairs.
changelog.d/​4848.fixed.md Documents the virtual-sibling depth fix.
changelog.d/​4811.fixed.md Documents the stacked lock-metadata fixes.

Review effort: Balanced

Comment thread src/apm_cli/deps/reachability.py Resolved
…ement when nothing is rescued

- A surviving local parent is not in the walk's candidate directory
  index, so its recorded parent key was an absolute path and the depth
  repair could not find the row. The walk falls back to the parent's
  own unique key, and the resolver falls back to the repaired identity
  when an exact key is not a lock row. Red-first cell: ./vendor/d
  declaring test/e, uninstall test/e, depth 2 and byte-identical
  reinstall (depth stayed 1 before).
- The depth repair returns early without rescued roots and reads
  installed manifests for legacy placement only when a descendant needs
  it, so uninstalls that rescue nothing do no extra manifest I/O (this
  also restores the MagicMock-lockfile engine unit tests).

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.

🔵 Needs a closer look

Unresolved legacy placement can incorrectly attach a descendant to a rescued sibling and change its recorded depth; it should use _UNKNOWN_PARENT to preserve depth while retaining None for direct rows.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve recorded depth for unresolved legacy placement

src/​apm_cli/​install/​orphans.py:708

When legacy placement cannot disambiguate a recorded edge, key in placed() is false and the fallback selects the last sibling with that repository identity anyway. If a sibling's installed manifest is unreadable, this can attach a descendant to a rescued sibling and change its depth from 2 to 3 without establishing its actual parent. Treat unresolved legacy placement as _UNKNOWN_PARENT so the recorded depth stays unchanged, while retaining None for direct rows.

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit f60bfd9 into main Nov 23, 2026
72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4823-virtual-sibling-depth branch November 23, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants