Repository navigation
fix(install): retire proven skill copies left in earlier layouts - #5836
Open
Daniel Meppiel (danielmeppiel) wants to merge 9 commits into
Open
Daniel Meppiel (danielmeppiel) wants to merge 9 commits into
Daniel Meppiel (danielmeppiel) wants to merge 9 commits into
Conversation
#5830) Builds a per-client skill layout, rewrites its lock to the shape APM 0.11 left (directory-only rows) or a 0.15 upgrade left (no rows), drops the receipts, then installs with the converged layout at project and user scope. The identical copy must go; an edited file, a .bak sibling and a symlinked skill stay; the edited folder is named once; the lock converges and a second install is byte-stable. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
An edited file, a .bak sibling, a symlinked skill, a note and a user's own skill in the legacy root all survive an upgrade install at project and user scope. Green before and after the fix: they pin the fail-closed boundary. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…5830) Legacy skill roots now come from KNOWN_TARGETS and apply_legacy_skill_paths per scope (integration/skill_layout.py), replacing the project-only pattern, so user roots such as ~/.copilot/skills and directory-only rows from APM 0.11 are recognised. - Cleanup proves the untracked members of a recorded skill directory against the locked render at the converged path before treating them as user content. - The migration examines <legacy root>/<name> for each skill this install deploys when no lock row names it (one lstat each) and removes it only when every file is proven; edited files, renamed folders and symlinks are kept and reported once. - The project fast path declines while such a copy exists. apm-spec-waiver: install-time cleanup of earlier APM layouts; no OpenAPM requirement covers legacy skill roots. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Migration can follow a linked legacy root and delete a live deployment, while its repeated full-record scans also add substantial overhead to ordinary installs.
2 open issues
What changed in this PR
Updates install cleanup to retire proven skill copies left by older layouts at project and user scope, addressing #5830.
Changes:
- Derives legacy roots from target definitions.
- Handles directory-only lock rows and unrecorded copies, with a fast-path guard.
- Adds lifecycle coverage, cost checks, and documentation.
| File | Description |
|---|---|
| tests/unit/install/test_skill_path_migration.py | Tests derived roots and filesystem-probe limits. |
| tests/integration/test_legacy_skill_layout_lifecycle.py | Covers upgrades, retained user content, and repeat installs. |
| tests/fixtures/lifecycle_bug_ledger/bugs/5830.json | Records regression coverage for #5830. |
| src/apm_cli/integration/skill_layout.py | Defines legacy roots and converged-path aliases. |
| src/apm_cli/integration/cleanup.py | Adds render proof for untracked directory members. |
| src/apm_cli/install/skill_path_migration.py | Detects and processes unrecorded legacy copies. |
| src/apm_cli/install/diff_apply.py | Declines the fast path when legacy copies remain. |
| docs/src/content/docs/reference/targets-matrix.md | Documents retirement behavior and preservation safeguards. |
| changelog.d/5836.fixed.md | Adds the user-facing fix entry. |
Review effort: Balanced
Comment on lines
+191
to
+195
| info = os.lstat(deploy_root / src) | ||
| except (OSError, PathTraversalError): | ||
| continue | ||
| if not stat.S_ISDIR(info.st_mode): | ||
| continue |
Comment on lines
+170
to
+188
| claimed = {path.replace("\\", "/").rstrip("/") for path in recorded} | ||
| owners: dict[tuple[str, str], str] = {} | ||
| for dep_key, paths in sorted(deployed.items()): | ||
| for path in paths: | ||
| value = path.replace("\\", "/") | ||
| for _legacy, converged in roots: | ||
| prefix = f"{converged}/" | ||
| if value.startswith(prefix): | ||
| name = value[len(prefix) :].split("/", 1)[0] | ||
| if name: | ||
| owners.setdefault((converged, name), dep_key) | ||
| plans: list[MigrationPlan] = [] | ||
| for legacy, converged in roots: | ||
| for (root, name), dep_key in sorted(owners.items()): | ||
| if root != converged: | ||
| continue | ||
| src = f"{legacy}/{name}" | ||
| if any(path == src or path.startswith(f"{src}/") for path in claimed): | ||
| continue |
…rs (#5830) The project fast path declines only for a recorded legacy row, which rewrites the lock; unrecorded copies are retired by the first full run after an upgrade, so a kept copy never forces a full run. At project scope a candidate with a symlinked path component is kept with a link note, and an unrecorded folder that resolves outside the project is kept rather than retried. The untracked-member proof moves to skill_layout.proves_untracked_skill_member. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…llowlist entry (#5830) An unrecorded legacy folder whose removal fails with an OSError is kept with a note naming the error; only a path that escapes the project gets the link note. diff_apply.py returns to main's form (default project roots), keeping it within its line budget, and the skills-root guard no longer allowlists detect_legacy_skill_deployments, which now derives its roots from the target owner. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A kept legacy folder's path passes through printable_ascii_text, and a removal error is named by its strerror (or exception type) instead of the raw exception text, which embeds the unescaped path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… name (#5830) The unrecorded-copy sweep takes one scandir per legacy root and checks entry types from it, so a full install adds no per-skill stat: 6 calls at project scope and 5 at user scope whatever the skill count, keeping the 50-skill count budgets unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…her scope (#5830) QL found that at -g a ~/.copilot/skills link (into ~/dotfiles or outside HOME) let install delete the link target's files. Two call sites deleted: - src/apm_cli/integration/cleanup.py _safe_remove_skill_directory, for a recorded directory-only row: the new untracked-member proof (skill_layout.proves_untracked_skill_member) authorized members behind the user's link, which cleanup traverses at -g. - src/apm_cli/install/skill_path_migration.py run_skill_path_migration, for an unrecorded folder: the symlink check ran only at project scope, and ensure_path_within admits a user-owned link at -g. Both now use skill_layout.linked_below, a strict walk below the scope root (project root or HOME) where a link the user owns counts too. The untracked-member proof refuses any linked member. The migration keeps every recorded or unrecorded candidate folder behind a link with one note, skipping the note when cleanup already named the folder. Cells cover scope x link target x lock shape; each site's guard is proven by a mutation. The stat-budget cell now patches the module's os only. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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.


Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
1d45c88c6f7049fa9584bb18ee3cf2c42816c892↑ 1138 neighbour tests pass; the full local lint mirror is clean.
↓ PR CI and Integration not yet observed at this revision.
↓ Cleanup now runs a render for the untracked members of a stale skill directory; more work on that path, unchanged decisions elsewhere.
↑ The pattern at
skill_path_migration.py:67-68and the untracked-member branch atcleanup.py:1022explain both observed shapes.~/.copilotand~/.config/opencodegenesis copies are byte-identical to the locked render (31/31 files), and the lock does not record them.↓ The exact upgrade sequence on that machine is inferred; there is no install log.
Description
Skill copies that an earlier APM layout left under a per-client root were never removed. Examples are
~/.copilot/skills/<name>,~/.cursor/skills/<name>and.github/skills/<name>. Harnesses that read those roots load stale or duplicate skills. There were two causes:.github|.cursor|.opencode|.gemini|.windsurf). User-scope roots such as~/.copilot/skillswere never considered.What changes:
skill_layout.legacy_skill_roots(user_scope=...)derives(legacy root, converged root)fromKNOWN_TARGETSandapply_legacy_skill_paths. Any root that is a current skills root at that scope is excluded (for example.claude/skillsand~/.config/opencode/skills), and so are dynamic roots._safe_remove_skill_directorythroughskill_layout.proves_untracked_skill_member): an untracked member of a recorded skill directory is checked withrender_verdictagainst the locked render at the converged path. It is deleted only when its bytes are proven and no component below the scope root is a link; otherwise it stays user content, as before.scandir; a missing root ends there) and plans<legacy root>/<name>when no lock row names it. There is no per-namestat. It plans only a real directory (byd_type), never a symlink. At both scopes, a candidate folder with any link or junction below the scope root (project root or HOME) is kept with one link note. This includes links the user owns, such as~/.copilot/skillspointing into dotfiles; the strictskill_layout.linked_belowcheck costs onelstatper component. The skills-root architecture allowlist entry fordetect_legacy_skill_deploymentsis removed, because it now derives roots from the target owner. A folder that resolves outside the project is kept with the link note, and any other removal error is kept with a note that names the error; neither is counted as "will retry". It deletes only whenDeploymentEvidence.authorizesproves every file, with the same all-or-nothing rule as before. A recorded legacy directory still on disk is left to cleanup, so no folder is decided twice.diff_apply.pyis identical to main, and the project diff path declines only for a recorded legacy row, because that rewrites the lock. Unrecorded copies are retired by the first full run after an upgrade (the replay key carries the build id), and a kept copy never forces a full run again.Cost: zero on the no-op fast path. A full run adds one
scandirper legacy root (6 at project scope, 5 at user scope) and no per-namestat(test_stat_budget, 50 skills). When a legacy candidate exists it adds onelstatper path component per candidate folder (3, or 4 for.codeium/windsurf), and onelstatper component for each untracked member of a recorded legacy directory. The perf worlds have no legacy candidates, so those costs are 0 there. A hash is read only for files under a matching folder. The Linux count budgets (test_perf_count_budgets, the 50-skill journeys have 188-261lstatof headroom) should not move.Fail-closed boundary: a file is deleted only when it is byte-equal to the package's render (or matches a receipt). Folders with other names (
alpha.bak-20260602), edited files, symlinks, notes and the user's own skills in the same root are never touched. The KEEP guards pin this at both scopes.Behaviour notes:
.codex/skillsis now a legacy root, because that is where--legacy-skill-pathsputs Codex skills. The old unit cell that pinned it as non-legacy is updated.skill_layout.proves_untracked_skill_member, which putscleanup.pyat 2098 lines (main has 2097).Issue and approved scope
Issue: Fixes #5830
Human scope-approval comment: #5830 (comment)
Does this PR complete the issue, or what remains? It completes the scoped work.
apm auditat user scope stays out of scope, as the record says. QL sign-off is pending.Type of change
Testing
All local runs went through the host
local-test.shguard withAPM_E2E_TESTS=1andAPM_BINARY_PATH=.venv/bin/apm.pytest -p no:xdist tests/integration/test_legacy_skill_layout_lifecycle.py: 23 passed. At 7b2a32a: the 4 retire cells fail, and the 2 KEEP guards pass.pytest -p no:xdistover the 18 modules that touch the migration, cleanup evidence, skill layout or diff path: 1138 passed, 12 skipped.pytest tests/unit/install tests/unit/scripts tests/unit/integration: 9070 passed.pytest tests/unit/install/test_skill_path_migration.py: 41 passed (addsTestLinkedBelow; the cost cell patches the module'sosonly), including the removal-error cell (non-ASCII folder name, ASCII-only output), which fails against c1b036e and c85bd10. This adds the derived-root cases, thelstatbudget and the outside-project cell (kept, notfailed; verified failing with the old branch), and updates the Codex cell.test_fast_path_consent.py: 889 passed.pytest tests/quality/test_lifecycle_bug_ledger.py: passed.ruff@0.15.12check and format on the src, tests and scripts paths;lint-auth-signals.sh;--base-ref 641743fb;tests.quality.taxonomy --changed;check_test_assertions.py;lint-architecture-boundaries.sh;cleanup.pyis at 2098, under the 2100 maximum.Hermetic diagnosis evidence: real 0.11.0 and 0.15.0 binaries were built from their tags and run in a temporary HOME with local git remotes.
Changelog
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)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
req-*; the fix commit carries anapm-spec-waiver:line.