Skip to content

fix(install): deny retirement consistency when the lockfile is absent - #4644

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-pgm-engineer-sec-ql-hardening
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-pgm-engineer-sec-ql-hardening

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

When apm.lock.yaml has no record of a package (the lockfile was lost, not committed, or regenerated), apm install did not retire the hook files the executables gate no longer deploys for it, because cleanup only used the prior lock as the record of what was deployed. A project without its lockfile now converges exactly like one that kept it:

  • Files. When the prior lock does not record a package, this installation's local deployment receipts for that package stand in for its prior deployed_files (DeploymentEvidence.receipted_claims, install/phases/cleanup.py). Each receipt is spelled by the canonical deployment-path codec for the run's targets (for example cowork:// for an external root), so it compares with current claims in the same spelling. The normal stale-file cleanup then retires what the package no longer deploys, still gated by deployment evidence. Lockfile assembly reconciles the same stand-in record, so an edited file is kept and recorded with APM's hash, and apm audit --ci reports it, the same as with a kept lock.
  • Cross-package protection. Without a prior lock, surviving_deployed_paths still projects this run's claims, including root-local files, so a peer package's or the project's own file is never treated as stale.

deployment_ledger.receipt_hashes takes an optional owner filter. MCP entries are out of scope here: without a lockfile there is no per-entry write evidence, and equality with a declaration never removes one.

Issue and approved scope

Issue: none; scope set by the maintainers.

Human scope-approval comment: approved by the maintainers.

Does this PR complete the issue, or what remains? It completes the lost-lockfile retirement item.

Type of change

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

Testing

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

tests/integration/test_deny_retirement_without_lock_lifecycle.py (real binary, parametrized [kept|lost]): deny retires the hook (and, with the lock kept, the MCP entry), and an edited hook is kept and named by apm audit --ci. Both [lost] cases fail on main and pass with this change.

Unit: tests/unit/test_deployment_materialization_receipts.py pins the stand-in spelling for a project target and an external (cowork://) root; red before this change.

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
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour. It makes a lost-lockfile install converge to the existing kept-lockfile behaviour.

apm-spec-waiver: lost-lockfile install now converges to the existing kept-lockfile retirement behaviour; no new contract.

When apm.lock.yaml has no record of a package, its local deployment
receipts stand in for the prior deployed files, so install retires what
the executables gate no longer deploys and keeps edited bytes recorded
exactly as with a kept lockfile. A parked self-defined MCP server whose
runtime entry still equals its declaration is removed the same way.

Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: lost-lockfile install now converges to the existing kept-lockfile retirement behaviour; no new contract.

Co-authored-by: Copilot App <[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

Two critical issues can delete user-owned MCP servers without evidence of an APM write and remove still-deployed Cowork skills because receipt paths and current claim locators do not match.

2 open issues
What changed in this PR

This PR extends install cleanup to recover prior deployments when the lockfile is missing, aiming to make deny retirement consistent with the kept-lockfile flow.

Changes:

  • Uses installation-local receipts for stale-file cleanup and preserves recovered hashes during lockfile rebuilding.
  • Adds declaration-based retirement of unrecorded, parked MCP entries.
  • Adds kept/lost-lock lifecycle tests and documents the behavior.
File Description
tests/​integration/​test_deny_retirement_without_lock_lifecycle.py Tests retirement and edited-hook audit behavior with kept or lost locks.
src/​apm_cli/​integration/​mcp_config_view.py Retains parked MCP declarations for cleanup.
src/​apm_cli/​integration/​cleanup.py Exposes owner-filtered receipt claims.
src/​apm_cli/​install/​phases/​lockfile.py Reconciles recovered files and hashes into the new lockfile.
src/​apm_cli/​install/​phases/​cleanup.py Uses receipt-backed prior records and protects current deployments.
src/​apm_cli/​install/​mcp/​parked_retirement.py Adds declaration-matching cleanup for unrecorded MCP entries.
src/​apm_cli/​install/​mcp/​integration.py Invokes parked-entry retirement for selected runtimes.
src/​apm_cli/​install/​context.py Carries recovered deployment records between phases.
src/​apm_cli/​core/​deployment_ledger.py Adds an optional owner filter to receipt lookup.
docs/​src/​content/​docs/​reference/​cli/​deny.md Documents lost-lock retirement and edited-file handling.
changelog.d/​4644.fixed.md Adds a user-facing fix announcement.
.apm/​architecture/​owners/​install-deployment.json Includes parked retirement in the MCP ownership registry.

Review effort: Balanced

Comment thread src/apm_cli/integration/cleanup.py Resolved
… proof

An unrecorded MCP entry that equals a parked declaration may be the
user's own, so it is removed only when the install started without a
lockfile and local deployment receipts show APM integrated the declaring
package here. Without a prior lock, this run's root-local files also join
the survivor set. Re-anchors the lifecycle rule citations that moved.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 21, 2026
Lost-lockfile stand-ins now take each receipt's lock value from the
canonical deployment-path codec for the run's targets, so a file under an
external root compares with this run's claims in the same spelling. MCP
entry retirement without a lockfile is withdrawn from this change: no
per-entry write evidence exists, so equality alone never removes one.

Co-authored-by: Copilot App <[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 21, 2026
… are withheld

A dropped lock entry for a package the gate still admits keeps its
existing behaviour: an existing file stays a local collision and is never
retired. A path this run skipped as an existing local file is never stale.

Co-authored-by: Copilot App <[email protected]>
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.

2 participants