Repository navigation
plan/apply P1: one orphan removal owner (#4011) - #4021
Merged
Daniel Meppiel (danielmeppiel) merged 13 commits intoNov 20, 2026
Merged
Conversation
…wner (#4011) WIP slice: decide_orphan_removal in install/orphans.py now computes install cleanup, install --dry-run, targeted install, prune, uninstall, audit no-orphans and inspection decisions from explicit keyword-only inputs. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…4011) Replace the known-caller orphan guard with a full-inventory scan that rejects private owner references (imports, aliases, getattr reads), entry calls that omit or unpack inputs, second removal selectors/predicates and direct reachability walks. Installed-CLI fixtures prove offline previews match the real install, prune and uninstall runs. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…4011) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Closed
5 of 14 tasks
#4011) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…e orphan owner (#4011) Add the installed-CLI fixture for safety-retained files: an orphan's skill the project's own .apm content also deploys is kept by both the dry-run preview and the real install. Tolerate partial cleanup contexts without deps_to_install (spec-conformance SimpleNamespace ctx), and tighten the CHANGELOG line. apm-spec-waiver: no spec-level behavior change; owner refactor only (#4011) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…#4011) Also tolerate partial install contexts without deps_to_install. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…aliased walks (#4011) Peer review of #4021: the closed-world guard policed references to the owner but not local removal predicates. - Restore a positive route check: every removal site (prune, the compile advisory, deps list, install cleanup and lockfile merge, the uninstall engine and its dry run, the install dry run, audit no-orphans, targeted install) must reach decide_orphan_removal. - Require deletion inputs at those sites (safe_rmtree targets, dropped lock rows, previewed paths) to carry the decision, not merely filter by it. - Reject set subtraction/filtering of installed or locked sets at removal sites, and lock-row subtraction anywhere outside the owner. - Reject importing decide_orphan_removal through a re-export and aliased imports of the reachability walks; restore prune's positive reachability check (it hands a ReachabilityProbe to the owner). - Restore main's four bypass mutations in set-difference form, plus renamed evidence, new lock-row helper, re-export and aliased-walk mutations. - Drop the getattr defaults from cleanup's owner call; partial test contexts now carry the fields. Assert the exact pin partition in the partial-subtree test (the pre-existing hash-seed-dependent pin choice is a follow-up). apm-spec-waiver: owner consolidation; preview-only behavior aligns with the real run (#4011) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The cleanup phase now builds the manifest intent once (desired_owners) and hands it to the orphan owner; the source guard follows it there. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
6 of 10 tasks
…e orphan owner (#4011) Re-verify of #4021 found two bypass shapes in the removal-site guard: - In-place growth of a sink (.append/.extend/.add/.update/.insert) now has to carry the decision like a binding; the universe source follows both branches of an if-expression (prune's installed_packages); a loop over an installed or locked set that filters by membership and then deletes, binds or grows a sink is rejected at removal sites. - Every function that calls _scan_installed_packages, registered site or not, is held to the same rules: no subtracting or filtering the scan, and no safe_rmtree of a path the orphan decision did not name. Mutations: sink-extend, sink-append-loop and an unregistered deletion helper. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Conflicts: imports in commands/prune.py and commands/uninstall/engine.py (keep main's new imports, drop the private orphan helpers), the linter analyzer import list, CHANGELOG, regenerated CONFORMANCE, and the mutation file (adjacent additions; main's old warning-bypass test is superseded by the closed-world params). Repoint main's new copy-validity mutation to the owner's private _build_expected_install_paths. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 20, 2026 08:35
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 08:35
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-animated-fiesta
branch
November 20, 2026 08:36
5 of 10 tasks
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Multiple architecture-linter bypasses can permit deletion of packages the owner did not release and evade private-member and required-input checks.
4 open issues
What changed in this PR
This PR centralizes orphan-removal decisions in install/orphans.py for the 0.38 plan/apply work tracked in #4011. Commands consume a shared decision while reachability and file deletion remain with their existing owners.
Changes:
- Routes install, prune, uninstall, audit, dependency listing, and compile advisories through one orphan-removal entry point.
- Aligns specific preview behaviors with real runs and recognizes case-equivalent installed paths.
- Expands architecture guards and regression coverage, including lifecycle and conformance checks.
| File | Description |
|---|---|
tests/unit/test_uninstall_engine_validation.py |
Redirects children-index tests to the owner. |
tests/unit/test_uninstall_engine_phase3w5.py |
Updates children-index imports. |
tests/unit/test_uninstall_engine_helpers.py |
Updates imports and installed-directory preview setup. |
tests/unit/test_prune_casing.py |
Uses the relocated expected-path helper. |
tests/unit/test_install_update.py |
Tests orphan previews through owner decisions. |
tests/unit/test_drift_detection.py |
Replaces removed drift-helper calls. |
tests/unit/test_command_helpers.py |
Imports orphan selection from its owner. |
tests/unit/models/test_dependency_uninstall_selection.py |
Updates candidate-selector import. |
tests/unit/integration/test_cleanup_helper.py |
Checks manifest intent reaches the owner. |
tests/unit/install/test_repo_to_subdirectory_switch.py |
Uses shared inspection and updates mocks. |
tests/unit/install/test_replacement_source_consumers.py |
Exercises replacement reachability through the owner. |
tests/unit/install/test_partial_subtree_reconciliation.py |
Tests targeted decisions and retained descendants. |
tests/unit/install/test_orphan_removal_owner.py |
Adds owner-level safety contracts. |
tests/unit/install/test_dry_run_render.py |
Updates preview mocks and decision assertions. |
tests/unit/install/phases/test_cleanup_phase.py |
Checks frozen retention in decision results. |
tests/spec_conformance/test_lockfile_reqs.py |
Adds shared-path preservation coverage. |
tests/integration/test_wave6_validation_uninstall_coverage.py |
Updates children-index imports. |
tests/integration/test_wave2_adapters_coverage.py |
Replaces legacy orphan-helper coverage. |
tests/integration/test_uninstall_engine_coverage.py |
Updates imports and module expectations. |
tests/integration/test_skipped_integration_preserves_deployments.py |
Supplies required cleanup context. |
tests/integration/test_orphan_removal_owner_lifecycle.py |
Adds installed-CLI lifecycle scenarios. |
tests/integration/test_coverage_gaps_phase4w2.py |
Uses decision objects in preview mocks. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds owner-boundary bypass mutations. |
tests/benchmarks/test_scaling_guards.py |
Benchmarks the relocated children index. |
tests/benchmarks/test_audit_benchmarks.py |
Updates the children-index import. |
src/apm_cli/policy/ci_checks.py |
Routes audit orphan checks through the owner. |
src/apm_cli/integration/cleanup.py |
Updates the cleanup docstring reference. |
src/apm_cli/install/presentation/dry_run.py |
Renders owner-selected files and shared claims. |
src/apm_cli/install/phases/resolve.py |
Passes incomplete-resolution evidence explicitly. |
src/apm_cli/install/phases/lockfile.py |
Uses owner decisions when retaining lock rows. |
src/apm_cli/install/phases/cleanup.py |
Consumes decisions for file and package cleanup. |
src/apm_cli/install/package_selection.py |
Delegates targeted orphan classification. |
src/apm_cli/install/orphans.py |
Defines the shared decision API and selection logic. |
src/apm_cli/drift.py |
Removes the separate orphan detector. |
src/apm_cli/commands/uninstall/engine.py |
Shares owner decisions across preview and removal. |
src/apm_cli/commands/prune.py |
Consumes selected paths and lock keys. |
src/apm_cli/commands/deps/cli.py |
Uses shared orphan inspection. |
src/apm_cli/commands/_helpers.py |
Adds owner-backed inspection for advisories. |
scripts/architecture_linter/checks/marketplace_locked_evidence.py |
Points evidence checks at relocated helpers. |
scripts/architecture_linter/checks/install_uninstall_and_resolution.py |
Updates routes and removes the old orphan guard. |
scripts/architecture_linter/checks/install_orphan_removal.py |
Adds owner-reference and input-contract checks. |
scripts/architecture_linter/checks/install_orphan_removal_sites.py |
Adds removal-route and decision-provenance checks. |
scripts/architecture_linter/checks/install_frozen_and_audit.py |
Checks reachability delegation through the owner. |
scripts/architecture_linter/checks/install_deployment_analyzers.py |
Registers the expanded orphan guard. |
scripts/architecture_linter/checks/install_base_integrator_and_contraction.py |
Updates the deployment-claim guard. |
CONFORMANCE.md |
Updates the requirement test count. |
CONFORMANCE.json |
Records the new conformance test. |
CHANGELOG.md |
Documents preview alignment. |
.apm/architecture/owners/install-deployment.json |
Records the consolidated owner contract. |
Review effort: Balanced
Comment on lines
+203
to
+204
| for node in self.nodes: | ||
| if isinstance(node, ast.Attribute): |
Comment on lines
+168
to
+177
| nodes = index.nodes | ||
| if any( | ||
| isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name == _INSTALLED_SCAN | ||
| for node in nodes | ||
| ): | ||
| return [] # the scanner's own module (or an unrelated namesake) | ||
| findings: dict[tuple[int, str], Violation] = {} | ||
| for function in index.functions(): | ||
| if not isinstance(function, (ast.FunctionDef, ast.AsyncFunctionDef)): | ||
| continue |
Comment on lines
+320
to
+323
| if key is None or key in tainted: | ||
| continue | ||
| if is_source(value) or flows(value, tainted): | ||
| tainted.add(key) |
Comment on lines
+491
to
+495
| node = stack.pop() | ||
| if isinstance(node, ast.Name) and node.id in names: | ||
| return True | ||
| if isinstance(node, ast.Attribute) and ast.unparse(node) in names: | ||
| return True |
This was referenced Nov 20, 2026
3 of 9 tasks
Takeshi Masukawa (takeaship)
pushed a commit
to takeaship/apm
that referenced
this pull request
Nov 20, 2026
…dings Full integration found five mutation cases whose source fragments no longer match the code after the 0.37 owner landings. Each is re-pointed to the current shape of the same decision, so the guard still has to catch it: - install compound (target-consumer-rejects-unrelated-getattr-sink): the integrator dispatch now passes `_target, package_info, ...` on one line inside `recorded_writes`; the mutation swaps that first argument for `rogue_target`. - retained lock keys (prune-bypasses-owner): prune hands the reachability walk to the orphan owner via `reachability=ReachabilityProbe(` (microsoft#4021); the mutation replaces that handoff with a private computation. - semantic rules (marketplace-integrations-projection-boundary): the boundary call is now followed by the `recorded_writes` import; the mutation moves the import ahead of the boundary. - shared skill preservation (orphan-survivor-bypass): orphan cleanup protects survivors through `DeploymentClaims(live_files=surviving_files, ...)` (microsoft#4021); the mutation drops the survivors. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
0.38 plan/apply P1: one orphan removal owner.
install/orphans.pygains one entry point,decide_orphan_removal, with keyword-only, no-default inputs (operation, roots, candidate universe, installed paths, resolved and intended keys, materialized refs, reachability probe, deployment claims). Install cleanup, install--dry-run, targeted install, prune, uninstall (and their dry runs),apm audit --cino-orphans,apm deps listand the compile advisory all call it; command differences are inputs, not private predicates. Forward reachability stays withdeps/reachability.py, which the owner consumes; file deletion stays with the cleanup owner (integration/cleanup.py) and the commands' deletion loops.The known-caller guard
install-deployment-orphan-selectionbecomes a closed-world guard over the fullsrc/apm_cliinventory:install_orphan_removal.py(references to the owner): rejects reads of any non-__all__owner name through imports, aliases, attribute reads orgetattr; entry-point calls that omit, unpack or pass inputs positionally, or rebind the entry; importing the entry through a re-export; second removal selectors and membership tests against removal evidence; and calling or importing (under any alias) the reachability walks outside the owner.install_orphan_removal_sites.py(what commands do with removal): a positive route check that every removal site still reaches the owner; deletion inputs at those sites (safe_rmtreetargets, dropped lock rows, previewed paths) must carry the decision, not merely filter by it; in-place growth of those sinks (.append/.extend/.add/.update) must carry the decision too; removal sites must not subtract or filter installed or locked sets (including membership-filtered loops that delete or feed a sink); every function that calls_scan_installed_packages, registered site or not, is held to the same no-subtract, no-filter, decision-only-deletion rules; no product module outside the owner and the lock model may subtract from lock rows.Scope of "closed world": owner references are checked across all of
src/apm_cli; removal predicates are checked at the registered removal sites, in every function that scansapm_moduleswith_scan_installed_packages, and (lock-row subtraction) everywhere. A deletion ofapm_modulescontent that neither sits at a registered site nor scans installed packages is not modeled. The deletion check coverssafe_rmtreeonly;shutil.rmtree,Path.unlink/rmdirand rawiterdir/scandir/listdirwalks ofapm_modulesare not modeled (adding them flagsapm deps clean's whole-directory wipe, which is not an orphan decision).Rebases onto P3 (#4016): no new code reads the frozen flag; the existing frozen read in
install/phases/cleanup.pyis left untouched for P3 to replace.Preview-only behavior that now aligns with the real run
apm install --dry-runno longer lists orphan files another package (or the project's own.apmcontent) still deploys; the real install already kept them.apm uninstall --dry-runwithout anapm_modules/directory no longer lists transitive packages; the real uninstall already removed none in that case._check_orphaned_packages) now recognizes case-equivalent installed paths (case-preserving, likeapm pruneandapm deps list), so it no longer warns about a package installed under different casing.Follow-up (pre-existing, not changed here)
_pin_retained_ancestors(install/orphans.py,by_identity) maps lock parent identity to a key by iterating a frozenset. When two dropped rows share an identity (e.g.acme/repoand its virtual childacme/repo/skills/child), which one is pinned depends on the hash seed: acrossPYTHONHASHSEED=0..7the same targeted-install decision split 3/8 retained={child}, removed={parent}and 5/8 retained={parent, child}, removed={}. This was moved verbatim from main'sinstall/phases/cleanup.py.test_pinned_nested_package_survives_parent_module_removalasserts the exact partition (retained is one of the two sets, removed ={parent}minus retained). Making the choice deterministic (and deciding which is correct) is tracked in #4060.apm-spec-waiver: owner consolidation; preview-only behavior aligns with the real run (#4011)
Issue and approved scope
Issue: Fixes #4011
Human scope-approval comment: #4011 (comment)
Completes the approved scope. Out of scope per the record: dry-run network (P2), frozen (P3), deletion evidence (#3701), stale-file previews.
Type of change
Testing
Installed-CLI fixtures (
tests/integration/test_orphan_removal_owner_lifecycle.py,APM_BINARY_PATH=.venv/bin/apm): offline install, prune and uninstall previews match the real runs; safety-retained files (an orphan's skill the project's own.apmalso deploys is kept in preview and real run);apm audit --cireports the direct-entry projection; targeted-install isolation; unlocked prune directories; uninstall rescue of a shared dependency.Static mutation tests (
tests/integration/test_architecture_owner_rule_mutations.py::test_orphan_owner_guard_is_closed_world) each fail the guard: a second predicate, an omitted input, positional input, a rebound entry, a private alias import, agetattrread, a second selector, a defaulted owner input, main's four bypasses restated in set-difference form (compile warning, targeted-install module removal, superseded-root trim, deps list), a renamed-evidence predicate, a new lock-row subtraction helper, a re-exported entry, an aliased reachability import, in-place sink growth (extend, and a for/if/appendloop), and an unregistered deletion helper that scans installed packages.test_prune_hands_the_reachability_walk_to_the_orphan_ownercovers prune's restored positive reachability check.uv run --extra dev ruff check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/-- passeduv run --extra dev ruff format --check(same paths) -- passeduv run --extra dev python scripts/lint_architecture_boundaries.py --root .-- passeduv run --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/-- passed (10.00/10)bash scripts/lint-auth-signals.sh-- passeduv run --extra dev pytest -n 8 tests/integration/test_architecture_owner_rule_mutations.py tests/unit/scripts-- 1322 passed, 1 failed (test_architecture_registry_conflicts, host git commit signing; unrelated)APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_orphan_removal_owner_lifecycle.py tests/unit/install/test_orphan_removal_owner.py-- 10 passeduv run --extra dev pytest tests/spec_conformance/test_lockfile_reqs.py tests/integration/test_skipped_integration_preserves_deployments.py tests/unit/install/test_partial_subtree_reconciliation.py-- passed (partial-subtree also underPYTHONHASHSEED=1and2)Changelog
## [Unreleased]inCHANGELOG.md.Spec conformance (OpenAPM v0.1)
No
req-XXXchanges;tests/spec_conformance/test_lockfile_reqs.pycites req-lk-020 for the owner's claim preservation andCONFORMANCE.{md,json}are regenerated.