fix(compile): target-aware instruction dedup for Codex AGENTS.md (closes #1678)#1685
Merged
danielmeppiel merged 2 commits intoJun 8, 2026
Conversation
The instruction deduplication introduced in 0.17.0 unconditionally suppressed instruction content from AGENTS.md whenever .github/instructions/ existed. This was wrong for Codex, OpenCode, Windsurf, and other targets that do NOT read .github/instructions/ -- they rely solely on AGENTS.md for instruction content. Root cause (two facets): 1. _compile_distributed() checked .github/instructions/ without considering which target was being compiled. 2. Unlike the Claude path, the AGENTS.md path did not respect the --no-dedup / --force-instructions flag. Additionally, _resolve_compile_target() collapsed mixed target lists like [copilot, codex] into bare 'vscode', erasing the info that Codex was in the target set. Changes: - target_detection.py: add can_dedup_agents_md_instructions() helper that returns True only when EVERY AGENTS.md consumer also reads .github/instructions/ (currently only vscode/copilot). - agents_compiler.py: _compile_distributed() now checks no_dedup first, then uses the target-aware helper before applying dedup. - compile/cli.py: _resolve_compile_target() preserves the frozenset when non-Copilot agents-family targets (codex, opencode, windsurf) are in the original target list. - Tests: 18 new tests covering the helper, target resolution regression, and AGENTS.md dedup scenarios. Closes #1678 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in apm compile where instruction deduplication incorrectly removed instruction content from AGENTS.md for non-Copilot targets (Codex/OpenCode/Windsurf, etc.) whenever .github/instructions/ existed, by making dedup target-aware and ensuring --no-dedup is honored on the AGENTS.md path.
Changes:
- Added
can_dedup_agents_md_instructions()to gate AGENTS.md instruction deduplication based on the effective target. - Updated distributed AGENTS.md compilation to (1) respect
--no-dedupand (2) only dedup when safe for the configured target(s). - Adjusted
_resolve_compile_target()to preserve multi-target frozensets when non-Copilot agents-family targets are present, and expanded/updated unit tests for the regression.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/apm_cli/core/target_detection.py |
Adds target-aware helper for whether AGENTS.md can safely omit instruction bodies. |
src/apm_cli/compilation/agents_compiler.py |
Uses the helper + no_dedup to decide whether to skip instructions in AGENTS.md when .github/instructions/ exists. |
src/apm_cli/commands/compile/cli.py |
Preserves mixed-target information (frozenset) so downstream compile logic can make correct dedup decisions. |
tests/unit/core/test_target_detection.py |
Adds coverage for the new helper and target-resolution regression cases. |
tests/unit/compilation/test_compile_no_dedup_flag.py |
Adds regression tests covering AGENTS.md dedup behavior across targets and --no-dedup. |
tests/unit/compilation/test_compile_target_flag.py |
Updates expected target-resolution behavior for windsurf+copilot mixed targets. |
- Update compile.md: Copilot dedup is now target-aware with --no-dedup opt-out - Clarify conservative-policy comment in can_dedup_agents_md_instructions() - Replace if-exists guards with assert-exists in non-dry-run tests - Strengthen dry-run dedup test with content assertion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Make AGENTS.md instruction deduplication target-aware so Codex, OpenCode, Windsurf, and other non-Copilot targets always receive instruction content in AGENTS.md, even when
.github/instructions/exists.Problem (WHY)
The instruction deduplication introduced in 0.17.0 unconditionally suppressed instruction content from AGENTS.md whenever
.github/instructions/contained.mdfiles. This was correct for Copilot (which reads both AGENTS.md and.github/instructions/), but wrong for every other target that consumes AGENTS.md -- Codex, OpenCode, Windsurf -- which rely solely on AGENTS.md for instruction content.The bug had three facets:
_compile_distributed()checked.github/instructions/without considering which target was being compiled.--no-deduprespect: Unlike the Claude path, the AGENTS.md path did not honour the--no-dedup/--force-instructionsflag._resolve_compile_target()collapsed mixed target lists like[copilot, codex]into bare"vscode", erasing the information that Codex was in the target set.Approach (WHAT)
can_dedup_agents_md_instructions(target)helper totarget_detection.pythat returnsTrueonly when every AGENTS.md consumer also reads.github/instructions/(currently only the"vscode"target)._compile_distributed()to checkconfig.no_dedupfirst (matching the Claude path pattern), then use the target-aware helper before applying dedup._resolve_compile_target()to preserve the frozenset when non-Copilot agents-family targets (codex, opencode, windsurf) are in the original target list.Implementation (HOW)
src/apm_cli/core/target_detection.pycan_dedup_agents_md_instructions()-- returnsTrueonly for"vscode"andfrozenset({"vscode"})src/apm_cli/compilation/agents_compiler.py_compile_distributed()now checksno_dedupfirst, thencan_dedup_agents_md_instructions(config.target)before detecting deployed instructionssrc/apm_cli/commands/compile/cli.py_resolve_compile_target()only collapses{"vscode","agents"}to"vscode"when there are no non-Copilot agents-family targets in the original listtests/unit/core/test_target_detection.pycan_dedup_agents_md_instructions+ 6 target resolution regression teststests/unit/compilation/test_compile_no_dedup_flag.pytests/unit/compilation/test_compile_target_flag.py[windsurf, copilot]Trade-offs
target="vscode"(solo Copilot), dedup still fires as before -- no regression for existing Copilot-only users.can_dedup_agents_md_instructionsreturnsFalsefor"all","minimal", and any frozenset containing"agents". This errs on the side of including instructions rather than risking silent suppression.Validation evidence
[copilot, codex]preserves frozenset and that codex/all/multi-target scenarios include instructions in AGENTS.mdHow to test
Closes #1678