Skip to content

fix(install): lockless MCP evidence follow-ups (#4801) - #4818

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-4801-lockless-mcp-followups
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-4801-lockless-mcp-followups

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Follow-ups to #4760 (lockless MCP write evidence) covering the four open cases in #4801:

  1. Kept entries stay reported after the lockfile is rewritten. If an install without apm.lock.yaml finds unusable evidence (an edited entry or a missing record), it writes a <key>.json.unusable note next to the evidence file. apm audit --ci (kept-mcp-entries) reads that note, so the report survives a regenerated lockfile until the file is removed.
  2. Each COPILOT_HOME profile keeps its own evidence. Records are keyed by (runtime, config file, native key). Retirement and audit only look at records for the selected config file, so one profile never changes another.
  3. Local bundle MCP writes are recorded. local_bundle_handler / mcp/integration now record the MCP entries a local bundle writes, so an install without a lockfile can retire them like any other entry.
  4. Kept entries are announced on every install. With a lockfile, retire_undeclared_mcp_writes still runs in announce-only mode and prints "Kept MCP server ..." until the entry is removed or declared again.

Docs: reference/cli/install.md, reference/baseline-checks.md, apm-guide governance.md.

Issue and approved scope

Issue: Fixes #4801

Human scope-approval comment: #4801 (comment)

This PR completes the issue.

Type of change

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

Testing

  • Tested locally (targeted, per host rule; CI runs the full suites)
  • All existing tests pass (CI)
  • Added tests for new functionality (if applicable)

These lifecycle cells in tests/lifecycle/scenarios/test_mcp_write_receipts.py fail on base 32c476d (the #4760 head) and pass at this head:

Cell Base 32c476d This PR
test_a_kept_entry_stays_reported_after_the_lockfile_is_rewritten[unusable-evidence] FAIL PASS
test_a_kept_entry_stays_reported_after_the_lockfile_is_rewritten[edited] FAIL PASS
test_each_copilot_home_profile_keeps_its_own_evidence FAIL PASS
test_a_local_bundle_mcp_entry_is_retired_without_the_lockfile FAIL PASS

There are also unit tests in tests/unit/install/test_mcp_write_receipts.py, covering per-config keying and the unusable note. At user scope, the lifecycle driver rejects audit --ci, so a unit test covers the audit path for the profile case. Bug-ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4801.json. Lifecycle obligations regenerated: pair|SCOPE=user|MCPOWN=copilot is now required.

Lint mirror ran clean: ruff 0.15.12 check and format, pylint R0801, lint-auth-signals.sh, architecture boundaries, complexity ratchet, tests.quality.taxonomy --changed, check_test_assertions.py, and tests.lifecycle.generator --check.

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.

… entries on every install

MCP write evidence is now keyed by (runtime, config file, native key), so
each COPILOT_HOME profile keeps its own record; retirement and audit only
examine records of the selected config. Local bundle installs record the
MCP entries they write. With a lockfile, install announces each entry it
kept earlier until it is removed or declared again. Unusable evidence met
by an install without apm.lock.yaml is noted next to the evidence file,
so apm audit --ci keeps reporting it after the lockfile is rewritten,
until that file is removed.

Lifecycle cells cover the four cases; bug-ledger row 4801.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 21:04

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

Receipt handling still produces incorrect or missing kept-entry warnings and stale audit failures, while the fallback sidecar writer can follow symlinked ancestors into an external directory.

4 open issues
What changed in this PR

This PR extends APM's lockless MCP cleanup to preserve evidence across runtime profiles, record local-bundle writes, and keep unresolved entries visible after lockfile regeneration.

Changes:

  • Keys write evidence by runtime, config file and native key, and journals local-bundle MCP writes.
  • Persists unusable-evidence notes and adds kept-entry announcements to later installs.
  • Adds regression coverage, updates lifecycle obligations, and documents the behavior.
File Description
tests/​unit/​install/​test_mcp_write_receipts.py Tests profile isolation, persistent evidence notes and repeated notices.
tests/​quality/​lifecycle_obligations.json Updates regression witnesses and requires user-scope profile coverage.
tests/​lifecycle/​scenarios/​test_mcp_write_receipts.py Adds lifecycle scenarios for lock regeneration, profiles and bundles.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4801.json Records the failure modes and regression tests.
src/​apm_cli/​policy/​ci_checks.py Reports noted unusable evidence after lockfile regeneration.
src/​apm_cli/​install/​mcp/​write_receipts.py Adds per-config identities, persistent notes and announce-only reporting.
src/​apm_cli/​install/​mcp/​integration.py Invokes receipt reporting when a lockfile governs cleanup.
src/​apm_cli/​install/​local_bundle_handler.py Journals local-bundle MCP writes.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Updates audit behavior and remediation guidance.
docs/​src/​content/​docs/​reference/​cli/​install.md Documents evidence isolation and persistent reporting.
docs/​src/​content/​docs/​reference/​baseline-checks.md Clarifies kept-entry audit conditions and remediation.
changelog.d/​4818.fixed.md Summarizes the user-visible fixes.

Review effort: Balanced

…4818)

apm-spec-waiver: MCP write evidence notes, per-config keying and kept-entry reporting are local client state; no manifest, lockfile or resolver contract changes

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

The unusable-evidence fallback can write outside the metadata root through symlinked ancestors, and warning and kept-entry announcement gaps remain across install paths.

6 open issues

Review effort: Balanced

Comment thread src/apm_cli/install/mcp/integration.py Resolved

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.

🔵 Needs a closer look

A critical receipt-sidecar write can escape the trusted tree through symlinked ancestors, and targeted and local-bundle installs omit required kept-server notices.

6 open issues

Review effort: Balanced

… directory

The note next to unusable MCP write evidence is written only when no
component between the evidence owner's anchor (above APM_HOME) and the note
is a link, matching the check that refused the evidence itself.

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.

🟢 Approval recommended

No active review issues remain for the changes to profile-specific MCP cleanup evidence and persistent audit notices.

No open issues 🎉

6 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit db285a7 into main Nov 23, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4801-lockless-mcp-followups branch November 23, 2026 01:11
Antonin Rouxel (Antonin-Rouxel-LaPoste-BGPN) pushed a commit to anrouxel/apm that referenced this pull request Nov 23, 2026
The microsoft#4802 revert (microsoft#4855) and microsoft#4818 landed together and took the file to
2101 lines. The restored _encode call takes one formatted line, as it
did before the revert; no behavior change.

Co-authored-by: Copilot App <[email protected]>
Antonin Rouxel (Antonin-Rouxel-LaPoste-BGPN) pushed a commit to anrouxel/apm that referenced this pull request Nov 23, 2026
…ept reporting

Reporting accuracy for kept entries from lockless MCP write evidence
(microsoft#4861, deferred from microsoft#4818). Nothing is removed differently:
- apm install <bundle>, apm install --mcp NAME and apm mcp install NAME
  announce kept entries (announce-only) against the lockfile's complete
  managed-server set, through one helper, announce_kept_mcp_writes;
- a located rewrite supersedes the key-less record of the same runtime,
  config and name, so a retired entry leaves no stale notice or audit
  finding;
- announce-only skips a server redeclared on the same native key, as
  retirement already does;
- every recognized unusable-evidence reason (OSError, path traversal)
  is announced on a lockless install, not only a parse error.
Six red-first cells.

Fixes microsoft#4861

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] Lockless MCP retirement follow-ups: evidence after lock regeneration, kept-entry notices, profiles, local bundles

2 participants