Skip to content

fix(audit): fail audit --ci on a differing unrecorded native MCP entry - #4493

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-h-4477-audit-mcp-conflict
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-h-4477-audit-mcp-conflict

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

apm audit --ci now runs a native-mcp-ownership baseline check. It fails when a runtime MCP config holds an entry, not recorded in the lockfile, that differs from a declared server with the same name. The check calls the same ownership helper as apm install --frozen (differing_unrecorded_native_mcp_entries in install/mcp/ownership.py), so both commands give the same verdict. An identical unowned entry still passes.

Stacked on #4470 (head 719c757); the first commits in this diff belong to #4470.

Issue and approved scope

Issue: Fixes #4477

Human scope-approval comment: assigned in the 0.37 final release train by the maintainer-run PM.

Does this PR complete the issue, or what remains? Completes it.

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:

  • tests/integration/test_native_mcp_collision_lifecycle.py::test_user_disabled_matching_codex_connection_installs_and_replays_frozen: fails 2/2 without the src change (audit exits 0) and passes 2/2 with it. It asserts exit 1, the server and target are named, and the file bytes are unchanged.
  • Neighbour run (collision lifecycle, tests/unit/policy/test_ci_checks.py, MCP portable-approval lifecycle, transitive MCP audit e2e): 196 passed.
  • The check inventory is updated: the test_ci_checks count goes from 11 to 12, and _GLOBAL_AUDIT_RULES is updated.
  • ruff check and ruff format --check (0.15.12) are clean on the changed files.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

…t on install or --frozen (#4449)

The Codex adapter compares connection identity: the user's enabled switch and
empty args or env are not part of it. The --frozen services gate needs no
recorded ownership for a self-defined server whose native entry already equals
the declaration, since nothing is written and the entry stays the user's.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…te-stable across install, --frozen and audit (#4449)

An identical foreign self-defined entry needs no write, so install and --frozen
both pass without claiming it; a differing entry is refused by both. Docs and
the apm-usage guide state the same rule.

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

apm audit --ci now runs a native-mcp-ownership baseline check that uses
the same ownership helper as install --frozen, so a user's MCP entry
that differs from a declared server of the same name fails both.

apm-spec-waiver: audit baseline check parity with install --frozen; no OpenAPM-observable requirement changes

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 19:44
@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

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

MCP ownership checks can falsely reject excluded runtime entries and matching plugin-derived configs, and abort audits on unreadable or malformed Codex state.

3 open issues
What changed in this PR

This PR adds a native MCP ownership check to apm audit --ci to align its verdict with frozen install for conflicting user-owned entries, addressing #4477. It also includes the matching-entry handling from stacked PR #4470.

Changes:

  • Add a baseline check that reports differing, unrecorded native MCP entries by server and target.
  • Allow matching user-owned entries during frozen replay, including Codex entries disabled by the user.
  • Extend lifecycle coverage, update check inventories, and document the behavior.
File Description
tests/​unit/​policy/​test_ci_checks.py Update the expected baseline-check count.
tests/​integration/​test_required_lifecycle_state_machine.py Register the new audit rule.
tests/​integration/​test_native_mcp_collision_lifecycle.py Cover matching entries, frozen replay, and audit conflicts.
tests/​integration/​test_codex_native_plugin_lifecycle.py Distinguish native-cache and replay drift diagnostics.
tests/​fixtures/​lifecycle_bug_ledger.json Record regression coverage for both fixes.
src/​apm_cli/​policy/​ci_checks.py Add and run the native MCP ownership check.
src/​apm_cli/​install/​service.py Accept matching unrecorded entries during frozen replay.
src/​apm_cli/​install/​mcp/​ownership.py Add declaration matching and unrecorded-conflict detection.
src/​apm_cli/​adapters/​client/​codex.py Ignore activation and normalize empty connection fields.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Document the new baseline check.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Explain matching user-owned entries during install.
docs/​src/​content/​docs/​reference/​cli/​install.md Clarify collision and frozen-replay behavior.
docs/​src/​content/​docs/​reference/​baseline-checks.md Describe the ownership check and remediation.
CHANGELOG.md Add user-facing entries for both fixes.

Review effort: Balanced

state = compare_native_mcp_connection(
client,
name,
requested_info=MCPIntegrator._build_self_defined_info(dependency),
Comment on lines +134 to +136
except (TypeError, ValueError):
logger.debug("Could not compare %s MCP entry %s", runtime, name, exc_info=True)
return False
Comment on lines +187 to +189
for runtime in sorted(clients):
recorded = ownership.get(runtime, set())
for name, stored in sorted((lockfile.mcp_configs or {}).items()):
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…3 checks)

#4065 pinned the exact ordered baseline; #4493 adds native-mcp-ownership after config-consistency. Interaction fix, no check dropped.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…migration

#4493 (main-based) adds a free-text remedy to policy/ci_checks.py; the train's
remediation-advice ratchet (#4090) counts it. Baselined (1 -> 2) so the
gate-9 remedy migration renders it from core/remediation.py with the rest.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 60b2b96 into main Nov 21, 2026
19 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-h-4477-audit-mcp-conflict branch November 21, 2026 05:24
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.

audit --ci passes a conflicting user Codex MCP entry that install --frozen refuses

2 participants