Repository navigation
fix: avoid duplicate Copilot global instructions - #3113
Daniel Meppiel (danielmeppiel) merged 10 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The cleanup contract breaks existing tests, omits dry-run deletion previews, and leaves documentation inconsistencies.
Review effort: Balanced
Findings: 2
Open (4)
What changed in this PR
Adds Copilot root-instruction deduplication while protecting user-modified files.
Changes:
- Omits global instructions already deployed as native Copilot rules.
- Adds guarded cleanup and regression coverage.
- Updates CLI help and documentation.
| File | Description |
|---|---|
src/apm_cli/compilation/agents_compiler.py |
Implements deduplication and protected cleanup. |
src/apm_cli/commands/compile/cli.py |
Expands flag help text. |
tests/unit/compilation/test_compile_target_flag.py |
Adds compiler regression tests. |
tests/integration/test_install_compile_copilot_dedup_e2e.py |
Tests install-to-compile behavior. |
docs/src/content/docs/reference/cli/compile.md |
Updates flag reference. |
docs/src/content/docs/producer/compile.md |
Documents Copilot deduplication. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…uctions.md The _cleanup_copilot_root_instructions guard was treating any file whose Build ID did not validate (including legacy files that pre-date the Build ID feature and have no <!-- Build ID: ... --> line at all) as user-edited and retaining them with a warning. That prevented the stale-file removal path from cleaning up pre-existing APM-generated copilot-instructions.md files when their content had been redeployed to .github/instructions/, breaking the upgrade path. Introduce has_build_id_line() to distinguish three cases: * No Build ID line → legacy pre-Build-ID APM output → safe to remove. * Build ID present & matching → unmodified APM output → safe to remove. * Build ID present & mismatching → user-edited → preserve + warn. Refactor has_valid_build_id() to share _find_build_id / _expected_build_id helpers with the new predicate so there is no duplicated parsing logic.
Bug found: legacy pre-Build-ID copilot-instructions.md not cleaned upThe new Build ID guard in ReproductionTwo pre-existing unit tests fail on this branch:
Both write a marker-only file ( FixIntroduce a new predicate if has_build_id_line(existing) and not has_valid_build_id(existing):
# warn and preserve (user-edited)This correctly distinguishes three cases:
Files changed
All 1417 compilation unit tests pass; (Note: I was unable to push a branch to this repo due to OAuth App access restrictions, so I'm filing the fix details here.) |
|
Fix for #3099 is ready: the cleanup logic now correctly distinguishes between:
Pushed the fix to dajiaohuang/apm:fix/3099-copilot-instruction-dedup branch. |
APM Review Panel:
|
| PR | Head | CEO | Iterations | Folds | Deferrals | Copilot rounds | CI | Mergeable | Merge state | Notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3113 | f765607 | ship_now | 2 | 10 | 0 | 2 | green | MERGEABLE | BLOCKED | Platform admission pending |
Strict compatibility with current main 6333b56a3c2e11e20d87f6f55070c4a06669d06d is clean; it is also the executed local test base. Repository merge admission is not granted by this advisory.
The recommendation is advisory. Technical readiness is separate from repository admission: this worker did not merge, enqueue, approve reviews, change protection, or request reviewers. Existing reviewer ownership is unchanged.
Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.
Merge current main without rewriting contributor history. Address the recovered panel findings for microsoft#3113: restore the approved marker-and-hash cleanup boundary, enforce containment, strengthen regression tests and ownership guards, and clarify docs. Keep main user-scope Build ID verification and its canonical owner. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
The Copilot dedup fix crossed the current 2100-line source guardrail. Move its existing native-rule filename and containment helpers into the existing root-context protection owner, preserving aliases and behavior rather than waiving the limit or adding another authority. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
Address delta coverage follow-up with live and dry-run command-level linked-parent refusal. Both cases fail without containment and pass with the restored guard. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
Preserve current local target provenance and shared claims alongside the bounded Copilot cleanup fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
CI exposed the missing frozen-inventory expectation for the new canonical Build ID guard. Include it without relaxing the exact registry contract. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
4c083f3
into
microsoft:main
…3251) Restore the release-gate integration suite (nightly + tag) to green: - runtime: route runtime setup/version/uninstall children through external_process_env so a frozen binary's bundled LD_LIBRARY_PATH / DYLD_* never leak into the setup script's python3 (ensurepip failed under the PyInstaller binary). - tests: align fixtures with contracts merged since v0.33.0 -- grok-bot skills_rel_root/supports on MagicMock targets (#3106), Cursor native flat hooks (#3149), frozen installs that never rewrite the lockfile (#2384), manifestless SKILL.md probe (#3064), unknown apm.yml key warning (#3222), resolved Claude config path (#3148), and the build-ID owner guard mutation case (#3113). - flakes: skip transient git maintenance files when snapshotting a bare fixture repo; widen multiprocess lock-test timeouts for slow runners. Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 761bf207-57da-41d0-bd3f-ffecbb97b83a


Description
For the Copilot target, compilation now omits each global instruction from
.github/copilot-instructions.mdwhen its matching target-native rule file is deployed under.github/instructions/. Unmatched global instructions remain in the root file.When all global instructions are deduplicated, compilation removes an existing root output only when the APM generated marker is in its header and its Build ID matches the content. Hand-authored, edited, and symbolic-link files are retained.
--force-instructionsand--no-dedupkeep the intentional duplicate path.Issue and approved scope
Issue: #3099
Human scope-approval comment: #3099 (comment)
This PR completes the approved issue. It preserves the requested flags, protects hand-authored root files, adds default and forced regression coverage, and updates compile documentation.
Fixes #3099
Type of change
Testing
Focused checks: 144 passed; integration checks: 3 passed; Ruff check and format passed; link-check tests: 14 passed. The generated docs build could not run locally because Astro is unavailable.
Spec conformance (OpenAPM v0.1)