Repository navigation
fix(install): deterministic orphan retention for shared-identity rows (#4060) - #4063
Merged
Daniel Meppiel (danielmeppiel) merged 2 commits intoNov 20, 2026
Merged
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-4060-orphan-determinism
branch
from
November 20, 2026 03:21
bbae8e6 to
8645ee7
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-4060-orphan-determinism
branch
from
November 20, 2026 04:23
8645ee7 to
0b5b6ec
Compare
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-4060-orphan-determinism
branch
from
November 20, 2026 08:22
0b5b6ec to
40edf8d
Compare
…#4060) _pin_retained_ancestors mapped each lock parent identity to one dropped key by iterating a frozenset, so when a repository and its virtual child shared an identity, the retained set depended on PYTHONHASHSEED. Map each identity to every dropped row that carries it and pin all of them, keeping the parent chain the next targeted install needs. The new test replays the decision under 12 fixed hash seeds with two controls; the nested-package test now asserts the exact partition. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-4060-orphan-determinism
branch
from
November 20, 2026 08:36
40edf8d to
bcab245
Compare
Merged
6 of 10 tasks
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 20, 2026 08:49
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 08:49
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-4060-orphan-determinism
branch
November 20, 2026 08:49
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The orphan traversal repeatedly enqueues shared-identity buckets, causing quadratic work and excessive queue growth when many virtual children share a parent’s identity.
1 open issue
What changed in this PR
Fixes #4060 in the centralized orphan-removal owner introduced by #4021, making targeted installs retain shared-identity repository and virtual-child rows regardless of Python hash seed.
Changes:
- Pins every dropped row matching a retained entry's parent identity.
- Adds regression coverage across 12 hash seeds and strengthens retention, directory-survival, and dry-run assertions.
- Documents the user-visible fix in the changelog.
| File | Description |
|---|---|
tests/unit/install/test_partial_subtree_reconciliation.py |
Adds seeded regression cases and exact retention assertions. |
src/apm_cli/install/orphans.py |
Maps each parent identity to all matching dropped rows. |
CHANGELOG.md |
Records deterministic retention during targeted installs. |
Review effort: Balanced
| if parent in by_identity | ||
| ) | ||
| for parent in lockfile.dependencies[key].parent_keys: | ||
| queue.extend(by_identity.get(parent, ())) |
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
TL;DR
_pin_retained_ancestors(the targeted-install pin walk in the orphan removal owner) mapped each lock parent identity to one dropped key by iterating a frozenset. When a repository and its virtual child share an identity, which row was pinned depended onPYTHONHASHSEED. Each identity now maps to every dropped row that carries it, and all of them are pinned, so the retained set is always{parent, child}and nothing is removed.Fixes #4060
Note
Stacked on #4021 (base
danielmeppiel-animated-fiestaatfa99ad85, the P1 guard fold), which moves the function intoinstall/orphans.py. CI does not run on a stacked base, so local evidence is below.Problem (WHY)
PYTHONHASHSEED=0..7the same targeted-install decision split: seeds 0, 2 and 6 retained{acme/repo/skills/child}and removed{acme/repo}; the rest retained both.{parent, child}is correct.apm install --dry-runpreviews no package orphans for a targeted install (install/presentation/dry_run.py), so on the bad seeds the real run removed a package that the preview did not show.Approach and implementation
src/apm_cli/install/orphans.pyby_identitybecomesdict[str, set[str]]; the walk pins every dropped row that has the parent identity. No other selection semantics change.tests/unit/install/test_partial_subtree_reconciliation.pytest_shared_identity_retention_is_independent_of_hash_seedreplays the decision in a subprocess under 12 fixed seeds (0-11), with two controls: distinct identities (a<-bretained,cremoved) and a retained row with no dropped ancestor (xkept,yremoved).test_pinned_nested_package_survives_parent_module_removalnow asserts the exact partition (retained == {parent, child},removed == {}), that the targeted--dry-runpreview equals the real removal set, and that both module dirs survive.CHANGELOG.mdDocs: no page describes targeted-install orphan retention, so there is no docs change (per the record).
Trade-offs
Validation (local; no CI on the stacked base)
Red on base (fix reverted; first measured on 33c8cc9, re-confirmed on fa99ad8: 2 failed, 8 passed) and green on this branch
Lint mirror, architecture linter, orphan suites
The one failure,
test_cache_pin.py::test_sync_markers_never_stamps_a_checkout_at_another_commit, fails identically on the base: this host's commit signing rejects the test's owngit commit. It is unrelated.Scenario evidence
retained = {parent, child},removed = {}test_shared_identity_retention_is_independent_of_hash_seed(12 seeds)distinct-identities,no-dropped-ancestortest_pinned_nested_package_survives_parent_module_removalapm install --dry-runreports the same partitionIssue and approved scope
Issue: Fixes #4060
Human scope-approval comment: #4060 (comment) (verified
record-presentwithscripts/governance/eligibility.cjs)Completes the issue. Out of scope per the record: other orphan-selection semantics, deletion evidence (#3701), #3188, #2413.
Type of change
Testing
Changelog
## [Unreleased]inCHANGELOG.md.Spec conformance (OpenAPM v0.1)
How to test
git checkout danielmeppiel-4060-orphan-determinismuv run --extra dev pytest -q tests/unit/install/test_partial_subtree_reconciliation.py-- 10 passed.git checkout fa99ad85 -- src/apm_cli/install/orphans.pyand rerun step 2: the seeded test fails on the split partition. Restore withgit checkout HEAD -- src/apm_cli/install/orphans.py.Co-authored-by: Copilot [email protected]