Skip to content

fix(install): replace a managed file only with deployment evidence (#4360) - #4382

Merged
Daniel Meppiel (danielmeppiel) merged 12 commits into
mainfrom
danielmeppiel-4360-edited-managed-files
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 12 commits into
mainfrom
danielmeppiel-4360-edited-managed-files

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

A receipt-less apm install overwrote 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_skip already 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):

  • (i) this checkout's trusted receipt: the DeploymentMaterializationSession baseline, extended from skill paths to every file primitive through _write_locator (owner and claim bind, lock records the path); or
  • (ii) bytes equal to what the locked versions render. This uses the existing #3701 (2/2) cleanup deletes only with deployment evidence, never a lockfile hash alone #4049 DeploymentEvidence render 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_writes binds an OverwriteGate around 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).

  • A kept dependency file stays in the package's deployed set with its PRIOR lock entry, through the existing package_cleanup_retained path.
  • Every other file is written and recorded, and the lockfile is committed, so the lockfile matches the project.
  • Finalize then fails with exit 1. It names each kept file with the remedy, lists the files this install wrote, and states that 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; -g prints apm install -g):

[x] ... Kept .github/instructions/style.instructions.md: it differs from what APM renders and there is no local deployment receipt or locked render proving APM wrote it, so it may hold local edits. Move it aside, then run 'apm install' to restore it; or run 'apm install --force' to overwrite it.
[x] Installation failed with 1 error(s) in 0.1s. apm.lock.yaml keeps the previous entries of the 1 kept file(s).

Closed-world guard. The new install-deployment-overwrite-evidence architecture rule enforces three things:

  • the owner has exactly one write-permitting return, and it sits behind force, a missing file, or OverwriteGate.authorizes;
  • overwrite_authorized decides only from _trusted_hash(..., self._write_locator) or the render verdict and reads no lockfile hash surface; recorded_writes binds the gate;
  • in the instruction, prompt, command and agent integrators, a function that writes bytes either asks the owner itself or is one of the listed leaf writers whose in-module callers all ask.

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:

  • A root-local (.) file without evidence still fails before the lockfile commit, as before, rather than keeping its prior entry.
  • A local-path dependency has no versioned locked render, so an edited-or-upgraded receipt-less file from it is kept until moved aside.
  • Files that match the lock but render differently under this APM version are kept rather than adopted, since a lock hash is no proof.

Residual from #4049 (a legacy .github/skills bundle 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 two test_agent_skills_target auto-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

  • Bug fix

Testing

  • Tested locally. Targeted runs only, per the speed rule:
    • pytest tests/integration/test_receiptless_overwrite_lifecycle.py (installed CLI, APM_BINARY_PATH at this worktree): 7 passed. Against main's src: 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.
    • ruff check and format (src, tests, linter), the architecture linter, the complexity ratchet and pylint R0801 are clean.
  • Added tests for new functionality:
    • 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_render
    • Ledger row 4360. Promise markers: P-LAW-ownership.preserve_unowned, P-LAW-outcome.status_matches_state.

Failing-before evidence (installed CLI, head 4450272)

pytest tests/integration/test_receiptless_overwrite_lifecycle.py with APM_BINARY_PATH pointed at this worktree's editable install:

  • Before (this branch's tests against origin/main src/): 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_render
    • test_receiptless_legacy_bundle_skill_migrates_only_when_render_equal[unedited|edited]
    • test_receipted_file_edited_after_deployment_is_kept_on_upgrade[project|user]
  • After (this head): 11 passed.

The repair oracles moved by #4360 (self-audit changed-file repair, required tamper repair, cursor legacy globs rule, frozen replay of 0.35.1 output) assert the refusal and then execute the printed remedy. CI on 4450272: all CI jobs green.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.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.

…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]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 15:34
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

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

Comment thread src/apm_cli/core/deployment_ledger.py Resolved
Comment thread src/apm_cli/core/deployment_ledger.py Resolved
…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
…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
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
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
… 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]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit b1b0aef into main Nov 21, 2026
41 of 43 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4360-edited-managed-files 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install overwrites user-edited managed files when no deployment receipt exists

2 participants