Skip to content

fix(install): a refused native registration restores the previous lockfile byte for byte - #4689

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-fix-refused-native-rollback-lock
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-fix-refused-native-rollback-lock

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

When native plugin declaration fails (for example, apm install -g --trust-bin refuses because a user's own file sits at a Claude plugin's bin/ path), claude_plugins.run rolls apm.lock.yaml back to the previous lock. The rollback also carries the MCP/LSP records that reconciliation wrote (#4329). It always re-recorded the MCP target servers, which marks the field present, so an unchanged lock gained mcp_target_servers: {}. The refused install therefore changed the lockfile (I7: a failed command preserves state).

The fix is in _with_reconciled_services (install/phases/claude_plugins.py). When the committed MCP/LSP records equal the previous lock's, the previous lock is returned untouched, so the rollback restores it byte for byte. When reconciliation did change records, they are still carried as before.

Issue and approved scope

Issue: Fixes #4685

Human scope-approval comment: #4685 was filed and routed by the Q&L lead as the regression owner's fix (a regression from #4579 / #4329). Its scope is the rollback owner only.

Does this PR complete the issue, or what remains? It completes it. The lifecycle scenario cell that found it (test_ownership_siblings.py::test_a_users_file_at_the_plugin_bin_path_refuses_the_plugin, strict known cell #4685) is on the corpus train branch, not on main. That train retires the known cell once this lands. I checked locally that the cell passes with this fix applied.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
promise: P-INV-I7 -- a failed command preserves state (source: tests/lifecycle/oracles.py ORACLE_LAWS I7)
cell: OP=install SCOPE=user PRIM=bin DEPLOYED=unowned (refused native registration)   owner: src/apm_cli/install/phases/claude_plugins.py
instrument: today test -> tests/unit/install/test_services_before_native_registration.py::test_a_refused_declaration_with_unchanged_services_restores_the_lock_byte_for_byte (extends the #4329 phase module)
oracles: rolled-back apm.lock.yaml == the previous lock as written; no mcp_target_servers key
failing-before: source change reverted -> AssertionError: 'mcp_target_servers' is contained in the rolled-back lock
passing-after: module -> 7 passed
guard+mutation: n/a   ledger: #4685
hints executed: none printed

Commands run (local, through the host guard):

  • pytest tests/unit/install/test_services_before_native_registration.py: 7 passed. With the source change reverted, the new case fails.
  • Real CLI, with the fix applied on the corpus branch: pytest tests/lifecycle/scenarios/test_ownership_siblings.py -k plugin_bin: 3 passed.
  • Lint contract (ruff check and format, pylint R0801, auth signals, complexity ratchet, taxonomy, assertion ratchet): clean.

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.

…kfile byte for byte

When native plugin declaration fails (for example a user's own file at
a Claude plugin bin path), claude_plugins.run rolls apm.lock.yaml back
to the previous lock carrying the MCP/LSP records reconciliation wrote.
The rollback always re-recorded the MCP target servers, so an unchanged
lock gained an empty mcp_target_servers field and the refused install
changed the lockfile. The rollback now returns the previous lock
untouched when no MCP/LSP record changed.

Fixes #4685

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 20:41
Refs #4685

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@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

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

Rollback logic conflates type-distinct MCP values and fails to restore the original lockfile bytes, risking stale baselines and altered timestamps or lost comments.

2 open issues
What changed in this PR

This PR addresses #4685 in APM's native Claude plugin rollback path, avoiding an added empty mcp_target_servers field when registration fails and service records are unchanged.

Changes:

  • Return the previous lock unchanged when MCP/LSP records compare equal.
  • Add regression coverage and a lifecycle bug-ledger entry.
  • Document the user-visible fix in a changelog fragment.
File Description
tests/​unit/​install/​test_services_before_native_registration.py Adds unchanged-service rollback regression coverage.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4685.json Records the bug and links its regression test.
src/​apm_cli/​install/​phases/​claude_plugins.py Adds service-record comparison and an unchanged-record fast path.
changelog.d/​4689.fixed.md Describes the refused-registration lockfile fix.

Review effort: Balanced

…istration

Review: returning the previous LockFile still reserialized it, refreshing
a legacy generated_at and dropping comments. The phase now captures the
on-disk lock before its commit and restores those bytes through
restore_lockfile_bytes when no MCP/LSP record changed; service records
compare type-sensitively (_json_identity), so 1 and true differ.

Refs #4685

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs #4685

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The change restores the previous lockfile bytes when native plugin
declaration fails; it adds no OpenAPM-observable behaviour.

apm-spec-waiver: rollback restores pre-install lockfile bytes; no OpenAPM-observable behaviour change

Refs #4685

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 85eebbd into main Nov 22, 2026
62 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-refused-native-rollback-lock branch November 22, 2026 08:25
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
… are fixed

#4689 fixed #4685 and b0d62e2 fixed #4697 on main, so both pair cells
(bin and lsp, DEPLOYED=unowned) are required: drop the strict known
expectations, the scenario's known map entries, and the known-failing
status in lifecycle_obligations.json.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

[BUG] A refused apm install -g still rewrites ~/.apm/apm.lock.yaml (adds mcp_target_servers: {})

2 participants