Repository navigation
fix(install): replace a managed file only with deployment evidence (#4360) - #4382
Merged
Daniel Meppiel (danielmeppiel) merged 12 commits intoNov 21, 2026
Merged
Daniel Meppiel (danielmeppiel) merged 12 commits into
Daniel Meppiel (danielmeppiel) merged 12 commits into
Conversation
…4360) BaseIntegrator._check_adopt_or_skip, the one adopt/overwrite owner for instructions, agents, prompts, commands and rules, now replaces an existing managed file that differs from the render only when this checkout holds a trusted receipt for it or its bytes equal the locked render (DeploymentEvidence, req-lk-024). The lockfile hash is never consulted. Otherwise the file is kept, its prior lock entry stays, the other files are written and recorded, and install exits 1 naming each kept file with the remedy. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…4360) Installed-CLI tests at project and -g scope for instructions, agents, prompts, commands and rules: an edited receipt-less file is kept, named and exits 1 (also when the lock hash is forged to the edit), render-equal files adopt silently, and a git upgrade replaces files equal to the locked render while keeping the edited one. All but the adopt controls fail on main. install-deployment-overwrite-evidence guards the owner, the evidence decision and every file-primitive writer, with mutation proofs. Unit tests that exercise a managed overwrite now model a receipted reinstall. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 15:34
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical overwrite-authorization gaps can allow locally edited files to be replaced without trusted evidence, while transformed-command adoption and linter enforcement also remain unresolved.
4 open issues
What changed in this PR
This PR extends APM's deployment-evidence checks to managed-file overwrites, addressing #4360. It uses per-file refusal while leaving whole-install preflight to #4381.
Changes:
- Adds a shared overwrite gate using trusted receipts or locked-render evidence rather than lockfile hashes.
- Preserves refused files and their prior lock entries, records successful writes, and reports failure at finalization.
- Adds lifecycle coverage, architecture checks, and user documentation.
| File | Description |
|---|---|
tests/utils/deployment_evidence.py |
Adds an overwrite-evidence helper for integrator tests. |
tests/unit/scripts/test_architecture_runner.py |
Registers the overwrite guard in the expected rule inventory. |
tests/unit/integration/test_kiro_target.py |
Supplies evidence for managed-agent replacement tests. |
tests/unit/integration/test_instruction_integrator.py |
Supplies evidence for instruction and rule overwrite tests. |
tests/unit/integration/test_deployed_files_manifest.py |
Supplies evidence for managed-file manifest tests. |
tests/unit/integration/test_agent_integrator.py |
Supplies evidence for agent update tests. |
tests/unit/install/test_finalize_phase.py |
Extends the fake context with kept-file reporting state. |
tests/integration/test_receiptless_overwrite_lifecycle.py |
Covers refusal, adoption, forged hashes, and partial upgrades. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds overwrite-guard mutation cases. |
tests/fixtures/lifecycle_bug_ledger.json |
Records #4360 and its regression coverage. |
src/apm_cli/integration/base_integrator.py |
Adds shared overwrite authorization and refusal behavior. |
src/apm_cli/install/phases/integrate.py |
Binds evidence and tracks retained entries and successful writes. |
src/apm_cli/install/phases/finalize.py |
Reports kept files and marks the install unsuccessful. |
src/apm_cli/install/phases/cleanup.py |
Merges cleanup retention with overwrite retention. |
src/apm_cli/install/context.py |
Stores kept-file and written-file reporting state. |
src/apm_cli/core/deployment_ledger.py |
Adds overwrite gates and extends receipt authorization. |
src/apm_cli/core/command_logger.py |
Reports partial writes and retained lock entries. |
scripts/architecture_linter/checks/install_overwrite_evidence.py |
Adds checks for overwrite authorization and writer routing. |
scripts/architecture_linter/checks/install_deployment_analyzers.py |
Registers the new architecture rule. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Documents overwrite evidence and recovery options. |
docs/src/content/docs/reference/cli/install.md |
Explains retained files and partial-install behavior. |
CHANGELOG.md |
Adds the user-facing overwrite-protection entry. |
.apm/architecture/owners/install-deployment.json |
Records overwrite authority and its architecture guard. |
Review effort: Balanced
…nce (#4360) - Claude/Cursor/Gemini commands are transformed: the adopt check now compares the rendered text, so render-equal commands on a clone adopt instead of being falsely refused (J02/J03 frozen exit 0 again). - A local bundle's freshly deployed bytes are its render: a receipt-less legacy .github/skills copy equal to them migrates; an edited one is kept, named and exits 1 (#4049 residual). - --frozen no longer prints 'Deployed files verified' after failing. - Frozen replay of 0.35.1 renders keeps those files (steward-approved); goldens J01/06, J02/02, J03/02 re-recorded; J02 known cell -> #4183. - Generator citation re-anchored; obligations regenerated; upgrade note. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]> # Conflicts: # tests/fixtures/lifecycle_bug_ledger.json # tests/quality/lifecycle_obligations.json
Commands are transformed, so adoption compares the render, not the raw source; the unit test pre-places what APM writes. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
This was referenced Nov 20, 2026
… bytes (#4360) Steward ruling on review threads: a trusted receipt (owner and claim bound) proves APM deployed the path, not that the user left it alone. overwrite_authorized now also requires the current bytes to equal the receipted hash, failing closed on read errors, and its fallback uses the receipt-free DeploymentEvidence.render_verdict, so a receipt the bound session rejected can never authorize through the render path. The closed-world guard pins the exact write condition and the byte check; new mutation proofs: an 'or True' write, a bytes-unchecked receipt. New failing-before installed-CLI test: a receipted file edited after deployment is kept on an upstream change (project and -g). A Gemini command adopts its rendered TOML. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]> # Conflicts: # tests/quality/lifecycle_obligations.json
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
…loyment evidence (#4360) Co-authored-by: Copilot App <[email protected]> # Conflicts: # tests/lifecycle/generator/rules.py # tests/quality/lifecycle_obligations.json
The frozen replay now asserts the printed recovery for kept files: move them aside, then 'apm install' (or --force). Steward audit. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
…loyment evidence (#4360) Co-authored-by: Copilot App <[email protected]> # Conflicts: # tests/quality/lifecycle_obligations.json
Three lifecycle oracles repaired a tampered managed file with a plain 'apm install' (self-audit changed-file repair, required tamper repair, cursor legacy globs rule). Under #4360 install keeps a file it cannot prove it wrote: each now asserts the refusal (exit 1, named, bytes kept) and then executes the printed remedy (move it aside, then install). The Gemini adopt unit test asserts the file's bytes (AQ003). Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
…loyment evidence (#4360) Co-authored-by: Copilot App <[email protected]> # Conflicts: # tests/quality/lifecycle_obligations.json
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
…loyment evidence (#4360) Co-authored-by: Copilot App <[email protected]>
test_install_audit_tamper_audit_reinstall_audit_loop asserts the refused reinstall (exit 1, the kept file named with its remedy, bytes kept), then executes the remedy (move aside, install) and audits clean. test_managed_file_collision_not_skipped models a receipted reinstall; the new test_managed_file_without_evidence_is_kept pins the refusal. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Co-authored-by: Copilot App <[email protected]>
This was referenced Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
…4382 rule lists) Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
… JSON is receipted Steward ruling (journeys run 44827495768): a repeat install printed "|-- N prompts/agents/commands/instruction(s) adopted -> <dir>" for files already holding the render. Receipts did exist (the first install records them); the defect was the summary: install/services.py emitted a per-kind line for pure adoption and a "(N adopted)" suffix in default output. Adoption changes nothing, so it is now --verbose only (#4382/#4360, I2); the per-kind hints still run. Cell (b) also exposed a gap: an unchanged managed hook JSON (write_text_if_changed returned False) recorded no receipt on a receipt-less clone. It now records one, like the other managed adoptions. Cells: test_a_repeat_install_is_a_quiet_no_op (a: no "adopted", receipt store and lock byte-unchanged) and test_a_receiptless_clone_install_receipts_every_file_quietly (b: exit 0, no "adopted", a receipt per file primitive equal to its bytes, audit --ci clean). Re-pointed to the ruling (default silent; --verbose keeps the adoption lines): test_services_rendering (+ default-silent case), test_install_services_orchestration / _phase3w5, test_install_summary_destinations_lifecycle, and goldens J01/06, J02/02, J03/02 (the 4 adopted lines removed; J01/J02 FORBID 'adopted' stands). Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-4360-edited-managed-files
branch
November 21, 2026 05:24
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
A receipt-less
apm installoverwrote user-edited managed instruction, agent, prompt, command and rule files. This happens on a fresh clone, or on a project last installed by an APM that recorded no receipts, and it predates 0.37: v0.36.1 also rewrites them. It also overwrote when the lockfile hash had been edited to match the user's bytes.Fix, in one owner.
BaseIntegrator._check_adopt_or_skipalready decides adopt-or-write for every file primitive. It now replaces an existing managed file that differs from the render only with deployment evidence (steward ruling Q1):DeploymentMaterializationSessionbaseline, extended from skill paths to every file primitive through_write_locator(owner and claim bind, lock records the path); orDeploymentEvidencerender owner, so an unedited file from an older APM still updates on a version change.The lockfile hash is never consulted. Render-equal files still adopt silently (req-lk-024).
recorded_writesbinds anOverwriteGatearound every integrator call. Without an installation-bound session nothing is authorized; that is closed-world.Per-file refusal (steward ruling Q2, accepted for 0.37).
package_cleanup_retainedpath.apm.lock.yaml keeps the previous entries of the N kept file(s).The whole-plan preflight is deferred to 0.38 as #4381, next to #4282.
Pinned output (project scope;
-gprintsapm install -g):Closed-world guard. The new
install-deployment-overwrite-evidencearchitecture rule enforces three things:force, a missing file, orOverwriteGate.authorizes;overwrite_authorizeddecides only from_trusted_hash(..., self._write_locator)or the renderverdictand reads no lockfile hash surface;recorded_writesbinds the gate;There is one MutationCase in the matrix, plus 3 closed-world mutation proofs: a lockfile-hash authorizer, an unbound gate, and a writer that bypasses the owner.
Known limits:
.) file without evidence still fails before the lockfile commit, as before, rather than keeping its prior entry.Residual from #4049 (a legacy
.github/skillsbundle installed receipt-less by 0.36.1, then migrated): its evidence lives in skill path migration, not in this owner. I'll follow up with it right after this PR. #4302 already turns the twotest_agent_skills_targetauto-migration tests green.Issue and approved scope
Issue: Fixes #4360
Human scope-approval comment: #4360 is HARD for 0.37.0. The scope and steward rulings (Q1 evidence, Q2 atomicity) were relayed by the 0.37 Stream H lead.
Does this PR complete the issue, or what remains? It completes #4360. The whole-plan preflight is #4381 (0.38).
Type of change
Testing
pytest tests/integration/test_receiptless_overwrite_lifecycle.py(installed CLI,APM_BINARY_PATHat this worktree): 7 passed. Against main'ssrc: 5 failed, 2 passed; the two passes are the render-equal adopt controls (failing-before).pytest tests/integration/test_architecture_owner_rule_mutations.py -k "overwrite or every or registry or unique or guard_ids": 81 passed.pytest tests/unit/integration tests/unit/install tests/unit/core: the only failures (test_unix_install_ownership, the cowork version e2e and two core auth tests) fail identically on main in this environment.pytest tests/quality/test_lifecycle_bug_ledger.py tests/unit/scripts/test_architecture_runner.py tests/quality/test_test_taxonomy.py: passed.test_receiptless_install_keeps_each_edited_kind[project|user x recorded|forged-to-edit]test_receiptless_install_adopts_render_equal_files[project|user]test_receiptless_upgrade_replaces_files_equal_to_the_locked_renderP-LAW-ownership.preserve_unowned,P-LAW-outcome.status_matches_state.Failing-before evidence (installed CLI, head 4450272)
pytest tests/integration/test_receiptless_overwrite_lifecycle.pywithAPM_BINARY_PATHpointed at this worktree's editable install:origin/mainsrc/): 9 failed, 2 passed. The two passes are the render-equal adopt controls (test_receiptless_install_adopts_render_equal_files[project|user]). Failing:test_receiptless_install_keeps_each_edited_kind[project-recorded|project-forged-to-edit|user-recorded|user-forged-to-edit]test_receiptless_upgrade_replaces_files_equal_to_the_locked_rendertest_receiptless_legacy_bundle_skill_migrates_only_when_render_equal[unedited|edited]test_receipted_file_edited_after_deployment_is_kept_on_upgrade[project|user]The repair oracles moved by #4360 (self-audit changed-file repair, required tamper repair, cursor legacy
globsrule, frozen replay of 0.35.1 output) assert the refusal and then execute the printed remedy. CI on 4450272: all CI jobs green.Changelog
## [Unreleased]inCHANGELOG.md.Spec conformance (OpenAPM v0.1)
No spec change. The render-equal adopt and the receipt-or-render evidence apply the existing req-lk-024 deletion-evidence rule to overwrites.
Agent note, not authored by Daniel: opened by the #3701/#4360 implementation lane.