Skip to content

fix(install): adopt unchanged committed skills on cold restore - #3564

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-fix-3391-adopt-committed-skills-cold-res
Nov 12, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-fix-3391-adopt-committed-skills-cold-res

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR

On a fresh clone or CI runner with no local deployment receipts, apm install / apm install --frozen now keeps committed claude_skill and skill_bundle output whose whole directory equals what the install would write (after link rendering) and records receipts, restoring the 0.34.0 behavior that Renovate and CI depend on. Anything that differs keeps #3490's fail-closed path: no overwrite, no deletion, nonzero exit with guidance.

Fixes #3391

Important

Lockfile hashes are never adoption evidence. The proof is the on-disk tree compared against freshly materialized package source; the lockfile only supplies ownership claims (paths), as the existing collision gate already requires.

Problem (WHY)

  • Reproduced on main (77708eb7): cold apm install in a fresh clone of a repo with a committed native skill exits 1 with Skipped .claude/skills/<pkg>/SKILL.md: no trustworthy local deployment baseline for every file, although the bytes are identical to the package source.
  • Reproduced with obra/superpowers#v7.0.0 (skill_bundle): 34 refusals. Bundles already had a raw-identity shortcut, but committed SKILL.md files are the link-rendered output (../requesting-code-review/… is rewritten), so raw comparison never matches.
  • [!] --force is not an option for Renovate or cloud agents, and after fix(install): preserve skills during cold replay without deployment receipts #3490 the failure blocks every lockfile restore of committed skills.

The approved scope asks to adopt such files "matching the existing .apm sub-skill adoption (is_skill_dir_identical_to_source)", while "any file that differs keeps the #3372 fail-closed path" (scope record).

Approach (WHAT)

# Fix
1 Compare the whole destination skill directory with the admitted source members after link rendering. Extra, missing, symlinked, or differing files mean no adoption.
2 Adopt only when every member is claimed by apm.lock.yaml; same-run session hashes are not ownership evidence.
3 Use the verified on-disk hash as the missing baseline, so the existing guarded write path rewrites identical bytes and session.record writes receipts. No new authority path.
4 Only evaluate when the anchor SKILL.md has no receipt record at all (DeploymentMaterializationSession.has_receipt), so warm installs and replays whose receipt exists but is untrusted keep today's behavior and never rewrite receipt state.

Implementation (HOW)

File Change
src/apm_cli/integration/skill_adoption.py (new) adoptable_skill_members (strict tree equality against rendered output), adoption_baselines (ownership-gated hashes), shared render_skill_markdown; the raw is_skill_dir_identical_to_source / dircmp_equal helpers move here unchanged (keeps skill_integrator.py under the 2100-line cap).
src/apm_cli/core/deployment_ledger.py Adds has_receipt(path): whether any receipt, trusted or not, exists for a physical path.
src/apm_cli/integration/skill_integrator.py _copy_skill_bundle computes adoption baselines before copying, falls back to them in baseline_hash, and disables the raw unchanged shortcut only when adoption applies. _resolve_markdown_links_in_skill_bundle uses the shared renderer so the comparison and the write cannot drift.
tests/integration/test_cold_restore_skill_adoption_lifecycle.py (new, lifecycle_smoke, installed CLI) Git-backed claude_skill / skill_bundle packages (no apm.yml, bundle with a rendered link), committed, cloned, machine state evicted; install and --frozen.
tests/integration/test_cold_skill_receipt_preservation.py #3490's byte-identical overlapping replay now succeeds with lock and bytes intact and receipts recorded; edited variants still fail closed.
tests/unit/integration/test_skill_adoption.py, tests/unit/test_deployment_materialization_receipts.py Tree-difference, ignore-filter, rendered-link, symlink and ownership contracts; repeated unowned delivery gains no receipt.
Docs + apm-usage/commands.md Document cold-restore adoption and its limits.

Diagrams

Legend: the cold-restore decision inside _copy_skill_bundle; dashed nodes are new, every other node is existing #3490 behavior.

flowchart LR
    A["_copy_skill_bundle"] --> B{"any receipt for SKILL.md?"}
    B -->|"yes (warm)"| W["guarded write as before"]
    B -->|"no (cold)"| C["adoptable_skill_members: tree == rendered output?"]
    C -->|"no: extra, missing or edited file"| R["refuse member, nonzero exit (#3490)"]
    C -->|yes| D{"every member claimed in apm.lock.yaml?"}
    D -->|no| R
    D -->|yes| E["on-disk hash becomes baseline"]
    E --> F["guarded write rewrites identical bytes"]
    F --> G["session.record: receipt written"]
    classDef changed stroke-dasharray: 5 5;
    class C,D,E changed;
Loading

Trade-offs

  • Whole-directory, not per-file, adoption. Per-file adoption would let a cold upgrade that drops a file exit 0 and then retire the dropped file through lock-hash-based stale cleanup. The strict tree check keeps that case fail-closed (test_missing_receipt_errors_reach_install_from_every_skill_target still requires nonzero).
  • Rewrite identical bytes instead of skipping the write. Reusing the guarded write path avoids a new authority branch in copy_directory_files and records receipts through the one existing owner; only mtimes change.
  • Applies in the shared materializer, so .apm sub-skills benefit too when their committed copy is link-rendered. Their raw-identity shortcut is unchanged, including for unowned files (no receipts).
  • Out of scope, unchanged: --force, receipt root identity ([BUG] apm install -g fails with 'installation binding does not match' after a reboot when home is a btrfs subvolume #3421), other primitive types, and cold upgrades whose source changed (still fail closed per fix(install): preserve skills during cold replay without deployment receipts #3490).

Benefits

  1. Fresh-clone apm install and --frozen exit 0 for unchanged committed claude_skill and skill_bundle output, with git status clean and apm audit --ci green.
  2. Receipts exist after the first cold install, so later upgrades no longer need --force.
  3. Edited files still produce the fix(install): preserve skills during cold replay without deployment receipts #3490 refusal, guidance and nonzero exit, with no overwrite or deletion.

Issue and approved scope

Issue: Fixes #3391

Human scope-approval comment: #3391 (comment) (approved by Daniel Meppiel (@danielmeppiel) at Gate B on 2026-11-10, held until #3490 merged on 2026-11-11). scripts/governance/eligibility.cjs at 77708eb7 returned record-present.

Does this PR complete the issue, or what remains? It completes the approved scope. Cold upgrades with changed source remain fail-closed by design (#3372 / #3490).

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (two parallel-order flakes in unrelated modules pass in isolation; see below)
  • Added tests for new functionality (if applicable)

Validation

Exact command Result
APM_BINARY_PATH=$PWD/.venv/bin/apm python -m pytest -n 8 tests/integration/test_cold_restore_skill_adoption_lifecycle.py tests/integration/test_cold_skill_receipt_preservation.py tests/integration/test_obsolete_dependency_claim_lifecycle.py tests/integration/test_shared_skill_preservation_lifecycle.py (head 94603866) Passed: 102
python -m pytest -n 8 tests/unit/test_deployment_materialization_receipts.py tests/unit/integration tests/unit/install (head 94603866) Passed: 5769, 2 skipped
python -m pytest -n 8 tests/unit tests/test_console.py (first commit) 26026 passed; 2 failed (test_manifest_extension_keys::…warns_once_per_invocation, test_targets_phase::…names_config_source), both pass when rerun alone and touch no skill code
python -m pytest -n 8 tests/quality Passed: 161
python scripts/check_test_assertions.py / scripts/check_exact_test_duplicates.py Both ratchets clean
PATH=.venv/bin:$PATH APM_E2E_TESTS=1 python -m pytest -n 8 --dist loadgroup -m 'lifecycle_smoke and not lifecycle_merge_group' tests/integration (head 1f6d1207) Passed: 452, 17 skipped (includes the 8 new cases)
… pytest -n 8 tests/integration/test_frozen_no_rewrite_e2e.py <cold-skill suites> tests/unit/test_deployment_materialization_receipts.py tests/unit/integration tests/unit/install (head 1f6d1207) Passed: 5872, 2 skipped
Lint mirror: ruff check + format check, pylint R0801, lint-auth-signals.sh, lint-architecture-boundaries.sh, file length, relative_to guard All clean; skill_integrator.py is 2099 lines
Mutation and real-package evidence
  • Reverting skill_integrator.py to main: the 4 test_fresh_clone_adopts_unchanged_committed_skills cases fail with [x] 1 package failed:; the 4 edited cases still pass, so the byte-identical case fails on current main.
  • test_frozen_no_rewrite_e2e.py::test_frozen_install_fails_on_unrecorded_skill_without_rewriting_lockfile caught an intermediate version that bypassed the raw shortcut whenever the baseline was untrusted (receipt file rewritten on a converged frozen replay); gating on receipt absence (1f6d1207) fixes it.
  • test_repeated_identical_unowned_delivery_does_not_create_local_authority failed (assert not True: receipt written) before the lockfile-claim fix in 94603866, and passes after it.
  • Real packages, fresh clone, empty HOME, local CLI build:
    • obra/superpowers#v7.0.0 (skill_bundle): apm install returned exit 1 with 34 refusals on main; on this branch it returns exit 0 and git status --short is empty.
    • Aaronontheweb/dotnet-skills/skills/aot-trimming#v1.7.1 (claude_skill): apm install --frozen returns exit 0, git status --short is empty, and apm audit --ci --no-policy reports All 10 check(s) passed.

Scenario Evidence

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 A fresh clone with committed, unchanged skills restores with apm install or --frozen: exit 0, bytes and lock intact, receipts recorded, audit green Portability, DevX tests/integration/test_cold_restore_skill_adoption_lifecycle.py::test_fresh_clone_adopts_unchanged_committed_skills e2e (installed CLI)
2 A locally edited skill file is neither overwritten nor deleted, and install exits nonzero with guidance Secure by default …::test_fresh_clone_with_edited_skill_fails_closed, test_cold_skill_receipt_preservation.py::test_cold_overlapping_skill_replay_preserves_files_and_lock[*-edited-*] e2e
3 A cold upgrade with changed source still fails closed (no lock-hash trust) Secure by default test_cold_skill_receipt_preservation.py::test_missing_receipt_errors_reach_install_from_every_skill_target integration
4 Identical but unowned files never gain local authority Secure by default tests/unit/test_deployment_materialization_receipts.py::test_identical_unowned_members_do_not_create_local_authority, …::test_repeated_identical_unowned_delivery_does_not_create_local_authority unit
5 Overlapping and user-scope (--global) replay of unchanged skills succeeds Portability test_cold_skill_receipt_preservation.py::test_cold_overlapping_skill_replay_preserves_files_and_lock[*-unchanged-*] integration

How to test

  • APM_BINARY_PATH=$PWD/.venv/bin/apm uv run --extra dev pytest -q tests/integration/test_cold_restore_skill_adoption_lifecycle.py → 8 passed.
  • In a scratch repo: apm install a dependency on obra/superpowers#v7.0.0, commit, git clone it, then HOME=$(mktemp -d) apm install in the clone → exit 0 and git status --short is empty.
  • Edit one deployed SKILL.md in the clone and repeat → nonzero exit, no trustworthy local deployment baseline with "Move the conflicting file aside and retry", and the edit is preserved.

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. Local deployment receipts are implementation state (req-tg-009 covers agent adoption only); the commits carry an apm-spec-waiver trailer.

Co-authored-by: Copilot [email protected]

When local deployment receipts are missing (fresh clone, CI runner,
Renovate), a native skill or skill bundle directory is adopted when every
file equals what this install would write -- the admitted source member
after final link rendering -- with no extra or missing files and every
member claimed in apm.lock.yaml. The verified on-disk hash stands in for
the missing baseline, so the guarded write path rewrites identical bytes
and records receipts. Lockfile hashes are never used as evidence; any
difference keeps the #3372 fail-closed refusal (#3490).

apm-spec-waiver: local deployment receipts and cold-restore skill adoption are implementation state not covered by any OpenAPM v0.1 requirement

Fixes #3391

Co-authored-by: Copilot App <[email protected]>
Same-run session hashes from the raw unchanged shortcut are not
ownership evidence; adoption now requires every member to be claimed by
apm.lock.yaml so unowned identical files never gain receipts.

apm-spec-waiver: local deployment receipts and cold-restore skill adoption are implementation state not covered by any OpenAPM v0.1 requirement

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

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

The adoption flow can overwrite unverified edits through a baseline-hashing race, grant receipts to initially unowned skills, and accept incompletely inspected trees.

3 open issues
What changed in this PR

This PR restores cold installs of unchanged, committed skills for fresh clones and CI runners, while preserving the fail-closed behavior introduced by #3490 for conflicting content.

Changes:

  • Compare complete skill file trees against rendered package output before adopting lockfile-claimed files and recording receipts.
  • Add cold-restore, edited-file preservation, and ownership regression coverage.
  • Document adoption requirements and recovery behavior in the CLI reference, consumer guide, and packaged usage guide.
File Description
src/​apm_cli/​integration/​skill_adoption.py Adds rendered-tree comparison and adoption baseline helpers.
src/​apm_cli/​integration/​skill_integrator.py Integrates adoption into guarded skill writes and shares Markdown rendering.
tests/​unit/​integration/​test_skill_adoption.py Covers tree equality, rendering, symlinks, and ownership requirements.
tests/​unit/​test_deployment_materialization_receipts.py Checks repeated unowned delivery does not create receipts.
tests/​integration/​test_cold_restore_skill_adoption_lifecycle.py Exercises fresh-clone restoration and edited-file refusal through the installed CLI.
tests/​integration/​test_cold_skill_receipt_preservation.py Updates overlapping replay expectations for unchanged skills.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents cold-restore adoption in the packaged guide.
docs/​src/​content/​docs/​reference/​cli/​install.md Explains adoption alongside local receipt protections.
docs/​src/​content/​docs/​consumer/​install-packages.md Describes successful adoption and fail-closed recovery.
CHANGELOG.md Records the cold-restore fix and its limits.

Review effort: Balanced

)
if not all(owned(path) for path in members):
return {}
return {path: compute_file_hash(path) for path in members}
member = Path(directory) / name
expected[destination / member.relative_to(source)] = member
actual: set[Path] = set()
for directory, directories, filenames in os.walk(destination):
Comment on lines +496 to +499
def claimed(path: str) -> bool:
return managed_files is not None and (
path in managed_files or (path == anchor and directory_entry in managed_files)
)
A warm replay whose receipt exists but yields no trusted baseline (for
example root-local skills) keeps the raw unchanged shortcut, so frozen
replays no longer rewrite receipt state. Adoption now applies only when
no receipt record exists for the skill anchor.

apm-spec-waiver: local deployment receipts and cold-restore skill adoption are implementation state not covered by any OpenAPM v0.1 requirement

Co-authored-by: Copilot App <[email protected]>
Keep the PR changelog bullet under [Unreleased] after the 0.35.1 release cut.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 95de605 into main Nov 12, 2026
27 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-3391-adopt-committed-skills-cold-res branch November 12, 2026 09:03
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.

[BUG] 0.35.0: restoring from the lockfile on a fresh machine deletes committed skill files (claude_skill and skill_bundle packages)

2 participants