Skip to content

[0.38] fix(install): a failed MCP or LSP write restores the deploys and the lockfile (#4594) - #4681

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-p2-4594-mcp-write-restore
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-p2-4594-mcp-write-restore

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Builds on #4612 (#4282, merged): its deploy journal.

apm install writes MCP and LSP configuration after the pipeline stages apm.lock.yaml. When that write failed (for example .mcp.json is a directory), install exited 1 but kept the failed attempt's hooks and lockfile on disk. That is the mcp-config-write row of tests/lifecycle/scenarios/test_failure_phase.py.

The lockfile-write row of the same scenario is flipped by #4612.

Issue and approved scope

Issue: Fixes #4594

Human scope-approval comment: #4594 (comment)

Does this PR complete the issue, or what remains? It completes the approved scope.

Type of change

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

Testing

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

Done when: the strict known cell _LOCK_CHANGED (row mcp-config-write) is removed and the row passes on the real binary; it still exits 1 with "MCP configuration failed for selected runtime(s): p-exec-mcp". The other rows of the scenario stay green.

Command Result
pytest "tests/lifecycle/scenarios/test_failure_phase.py::test_failed_install_preserves_state_and_recovers[mcp-config-write]" with src/ from #4612 failed (I7: lockfile and .github/hooks/ changed): red before
pytest tests/lifecycle/scenarios/test_failure_phase.py tests/integration/test_lockfile_commit_point_lifecycle.py tests/integration/test_intellij_mcp_config_lifecycle.py tests/integration/test_mcp_integrator_characterisation.py (installed CLI) 68 passed, 1 skipped, 1 xfailed
pytest tests/integration/test_architecture_owner_rule_mutations.py tests/unit/install plus MCP integration files (after merging main) 4922 passed; 4 failures only in the load-sensitive shell installer tests test_unix_install_ownership.py, unrelated
pytest tests/unit/install/test_services_before_native_registration.py 7 passed
python scripts/lint_architecture_boundaries.py --root ., ruff 0.15.12 check/format, pylint R0801, lint-auth-signals.sh, complexity ratchet, taxonomy 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: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…lockfile (#4594)

The install transaction still holds its deploy journal while service
integrations run inside the lockfile writer scope; a failure there now rolls
back before the scope commits. MCP collisions keep the writes that reached
disk (#4268).

Co-authored-by: Copilot App <[email protected]>
#4594)

Keeps _install_apm_packages within the complexity limit; the commit-order
guard now requires the restoring call, with a mutation cell; bug-ledger row
and docs.

Co-authored-by: Copilot App <[email protected]>
Base automatically changed from danielmeppiel-p2-4282-lazy-snapshot to main November 21, 2026 20:40
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 21, 2026
Main now reconciles MCP and LSP inside the pipeline while the lockfile is
still staged (#4329), so the deploy journal is still live there: a failed
reconciliation rolls the install transaction back, except an MCP collision,
and native registration then registers nothing. The earlier hold of the
journal past the lockfile commit is no longer needed.

apm-spec-waiver: restores pre-command bytes under the existing req-pl-002 failing-check contract; no new OpenAPM-observable surface.

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

Service-failure rollback leaves successful MCP writes and native plugin registrations outside the transaction, risking unowned server entries and registrations inconsistent with restored packages and lockfiles.

4 open issues
What changed in this PR

This PR extends the install deploy journal from #4612 to roll back failed MCP/LSP reconciliation before the staged lockfile commits, addressing #4594.

Changes:

  • Rolls back the install transaction on service failures while preserving MCP collision behavior.
  • Adds rollback coverage and removes the MCP-write scenario’s known-failure allowance.
  • Updates the ownership record, bug ledger, CLI documentation, and changelog.
File Description
tests/​unit/​install/​test_services_before_native_registration.py Tests rollback and native-registration suppression; uses the typed MCP collision.
tests/​lifecycle/​scenarios/​test_failure_phase.py Requires MCP-write failures to preserve pre-command state.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4594.json Records the fix and linked lifecycle regression.
src/​apm_cli/​install/​phases/​services.py Adds transaction rollback and narrows native-registration eligibility.
docs/​src/​content/​docs/​reference/​cli/​install.md Documents service-write rollback and the MCP collision exception.
CHANGELOG.md Announces the install rollback behavior.
.apm/​architecture/​owners/​install-deployment.json Records service-failure rollback under the install transaction owner.

Review effort: Balanced

Comment thread CHANGELOG.md Resolved
Comment thread src/apm_cli/install/phases/services.py Resolved
Comment thread src/apm_cli/install/phases/services.py Resolved
Comment thread src/apm_cli/install/phases/services.py Resolved
…stration (#4594)

- MCP adapter config writes (base, Claude, Codex, Hermes, IntelliJ) are
  journaled at the deploy write seam, so a later service failure restores
  them too.
- MCP/LSP reconciliation runs before Copilot, Codex and Claude native
  registration, and a rolled-back reconciliation registers none of them.
- An LSP user-entry collision keeps its writes like an MCP collision.
- Unit cells assert the durable lockfile state and the restored MCP config.
- The changelog line moves to changelog.d/4681.fixed.md.

apm-spec-waiver: restores pre-command bytes under the existing req-pl-002 failing-check contract; no new OpenAPM-observable surface.

Co-authored-by: Copilot App <[email protected]>
…lockfile (#4594)

The #4086 single-write cell pinned the old record-what-reached-disk
contract for this failure; it now asserts the restored state and zero
lockfile writes.

apm-spec-waiver: restores pre-command bytes under the existing req-pl-002 failing-check contract; no new OpenAPM-observable surface.

Co-authored-by: Copilot App <[email protected]>
…-write-restore

# Conflicts:
#	.apm/architecture/owners/install-deployment.json
#	docs/src/content/docs/reference/cli/install.md
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 57bf799 into main Nov 22, 2026
70 of 72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-4594-mcp-write-restore branch November 22, 2026 09:21
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…; main flipped its cell)

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A failed install still keeps the deployed files of the failed attempt (lockfile or MCP config write)

2 participants