Skip to content

fix(uninstall): derive kept rows' parent, depth and dev status graph-wide (#4833) - #4870

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-4833-graph-wide-lock-repair
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel-4833-graph-wide-lock-repair

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

After a declaration-only apm uninstall (the dependency stays because a surviving package still needs it, #4749), the lock repair followed only the kept dependency's recorded resolved_by subtree. Three cases left metadata that differed from what a full install writes (#4833).

Fix:

  • deps/reachability.py: the walk records every declaring edge (_ParentGraph) and, after the walk, solves shortest depth over the whole graph from the surviving direct declarations, production and dev alike. Each node's parent is its nearest declaring parent, ties to the lowest key, as APMDependencyResolver._select_nearest_parent does. New ReachabilityResult.depths and graph_children. Dev status keeps the walk's own production-first propagation.
  • install/orphans.py: the decision returns rescued_parents, rescued_depths and rescued_dev for every row the walk reaches from the kept dependencies, not only the recorded subtree. A partial walk repairs only the reached roots and proves production, never its absence. This replaces fix(uninstall): resolve repaired parents by exact lock key for virtual siblings (#4823) #4848's subtree and placement resolver, whose cells still pass.
  • commands/uninstall/cli.py: applies parent, depth and dev status to every affected row. Replacement root requests are dropped only for the removed declarations.

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

Human scope-approval comment: #4833 (apm-scope:v1 record)

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 -- the lock after uninstall equals what a following `apm install --no-frozen` writes (source: .agents/skills/apm-lifecycle-tests/SKILL.md)
cell: OP=uninstall SRC=git LOCK=consistent GRAPH={d->e->f + g->f; p->q->x->e + b->c->e with dev x; dev d->e, e->f, dev a->f}   owner: install/orphans.py (decide_orphan_removal) + deps/reachability.py
instrument: today test -> tests/integration/test_uninstall_shared_direct_dependency_lifecycle.py::{test_uninstall_reparents_a_descendant_to_its_nearest_surviving_parent, test_uninstall_takes_the_shorter_dev_path_through_an_expanded_node, test_uninstall_makes_a_shared_descendant_dev_only_graph_wide} (extends the module)
oracles: [I2]  decisive: f under test/g at depth 2; e under test/x at depth 2 and production; e and f dev-only; then lock bytes unchanged by a full reinstall
failing-before: CI=true pytest <module> -k "<3 cells>" -n 2 -> 3 failed (('test/e', 2) != ('test/g', 2); ('test/c', 3, None) != ('test/x', 2, None); f is_dev None)
passing-after (CI=true, -n 2):
  - module + test_uninstall_engine_validation + test_deps_reachability + test_uninstall_shared_diamond_dependency + test_uninstall_transitive_cleanup + install/test_orphan_removal_owner -> 80 passed
  - replacement root-request cell + both #4749 skill-selection cells (APM_E2E_TESTS=1) -> 3 passed
guard+mutation: n/a     ledger: 4833
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.

…wide

After a declaration-only uninstall, the repair followed only the kept
dependency's recorded subtree. The reachability walk now records every
declaring edge and solves shortest depth and nearest parent (lowest key
at equal depth) over the whole graph from the surviving direct
declarations, independent of dev-status propagation. Uninstall repairs
parent, depth and dev status for every row the walk reaches from the
kept dependencies; replacement root requests are still dropped only for
the removed declarations. Lifecycle cells (descendant re-parenting, a
shorter dev path through an already-walked package, shared-descendant
dev status) assert a byte-identical full reinstall; all three failed
before.

Fixes #4833

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

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 shared local descendant can incorrectly remain marked as production after its last production path is removed, requiring exact lock-key matching and a regression test.

1 open issue
What changed in this PR

Updates declaration-only apm uninstall metadata repair to follow the surviving dependency graph, aiming to keep retained lock rows consistent with a full install and address #4833.

Changes:

  • Computes shortest depths and nearest parents across all recorded declaring edges.
  • Applies parent, depth and dev-status repairs beyond the recorded subtree, preserving surviving replacement root requests.
  • Adds three lifecycle regression cases, a bug-ledger entry and a changelog fragment.
File Description
tests/​integration/​test_uninstall_shared_direct_dependency_lifecycle.py Adds three cases checking metadata and byte-stable reinstall.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4833.json Records failure modes and regression coverage.
src/​apm_cli/​install/​orphans.py Derives repair metadata for graph-reachable affected rows.
src/​apm_cli/​deps/​reachability.py Records declaring edges and solves graph-wide placement.
src/​apm_cli/​commands/​uninstall/​cli.py Applies repairs and limits root-request removal to removed declarations.
changelog.d/​4870.fixed.md Documents the uninstall metadata fix.

Review effort: Balanced

Comment thread src/apm_cli/deps/reachability.py Resolved
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 2e01de3 into main Nov 23, 2026
73 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4833-graph-wide-lock-repair branch November 23, 2026 06:49
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Fold the changelog.d fragments for #4858, #4868, #4870, #4880 and #4908 into [0.38.1].

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: derive parent, depth and dev status graph-wide after a declaration-only removal

2 participants