Skip to content

Owner moves: install entry routing, commit order and lockfile write authority - #4138

Closed
Daniel Meppiel (danielmeppiel) wants to merge 56 commits into
mainfrom
danielmeppiel-cautious-chainsaw
Closed

Daniel Meppiel (danielmeppiel) wants to merge 56 commits into
mainfrom
danielmeppiel-cautious-chainsaw

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Trust and integrity consistency hardening (owner consolidation), part of 0.37. H2 integration PR: install entry routing, commit order and lockfile write authority.

  • install-commit-order (install/commit_gate.py): every check completes before apm.lock.yaml and deployed files are committed. Merged direct + transitive MCP policy and require_hashes run after every package is acquired and before the first deployed byte; require_hashes runs again on the built lockfile before it is written. A failing check leaves the lockfile and deployed files byte-identical.
  • install-entry-routing: install --dry-run runs run_install_pipeline(dry_run=True) (resolution into rollback staging, policy gate and commit gate in preview mode, stop before the first write); ProspectiveInstallPlan projects that plan instead of running a second resolver.
  • lockfile-write-authority (from the Owner moves: one lockfile write authority with a closed writer set #4086 lane): one write authority for apm.lock.yaml with writer scopes per entry.

Also folded in: #4050 (--frozen with nothing declared is a converged no-op, matching audit --ci; GATE cell g dropped), #4132 (cleanup keeps project-layout target roots such as a pre-existing .github/), #4153 (transitive relative local paths at user scope), #4166 (apm update on a ref-less dependency is a no-op), #4176 (orphaned deployment receipts are collected), and installed-CLI targets parity tests for dependencies.apm vs dependencies.mcp (no divergence).

Reviewer note (#4132 behavior change): tests/integration/test_mcp_pruned_runtime_dir_cleanup_lifecycle.py previously asserted that an emptied opt-in .claude/ or .opencode/ root is pruned; it now asserts the root survives, with every MCP-cleanup assertion kept. User-scope roots APM created are still removed.

Guards: install-deployment-install-entry-routing, install-deployment-install-commit-order (includes the frozen pre-deploy check pin and the single InstallTransaction definition), contracts-tooling-lockfile-write-authority, install-deployment-lockfile-required, install-deployment-cleanup-target-roots, contracts-tooling-local-path-anchor; each has a mutation case.

Issue and approved scope

Part of #4085 (scope record: #4085 (comment))
Fixes #4086 (scope record: #4086 (comment))
Fixes #4050 (scope record: #4050 (comment))
Fixes #4132 (scope record: #4132 (comment))
Fixes #4153 (scope record: #4153 (comment))
Fixes #4166 (scope record: #4166 (comment))
Fixes #4176 (scope record: #4176 (comment))

Does this PR complete the issue, or what remains? It completes #4050, #4086, #4132, #4153, #4166 and #4176. For #4085 it lands the commit gate (checks before the lockfile and the first deployed byte), dry-run routing through the pipeline, the guards and the ledger row; the audit-gated target snapshot and the local-bundle and --mcp routing follow in a stacked PR that completes issue 4085.

Type of change

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

Testing

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

Red on main 1b96706, green on this branch (installed CLI, APM_BINARY_PATH=.venv/bin/apm):

  • tests/integration/test_install_commit_order_lifecycle.py::test_blocked_transitive_mcp_on_fresh_project_commits_nothing
  • tests/integration/test_install_commit_order_lifecycle.py::test_blocked_transitive_mcp_keeps_previous_install_byte_identical
  • tests/integration/test_install_commit_order_lifecycle.py::test_dry_run_reaches_the_install_decision_for_transitive_mcp
  • tests/integration/test_policy_install_e2e.py::TestI8TransitiveMCPDenied (rewritten: no lockfile or deployed-file change after a blocked install)

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md (pending)
  • 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 -- aligns install with existing req-pl-002; no spec text change.

apm-spec-waiver: owner consolidation that enforces the existing req-pl-002 commit order; no new normative behavior

Add install/commit_gate.py as the single owner of the checks that guard
the two install commit points. The merged direct and transitive MCP
policy and require_hashes now run after every package is acquired and
before the first deployed byte; require_hashes runs again on the built
lockfile before it is written. A failing check leaves apm.lock.yaml and
deployed files unchanged.

Refs #4085

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Add the lockfile-write-authority owner: a closed set of writer entry
points (install, install --mcp, local bundles, lock, update, uninstall,
prune, compile) that each commit apm.lock.yaml at most once per command.
LockFile.write stages inside a writer scope and LockFile.read sees the
staged document; removal and rollback route through the owner. Compile
refuses a lockfile it may not rewrite before changing files.

Guarded by contracts-tooling-lockfile-write-authority with a mutation
case, installed-CLI write-count tests and a writer mapping test.

Refs #4086

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Scopes open at a command's first lockfile write, so the newer-generator
gate always refuses first; a failed or interrupted command discards what
it staged. Adds per-sub-check guard mutations, a shrink-only commit-site
baseline, and installed-CLI proofs for frozen, failure and MCP+LSP
installs.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The preview now runs run_install_pipeline(dry_run=True): resolution into
rollback staging, the policy gate and the commit gate in preview mode,
then it stops before the first write. ProspectiveInstallPlan projects
that plan instead of running a second resolver, so dry-run and install
reach the same decisions. Extract the skill path migration phase and the
preserved-install hint to keep module budgets.

Refs #4085

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) changed the title Install owners: one entry pipeline and one commit point Owner moves: install entry routing, commit order and lockfile write authority Nov 20, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…d CLI

Run each writer in the closed set against a newer-generator lockfile and
assert no write, no file change and an unchanged manifest; keep policy on
in the lifecycle tests; leave install/phases/lockfile.py untouched (its
LOC budget), relying on the authority's read-through.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
With no APM, MCP or LSP dependency declared, apm install writes no
lockfile. One owner (install/plan.py manifest_requires_lockfile) now
answers whether a missing lockfile is converged, for both
apm install --frozen and the audit lockfile-exists check, so the two
agree at project and user scope. Removes the GATE machine's known cell
for this disagreement.

Refs #4050

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
… package at user scope (#4153)

A relative local_path declared by a dependency now resolves against the
declaring package at every scope via deps/path_anchoring.local_dep_base_dir.
An unresolvable transitive local dependency fails the install with a clear
error instead of being dropped silently.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ecorded ref (RA-007)

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

Add install-deployment-lockfile-required: manifest_requires_lockfile is
the one owner, and enforce_frozen, frozen service integration and the
audit lockfile-exists check route through it; no other function
re-derives the answer. Registered on frozen-install-mutation-eligibility
with a mutation case.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Add install-deployment-cleanup-target-roots: cleanup_empty_parents stops
at every target root, and integration/install-phase modules remove
directories only through it or a closed set of owned-directory
removals. Mutation case, ledger row and changelog.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Add closed-world rules install-deployment-install-entry-routing and
install-deployment-install-commit-order with mutation cases, register the
install-entry-routing and install-commit-order owners (InstallTransaction
included), and record the #4085 ledger row.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Installed-CLI parametrized test: valid, unknown, all, MCP-only runtimes
(intellij, copilot-app), a target outside the project's active set, a
path-like value and malformed shapes give the same exit code and reason
for dependencies.apm and dependencies.mcp, and refusals change nothing.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
5 of 14 tasks
The locked-render replay writes a private scratch copy of the lockfile
and reads it back at once. lockfile_scratch_writes persists it
immediately (never staged, never withheld by --frozen); the authority
guard registers the site and requires the context.

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
Receipt files are not packages, so their cleanup is not a second orphan
removal selector: rename collect_orphaned_receipts to
retire_receipts_of_missing_projects (owner, callers, guard, mutation case
and tests).

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-swe-agent[bot] <[email protected]>
An install that deployed files and then exits non-zero (a later MCP
conflict or native write failure) keeps the lockfile records of what
reached disk, as before the write authority; refusals still happen before
the first write, and only an interrupt or a non-zero sys.exit discards
what was staged. The commit-semantics proof now asserts one write that
records the deployed package.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
A failure after deploy still commits what reached disk (#4086); an
org-policy refusal raised after staging (require_hashes on the staged
lockfile, install-time audit) now discards the staged lockfile, so a failing
check leaves no committed lockfile state (#4085).

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Move the dry-run declared-policy preview into install/pipeline_entry.py and
dedupe CHANGELOG lines after the merge. Revert the lockfile refusal marker
here: without the audit-gated deploy restore (H2b), discarding the staged
lockfile on a refusal after deploy would leave the lockfile out of step
with disk.

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-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 20, 2026 11:46
Copilot AI balanced review requested due to automatic review settings November 20, 2026 11:46
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…eline import

install --dry-run runs resolution with config creation suppressed, so a
preview of remote packages leaves ~/.apm untouched. The workspace-lock
fixture declares nothing, so --frozen is a converged no-op (#4050).

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-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 critical findings permit MCP policy bypasses and unsafe install/update behavior that can leave deployed files, module checkouts, and lockfiles inconsistent.

8 open issues
What changed in this PR

This PR consolidates APM’s install routing, pre-deployment checks, and lockfile write ownership. It also addresses frozen installs with empty manifests, cleanup stability, user-scope local dependencies, ref-less updates, and orphaned deployment receipts.

Changes:

  • Routes package dry-runs through the install pipeline and checks merged MCP policy before deployment.
  • Centralizes lockfile persistence and adds architecture guards, mutation tests, and lifecycle regressions.
  • Updates documentation and release notes for the revised install and cleanup behavior.
File Description
tests/​utils/​lockfile_write_counter.py Adds filesystem-based lockfile write counting.
tests/​unit/​test_deployment_materialization_receipts.py Tests conservative receipt cleanup.
tests/​unit/​scripts/​test_architecture_runner.py Registers new guard expectations.
tests/​unit/​install/​test_sources_phase3.py Tests user-scope local-path anchoring.
tests/​unit/​install/​test_sources_materialisation.py Updates relative-path refusal assertions.
tests/​unit/​install/​test_require_hashes.py Tests the pre-write integrity gate.
tests/​unit/​install/​test_plan.py Tests when manifests require lockfiles.
tests/​unit/​install/​test_dry_run_graph.py Exercises pipeline-derived previews.
tests/​unit/​copilot_plugins/​test_pr2705_folds.py Updates integrity-gate patch location.
tests/​unit/​commands/​test_install_context.py Tracks MCP policy enforcement state.
tests/​spec_conformance/​test_copilot_plugins_reqs.py Uses pipeline previews in conformance tests.
tests/​integration/​test_update_ref_less_dependency_lifecycle.py Tests unchanged and moved default branches.
tests/​integration/​test_transitive_relative_local_path_lifecycle.py Tests transitive paths at both scopes.
tests/​integration/​test_policy_install_e2e.py Asserts blocked installs preserve committed state.
tests/​integration/​test_mcp_pruned_runtime_dir_cleanup_lifecycle.py Expects project target roots to survive.
tests/​integration/​test_lockfile_writer_mapping.py Tests command-to-writer routing.
tests/​integration/​test_install_dry_run_transitive_lifecycle.py Updates the test module description.
tests/​integration/​test_install_commit_order_lifecycle.py Tests policy refusal before deployment.
tests/​integration/​test_frozen_empty_manifest_lifecycle.py Tests empty-manifest frozen convergence.
tests/​integration/​test_deployment_receipt_gc_lifecycle.py Tests orphan receipt collection.
tests/​integration/​test_dependency_targets_parity_lifecycle.py Tests APM/MCP target validation parity.
tests/​integration/​test_cleanup_target_root_lifecycle.py Tests target-root preservation and convergence.
tests/​integration/​test_architecture_semantic_rule_mutations.py Updates integrity ownership mutation.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds owner-routing mutation cases.
tests/​integration/​test_architecture_lockfile_write_authority.py Tests write-authority guard checks.
tests/​integration/​_gate_machine_kit.py Removes empty-manifest known-failure allowances.
tests/​fixtures/​lifecycle_bug_ledger.json Records fixes and regression coverage.
src/​apm_cli/​policy/​install_preflight.py Extracts dry-run verdict rendering.
src/​apm_cli/​policy/​ci_checks.py Shares the lockfile-required decision.
src/​apm_cli/​models/​validation.py Separates config creation from validation mode.
src/​apm_cli/​models/​results.py Carries preview and policy enforcement results.
src/​apm_cli/​integration/​mcp_integrator.py Recognizes staged lockfile existence.
src/​apm_cli/​integration/​mcp_config_view.py Reads staged state without creating config.
src/​apm_cli/​integration/​lsp_integrator.py Recognizes staged lockfiles.
src/​apm_cli/​integration/​hook_ownership.py Uses staged-aware lockfile checks.
src/​apm_cli/​integration/​cleanup.py Separates scratch lockfile writes.
src/​apm_cli/​integration/​base_integrator.py Preserves target roots during cleanup.
src/​apm_cli/​integration/​_shared.py Reads staged lockfile source mappings.
src/​apm_cli/​install/​transaction.py Allows completion after preview rollback.
src/​apm_cli/​install/​sources.py Uses canonical local-path anchoring.
src/​apm_cli/​install/​source_helpers.py Hosts the preserved-install diagnostic helper.
src/​apm_cli/​install/​skill_path_migration.py Hosts skill migration orchestration.
src/​apm_cli/​install/​service.py Adds writer scope and dry-run routing.
src/​apm_cli/​install/​service_integration.py Handles empty frozen state and checked policy.
src/​apm_cli/​install/​request.py Adds preview and MCP routing options.
src/​apm_cli/​install/​plan.py Normalizes ref-less updates and lockfile requirements.
src/​apm_cli/​install/​pipeline_entry.py Defines pipeline preview routing and results.
src/​apm_cli/​install/​phases/​resolve.py Records preview gaps and anchors local dependencies.
src/​apm_cli/​install/​phases/​policy_gate.py Renders policy verdicts during previews.
src/​apm_cli/​install/​phases/​local_content.py Adds anchored local dependency copying.
src/​apm_cli/​install/​phases/​integrate.py Invokes the pre-deployment gate.
src/​apm_cli/​install/​phases/​claude_plugins.py Flushes lockfile state before native registration.
src/​apm_cli/​install/​package_resolution.py Shares user-scope path admission.
src/​apm_cli/​install/​outcome.py Propagates MCP policy enforcement status.
src/​apm_cli/​install/​mcp/​integration.py Supports prospective locks and shared policy enforcement.
src/​apm_cli/​install/​integrity.py Checks supplied prospective lockfile state.
src/​apm_cli/​install/​helpers/​no_work.py Uses staged-aware lockfile reads.
src/​apm_cli/​install/​errors.py Adds an incomplete-preview signal.
src/​apm_cli/​install/​dry_run_plan.py Projects pipeline results instead of resolving again.
src/​apm_cli/​install/​context.py Stores preview and MCP gate state.
src/​apm_cli/​install/​commit_gate.py Centralizes pre-deployment and pre-write checks.
src/​apm_cli/​install/​command_context.py Carries MCP gate status to services.
src/​apm_cli/​deps/​path_anchoring.py Owns install-time local-path anchoring.
src/​apm_cli/​deps/​lockfile.py Stages writes and reads staged documents.
src/​apm_cli/​deps/​dependency_graph.py Records unavailable preview subtrees.
src/​apm_cli/​deps/​apm_resolver.py Adds pipeline preview and config-creation controls.
src/​apm_cli/​core/​lifecycle_scripts.py Flushes lockfiles before lifecycle scripts.
src/​apm_cli/​core/​deployment_ledger.py Adds orphan receipt collection.
src/​apm_cli/​core/​command_logger.py Makes preview resolution progress verbose-only.
src/​apm_cli/​commands/​update.py Adds writer scope and forwards MCP trust.
src/​apm_cli/​commands/​uninstall/​cli.py Routes lockfile persistence and restoration through authority.
src/​apm_cli/​commands/​prune.py Adds writer scope and receipt cleanup.
src/​apm_cli/​commands/​lock.py Declares the lock command’s writer scope.
src/​apm_cli/​commands/​install.py Shares pipeline options and routes previews.
src/​apm_cli/​commands/​deps/​cli.py Declares the dependency-update writer scope.
src/​apm_cli/​commands/​compile/​cli.py Adds writer scope and newer-generator refusal.
scripts/​validate-1061-real-world.py Formatting-only cleanup.
scripts/​perf/​measure_dotnet_skills.py Formatting-only cleanup.
scripts/​generate-notice.py Formatting-only cleanup.
scripts/​bootstrap_requirements.py Formatting-only cleanup.
scripts/​benchmark_manifest_ops.py Formatting-only cleanup.
scripts/​architecture_linter/​groups/​contracts_tests.py Registers new contract guards.
scripts/​architecture_linter/​checks/​install_receipt_collection.py Guards receipt ownership and cleanup routing.
scripts/​architecture_linter/​checks/​install_lockfile_required.py Guards the shared lockfile-required decision.
scripts/​architecture_linter/​checks/​install_dry_run_plan.py Guards pipeline-derived preview ownership.
scripts/​architecture_linter/​checks/​install_deployment_analyzers.py Registers install and cleanup guards.
scripts/​architecture_linter/​checks/​install_cleanup_target_roots.py Guards target-root cleanup boundaries.
scripts/​architecture_linter/​checks/​contracts_update_plan_ref.py Guards recorded-ref comparison.
scripts/​architecture_linter/​checks/​contracts_lockfile_generator.py Adds compile generator-gate coverage.
scripts/​architecture_linter/​checks/​contracts_local_path_anchor.py Guards local-path anchor ownership.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Documents revised policy refusal behavior.
docs/​src/​content/​docs/​troubleshooting/​install-failures.md Documents compile’s newer-lockfile refusal.
docs/​src/​content/​docs/​reference/​lockfile-spec.md Updates writer and frozen-mode contracts.
docs/​src/​content/​docs/​reference/​cli/​install.md Documents pipeline previews and empty frozen installs.
docs/​src/​content/​docs/​reference/​cli/​compile.md Documents the pre-mutation generator check.
docs/​src/​content/​docs/​reference/​baseline-checks.md Clarifies lockfile presence requirements.
CHANGELOG.md Records user-visible fixes.
.apm/​architecture/​owners/​install-deployment.json Registers install routing and commit ownership.
.apm/​architecture/​owners/​contracts-tooling.json Registers lockfile and dependency decision ownership.

Review effort: Balanced

Comment thread src/apm_cli/commands/install.py Resolved
Comment thread src/apm_cli/commands/update.py Resolved
Comment thread src/apm_cli/install/commit_gate.py Resolved
Comment thread src/apm_cli/install/commit_gate.py Resolved
Comment thread src/apm_cli/core/deployment_ledger.py Resolved
Comment thread src/apm_cli/core/lifecycle_scripts.py Resolved
Comment thread tests/utils/lockfile_write_counter.py Resolved
after_lockfile_commit runs state bound to the committed lockfile once the
writer scope's staged lockfile is on disk; install binds deployment receipt
claims through it, so a lockfile write that fails leaves the receipt
unbound. The lockfile-write-authority rule requires every claim binding to
follow the commit.

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-swe-agent[bot] <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by #4255, which carries all of this change plus the follow-up fixes.

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