Skip to content

fix(install): retire proven skill copies left in earlier layouts - #5836

Open
Daniel Meppiel (danielmeppiel) wants to merge 9 commits into
mainfrom
fix-5830-legacy-skill-roots
Open

Daniel Meppiel (danielmeppiel) wants to merge 9 commits into
mainfrom
fix-5830-legacy-skill-roots

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 1d45c88c6f7049fa9584bb18ee3cf2c42816c892

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ 4 red-first lifecycle cells (project/user x dir-rows/no-rows) fail on main and pass; KEEP guards are green before and after.
↑ 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.
Diagnosis confidence 9/10 ↑ Reproduced with real 0.11.0 to 0.15.0 to main binaries: 0.15 refused the directory rows and dropped them from the lock.
↑ The pattern at skill_path_migration.py:67-68 and the untracked-member branch at cleanup.py:1022 explain both observed shapes.
Evidence fit 8.5/10 ↑ The CEO's ~/.copilot and ~/.config/opencode genesis 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:

  1. APM 0.11 recorded each skill as a directory row. 0.15 refused to delete those directories but dropped the rows, so ownership was lost and the files stayed. On main, cleanup still treated the members of a directory row as user content and never tried the existing byte proof.
  2. The migration matched only project roots through a hand-written pattern (.github|.cursor|.opencode|.gemini|.windsurf). User-scope roots such as ~/.copilot/skills were never considered.

What changes:

  • Roots from the target table. skill_layout.legacy_skill_roots(user_scope=...) derives (legacy root, converged root) from KNOWN_TARGETS and apply_legacy_skill_paths. Any root that is a current skills root at that scope is excluded (for example .claude/skills and ~/.config/opencode/skills), and so are dynamic roots.
  • Cleanup (_safe_remove_skill_directory through skill_layout.proves_untracked_skill_member): an untracked member of a recorded skill directory is checked with render_verdict against 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.
  • Migration: for each skill this install deploys, it lists each legacy root once (scandir; a missing root ends there) and plans <legacy root>/<name> when no lock row names it. There is no per-name stat. It plans only a real directory (by d_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/skills pointing into dotfiles; the strict skill_layout.linked_below check costs one lstat per component. The skills-root architecture allowlist entry for detect_legacy_skill_deployments is 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 when DeploymentEvidence.authorizes proves 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.
  • Fast path: unchanged. diff_apply.py is 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 scandir per legacy root (6 at project scope, 5 at user scope) and no per-name stat (test_stat_budget, 50 skills). When a legacy candidate exists it adds one lstat per path component per candidate folder (3, or 4 for .codeium/windsurf), and one lstat per 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-261 lstat of 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/skills is now a legacy root, because that is where --legacy-skill-paths puts Codex skills. The old unit cell that pinned it as non-legacy is updated.
  • A kept folder (for example one with an edited file) is reported by full runs. No-op runs stay on the fast path and do not report it.
  • The member proof lives in skill_layout.proves_untracked_skill_member, which puts cleanup.py at 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 audit at user scope stays out of scope, as the record says. QL sign-off is pending.

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-LAW-ownership.preserve_unowned -- install retires only proven APM copies from earlier layouts and keeps everything else (source: #5830 scope record)
cell: OP=install SRC=git PRIM=skill SCOPE={project,user} LOCK={dir-rows (0.11), no-rows (0.15 upgrade)} DEPLOYED=legacy-root   owner: src/apm_cli/integration/skill_layout.py, integration/cleanup.py, install/skill_path_migration.py
instrument: today test -> tests/integration/test_legacy_skill_layout_lifecycle.py::test_upgrade_retires_proven_legacy_skill_copies, ::test_upgrade_keeps_unproven_legacy_skill_entries, ::test_legacy_copy_behind_a_linked_folder_is_kept[scope x outside/inside x dir-rows/no-rows], ::test_kept_legacy_copy_does_not_block_the_no_op_fast_path (extends the legacy-layout module)
oracles: [I1, I2, I7, I9, snapshot-absence]  decisive: identical legacy copy gone; edited/.bak/symlink/note/own skill byte-identical; edited folder named once; lock has no legacy alpha row and records .agents/skills/alpha; second install changes no bytes
failing-before: 7b2a32a7 (red-first) -> 4 failed: "assert not True where True = (legacy / 'alpha').exists"
passing-after: 23 passed (module). At a09aa546, 6 of the 8 linked cells fail: the link target is modified at user scope, and the folder is kept silently at project dir-rows. Mutations: dropping the cleanup-site guard turns [user-*-dir-rows] red; dropping the migration-site guard turns [user-*-no-rows], [project-inside-no-rows] and [project-*-dir-rows] red
guard+mutation: n/a      ledger: 5830
hints executed: none printed

All local runs went through the host local-test.sh guard with APM_E2E_TESTS=1 and APM_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:xdist over 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 (adds TestLinkedBelow; the cost cell patches the module's os only), including the removal-error cell (non-ASCII folder name, ASCII-only output), which fails against c1b036e and c85bd10. This adds the derived-root cases, the lstat budget and the outside-project cell (kept, not failed; verified failing with the old branch), and updates the Codex cell.
  • Unit neighbours plus test_fast_path_consent.py: 889 passed.
  • pytest tests/quality/test_lifecycle_bug_ledger.py: passed.
  • Lint mirror, all clean:
    • ruff@0.15.12 check and format on the src, tests and scripts paths;
    • pylint R0801;
    • lint-auth-signals.sh;
    • complexity ratchet, --base-ref 641743fb;
    • tests.quality.taxonomy --changed;
    • check_test_assertions.py;
    • obligation ratchet;
    • lint-architecture-boundaries.sh;
    • file length: cleanup.py is 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

  • 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: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour. Cleanup of earlier APM layouts has no req-*; the fix commit carries an apm-spec-waiver: line.

#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>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 08:36
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

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>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Dec 3, 2026
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old skill copies from earlier APM layouts are never cleaned up after an upgrade

2 participants