Skip to content

fix(install): reconcile MCP/LSP before native Claude registration commits the lockfile (#4329) - #4579

Merged
Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
danielmeppiel-fix-4329-single-lock-write
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
danielmeppiel-fix-4329-single-lock-write

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm install with a native Claude plugin and MCP or LSP servers wrote apm.lock.yaml twice: native registration flushed the staged lockfile (claude_plugins phase), then MCP/LSP reconciliation ran after the pipeline and the INSTALL writer scope committed a second time at exit.

MCP/LSP reconciliation now runs inside the install pipeline as a services phase, after the deploy gates and copilot_plugins/codex_plugins, and before claude_plugins. Claude's lockfile flush is then the install's single commit, and the lock equals disk at that commit.

  • install/phases/services.py (new, owned by lockfile-write-authority): calls the caller's reconciliation hook with the pre-commit InstallResult. An install that finalize will fail reconciles nothing, as before. A reconcile failure is kept on the context: native registration still runs when the lockfile authority commits on that failure (an MCP collision after other servers were written), so the committed native records are on disk. A refusal (org policy) registers nothing and the staged lock is discarded. The caller then raises the original error, at the point where it was raised before.
  • deps/lockfile_write_authority.py: commits_on_failure(error) exposes the owner's existing _commits decision. There is no second authority, and no new commit or flush site (contracts-tooling-lockfile-write-authority is unchanged and green).
  • install/service_integration.py: ServiceReconciliation wraps run_service_integrations and the PolicyBlock/RequiredIntegration rendering the command did before. The command reads call-time options from the pipeline result. If no pipeline ran the hook (--only mcp, no APM deps, no-work installs), the command runs it afterwards, as before.
  • --frozen passes no hook (it writes no lockfile), so its service order is unchanged. apm update and apm lock pass no hook and are unchanged.
  • Guard: install-deployment-install-commit-order now also requires _run_phase("services") before _run_phase("claude_plugins"), plus a mutation case (commit-order-native-commit-before-services).
  • commands/install.py: 2082 -> 2081 lines. pipeline.py stays within its LOC budget. The complexity ratchet is clean and the baseline did not grow.

Issue and approved scope

Issue: Fixes #4329. Refs #4565 (epic).

Human scope-approval comment: #4329 (comment)

Completes the issue. Out of scope and unchanged: what MCP/LSP records in the lock. Sequencing note: #4559 rewrites the same native registration path. This PR rebases onto it once it lands.

Type of change

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

Testing

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

Evidence (lifecycle-tests skill):

promise: P-INV-I1 / P-LAW-idempotency.byte_stable -- an install writes apm.lock.yaml once and the lock matches disk at that commit (source: #4329 scope)
cell: OP=install SRC=git PRIM=native-plugin+mcp+lsp SCOPE=user TGT=claude   owner: lockfile-write-authority (deps/lockfile_write_authority.py)
instrument: today test -> tests/integration/test_claude_native_hook_lifecycle.py::test_native_claude_install_with_mcp_and_lsp_writes_the_lockfile_once (extends: flips the strict xfail cell to required and adds LSP)
oracles: [I1, I2, I3-audit] decisive: counter.writes == 1; lock mcp/lsp/native rows on disk; audit --ci exit 0; repeat install writes 0
failing-before: the strict xfail cell was XFAIL on Linux CI (2 writes); unit oracle with the old order -> "assert len(writes) == 1" failed (3 of 4 tests)
passing-after: unit tests 4 passed on macOS; the integration cell needs Linux inotify (explicit skip reason) and passes locally with an inode-based stand-in counter; the CI Linux lane is the witness
guard+mutation: install-deployment-install-commit-order + commit-order-native-commit-before-services     ledger: 4329
hints executed: none printed

Commands run locally (macOS):

  • pytest tests/unit/install/test_services_before_native_registration.py -> 4 passed
  • pytest tests/unit/install tests/unit/commands tests/unit/test_install_* -> 4479 passed (installer-script shell tests deselected: they time out on this shared host and do not touch this change)
  • pytest tests/integration/test_claude_native_hook_lifecycle.py test_lockfile_commit_point_lifecycle.py test_lockfile_write_authority_lifecycle.py test_opencode_lsp_lifecycle.py test_policy_announced_once_lifecycle.py test_gitlab_subgroup_policy_lifecycle.py (real binary) -> 37 passed, 22 skipped (inotify/platform), 3 xfailed (other issues)
  • pytest tests/integration/test_architecture_owner_rule_mutations.py tests/integration/test_architecture_lockfile_write_authority.py tests/unit/scripts/test_architecture_runner.py -> passed
  • pytest tests/quality/test_lifecycle_bug_ledger.py -> 2 passed
  • Lint contract: ruff 0.15.12 check/format, pylint R0801, lint-auth-signals, complexity ratchet, taxonomy --changed, lint-architecture-boundaries -> all clean

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .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.

…mits the lockfile (#4329)

MCP and LSP reconciliation now runs inside the install pipeline as a
services phase ahead of claude_plugins, so native registration's lockfile
flush is the install's single commit and the lock matches disk there.
A reconcile failure the lockfile authority still commits registers native
plugins first; a refusal registers nothing.

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

Route the call-time service options through the install command so the
target-selection and frozen guards keep their seams; own the services
phase under the lockfile write authority; extend the install commit-order
guard (services before claude_plugins) with a mutation case.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 09:41
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

A critical rollback gap leaves reconciled MCP/LSP service configurations on disk without matching ownership records when native Claude registration fails.

1 open issue
What changed in this PR

This PR addresses #4329 by moving MCP/LSP reconciliation into the install pipeline before native Claude registration, so its lockfile commit includes service ownership records.

Changes:

  • Adds a services phase with deferred failure handling and command-level fallback.
  • Reuses the lockfile authority’s failure decision to control native registration.
  • Strengthens ordering guards and regression coverage for single-write installs.
File Description
tests/​unit/​install/​test_services_before_native_registration.py Tests ordering, commit counts, and failure handling.
tests/​integration/​test_claude_native_hook_lifecycle.py Requires the single-write regression and adds LSP assertions.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds a services-ordering mutation case.
tests/​fixtures/​lifecycle_bug_ledger.json Records #4329 and its regression coverage.
src/​apm_cli/​install/​service.py Passes reconciliation into the pipeline.
src/​apm_cli/​install/​service_integration.py Wraps reconciliation results and deferred failures.
src/​apm_cli/​install/​request.py Adds the reconciliation callback option.
src/​apm_cli/​install/​pipeline.py Runs services before Claude registration.
src/​apm_cli/​install/​phases/​services.py Implements reconciliation and registration eligibility.
src/​apm_cli/​install/​phases/​finalize.py Exposes the kept-overwrite failure check.
src/​apm_cli/​install/​context.py Holds the callback and deferred service failure.
src/​apm_cli/​deps/​lockfile_write_authority.py Exposes the existing commit-on-failure decision.
src/​apm_cli/​commands/​install.py Supplies service options and settles reconciliation.
scripts/​architecture_linter/​checks/​install_entry_and_commit.py Enforces service ordering before registration and scripts.
CHANGELOG.md Documents the single-write fix.
.apm/​architecture/​owners/​contracts-tooling.json Registers the services phase under lockfile authority.

Review effort: Balanced

Comment thread src/apm_cli/install/pipeline.py Resolved
…4329)

The phase tests now read the lockfile on disk when native registration
declares and at the end, instead of patching the atomic writer.

apm-spec-waiver: internal phase ordering; lock content and OpenAPM-observable behaviour unchanged, only the write count drops to one

Co-authored-by: Copilot App <[email protected]>
… rolls back (#4329)

Services now reconcile before native Claude registration, so a failed
declaration that restores the previous lock (req-na-004) keeps the MCP and
LSP records for what reconciliation already wrote, on a first install and
over an existing lock.

apm-spec-waiver: req-na-004 rollback unit unchanged; only the service records that reached disk are kept

Co-authored-by: Copilot App <[email protected]>
…le owner (main red)

#4037 added deps/lockfile_lookup.py to the read-only-lockfile-path owner;
the pack lockfile read test still pinned one selector, so Integration Tests
failed on main and on every PR merge group.

Co-authored-by: Copilot App <[email protected]>
…l-fix-4329-single-lock-write

# Conflicts:
#	tests/integration/test_architecture_pack_lockfile_read.py
@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
…sed-wip

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
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.

install: reconcile MCP/LSP before native plugin registration commits the lockfile

2 participants