Skip to content

fix(install): skill adoption accepts a locked-render match without a local receipt; cleanup retains files the install kept - #4258

Merged
Daniel Meppiel (danielmeppiel) merged 35 commits into
mainfrom
danielmeppiel-scaling-telegram
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 35 commits into
mainfrom
danielmeppiel-scaling-telegram

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Skill adoption accepts a locked-render match without a local receipt, and cleanup retains files the install kept.

Required tests for the step-5 contract and the cleanup rule:

  • tests/integration/test_checkout_switch_skill_lifecycle.py::test_branch_switch_then_source_edit_never_deletes_skill_members (clean, dirty): after a branch round trip, a source edit to a skill with no trustworthy baseline exits non-zero, keeps the user's bytes, keeps apm.lock.yaml byte-unchanged and prints a recovery scoped to that skill. Running the recovery converges and keeps a genuine edit in another deployed skill.

  • tests/integration/test_checkout_switch_skill_lifecycle.py::test_discarded_deploy_then_source_edit_installs and ::test_user_scope_discarded_deploy_then_source_edit_installs (checkout, stash, reset): the revert variant installs in one step and deletes nothing.

  • ::test_member_skipped_as_modified_is_never_stale (project, user): a skipped member is never cleaned as stale.

  • ::test_member_removed_from_source_is_still_cleaned: a member removed from source is still deleted.

  • ::test_source_edit_after_branch_round_trip_installs_without_recovery: strict expected failure tracked by Round-trip a source edit after a branch switch without a manual recovery step (multi-hash receipt history) #4428.

  • Receipt trust has one owner (DeploymentMaterializationSession.baseline). A receipt is trusted when its owner and claim signature bind to the current lock claim AND either the lock records the receipted hash or the file still holds the receipted bytes. The lock can only withdraw trust, never grant it. A receipt written under another checkout's lock therefore never vouches for, or refuses, different bytes on disk.

  • Skill adoption (skill_adoption.skill_tree_baselines, shared by preflight and materialization) skips adoption only when every file in the tree still holds the bytes this installation receipted there. Otherwise each member matches its own trusted receipt or the current or locked (link-rewritten) render. Adopted hashes take precedence over a receipt the file no longer holds.

  • Cleanup retains kept members. Members that the skill integrator declares but leaves unwritten are recorded as kept (DeploymentMaterializationSession.keep -> ctx.kept_deployed_values -> DeploymentEvidence.kept). remove_stale_deployed_files retains them before any deletion gate, so their lockfile entries carry forward.

  • Actionable refusal. When no trustworthy baseline exists for a locally edited skill (no receipt matches the disk, and no render does), install refuses without changing anything. It names the deployed skill directory and the recovery: move it aside (or delete it if it holds no edits), then run apm install. This is the strict known cell; multi-hash receipt history is planned for 0.38.

  • Two closed-world guards plus mutation cases: install-deployment-skill-adoption-trusted-receipt and install-deployment-cleanup-retains-kept-members.

Steward note

  • Step 5 (a source edit after a branch round trip with no reinstall) fails closed: install exits 1, keeps every byte on disk and apm.lock.yaml unchanged, and prints a recovery scoped to the refused skill. Running it rewrites only that skill and never overwrites edited files elsewhere. Installing the edit in one step needs multi-hash receipt history, tracked by Round-trip a source edit after a branch switch without a manual recovery step (multi-hash receipt history) #4428 (0.38.0) and pinned by a strict expected-failure cell.
  • Expectation changes: test_receipt_outlives_checked_out_hash_only_while_disk_holds_it (a receipt for another lock's hash vouches only for bytes the file still holds) and the refusal guidance pinned in test_cold_skill_receipt_preservation (scoped recovery, no global --force).

Issue and approved scope

Issue: Fixes #4229
Issue: Fixes #4230

Human scope-approval comment: #4229 (comment) and #4230 (comment)

Does this PR complete the issue, or what remains? Completes both issues.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Validation evidence:

promise: I7 + req-lk-024 -- install never deletes a declared skill member and accepts bytes equal to its render (source: docs/src/content/docs/specs/openapm-v0.1.md#req-lk-024)
cell: OP=install SRC=git|local PRIM=skill SCOPE=project|user DEPLOYED=committed LOCK=switched|restored
owner: core/deployment_ledger.py baseline + integration/skill_adoption.py skill_tree_baselines + integration/cleanup.py remove_stale_deployed_files
instrument: today test -> tests/integration/test_checkout_switch_skill_lifecycle.py (new: no module covered checkout switches)
oracles: I1, I2, I7, snapshot equality, lock bytes unchanged, executed recovery hint
guard+mutation: install-deployment-skill-adoption-trusted-receipt, install-deployment-cleanup-retains-kept-members
ledger: #4229, #4230
hints executed: "move .agents/skills/x/ aside ... then run 'apm install'" -> exit 0, source edit deployed
  • APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_checkout_switch_skill_lifecycle.py tests/integration/test_frozen_no_rewrite_e2e.py tests/integration/test_cold_restore_skill_adoption_lifecycle.py -> passed
  • Neighbour lifecycle modules (skill materialization receipts, obsolete claims, cold receipt preservation, update receipt-less, lock-derived expected state) -> 117 passed
  • uv run --extra dev pytest tests/unit/integration tests/unit/test_deployment_materialization_receipts.py tests/quality/test_lifecycle_bug_ledger.py tests/unit/scripts/test_architecture_runner.py -> passed
  • Lint chain (ruff check, ruff format --check, pylint R0801, lint-auth-signals, complexity ratchet, architecture linter) -> clean

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: retention and adoption stay within req-lk-024 evidence rules; no new normative surface

…cleanup retains kept skill members

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…es render or own receipt; lifecycle tests

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
…-switch skill trust

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 20, 2026
…e is still cleaned

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

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

Unresolved issues make user-scope and Cowork recovery unusable, allow stale receipts to bypass baseline validation, and introduce O(M*K) cleanup costs.

3 open issues
What changed in this PR

Addresses #4229 and #4230 by refining skill adoption after checkout changes and preventing install cleanup from deleting declared files that were left unwritten.

Changes:

  • Refines receipt trust and allows skill adoption through current or locked rendered content.
  • Carries kept members into cleanup retention and adds directory-level recovery guidance.
  • Adds regression coverage, architecture guards, and updated installation documentation.
File Description
tests/​unit/​test_deployment_materialization_receipts.py Updates receipt-trust expectations.
tests/​unit/​scripts/​test_architecture_runner.py Registers the new guard inventory.
tests/​unit/​integration/​test_skill_preflight.py Checks expanded recovery guidance.
tests/​unit/​integration/​test_skill_adoption.py Covers mixed receipt and render matches.
tests/​unit/​integration/​test_cleanup_helper.py Tests kept-member retention and deletion controls.
tests/​integration/​test_checkout_switch_skill_lifecycle.py Exercises checkout switching, recovery, and cleanup.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds mutations for both architecture guards.
tests/​fixtures/​lifecycle_bug_ledger.json Records regressions for both issues.
src/​apm_cli/​integration/​skill_preflight.py Supplies the recovery directory.
src/​apm_cli/​integration/​skill_integrator.py Records skipped members and prioritizes adopted baselines.
src/​apm_cli/​integration/​skill_adoption.py Compares members against trusted receipts or renders.
src/​apm_cli/​integration/​cleanup.py Retains kept members before deletion checks.
src/​apm_cli/​integration/​base_integrator.py Adds skill-directory recovery instructions.
src/​apm_cli/​install/​phases/​integrate.py Collects kept skill members into install state.
src/​apm_cli/​install/​phases/​cleanup.py Passes kept members into cleanup evidence.
src/​apm_cli/​install/​context.py Stores kept deployment values.
src/​apm_cli/​core/​deployment_ledger.py Refines receipt trust and tracks kept members.
scripts/​architecture_linter/​checks/​install_deployment_analyzers.py Registers the new architecture checks.
scripts/​architecture_linter/​checks/​install_checkout_skill_trust.py Guards receipt trust and cleanup retention.
docs/​src/​content/​docs/​reference/​cli/​install.md Documents adoption, retention, and recovery behavior.
CHANGELOG.md Summarizes the user-visible fixes.
.apm/​architecture/​owners/​install-deployment.json Updates ownership contracts and guard references.

Review effort: Balanced

Comment thread src/apm_cli/core/deployment_ledger.py Resolved
Comment thread src/apm_cli/integration/cleanup.py Resolved
apm-spec-waiver: retention and adoption stay within req-lk-024 evidence rules; no new normative surface

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…te recovery; O(1) kept lookup

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…R1-R4 no-loss controls

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…oject and user scope

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…er match without a local receipt; cleanup retains files the install kept

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…er match without a local receipt; cleanup retains files the install kept

Co-authored-by: Copilot App <[email protected]>
…; strict known cell for step 5

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…er match without a local receipt; cleanup retains files the install kept

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
#4258 makes kept a required keyword (explicit kept=() at non-install callers); #4394's frozen_withdrawal caller predates that and relied on the old default.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…er match without a local receipt; cleanup retains files the install kept

Co-authored-by: Copilot App <[email protected]>

# Conflicts:
#	src/apm_cli/integration/cleanup.py
#	tests/fixtures/lifecycle_bug_ledger.json
#	tests/quality/lifecycle_obligations.json
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…er match without a local receipt; cleanup retains files the install kept

Co-authored-by: Copilot App <[email protected]>

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
#	tests/quality/lifecycle_obligations.json
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d1e4938 into main Nov 21, 2026
59 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-scaling-telegram branch November 21, 2026 05:24
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

2 participants