Skip to content

fix(compile): target-aware instruction dedup for Codex AGENTS.md (closes #1678)#1685

Merged
danielmeppiel merged 2 commits into
mainfrom
sergio-sisternes-epam/fix-issue-1678-target-aware-instruction
Jun 8, 2026
Merged

fix(compile): target-aware instruction dedup for Codex AGENTS.md (closes #1678)#1685
danielmeppiel merged 2 commits into
mainfrom
sergio-sisternes-epam/fix-issue-1678-target-aware-instruction

Conversation

@sergio-sisternes-epam
Copy link
Copy Markdown
Collaborator

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 .md files. 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:

  1. No target awareness: _compile_distributed() checked .github/instructions/ without considering which target was being compiled.
  2. No --no-dedup respect: Unlike the Claude path, the AGENTS.md path did not honour the --no-dedup / --force-instructions flag.
  3. Target resolution erasure: _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)

  • Add a can_dedup_agents_md_instructions(target) helper to target_detection.py that returns True only when every AGENTS.md consumer also reads .github/instructions/ (currently only the "vscode" target).
  • Update _compile_distributed() to check config.no_dedup first (matching the Claude path pattern), then use the target-aware helper before applying dedup.
  • Fix _resolve_compile_target() to preserve the frozenset when non-Copilot agents-family targets (codex, opencode, windsurf) are in the original target list.

Implementation (HOW)

File Change
src/apm_cli/core/target_detection.py Added can_dedup_agents_md_instructions() -- returns True only for "vscode" and frozenset({"vscode"})
src/apm_cli/compilation/agents_compiler.py _compile_distributed() now checks no_dedup first, then can_dedup_agents_md_instructions(config.target) before detecting deployed instructions
src/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 list
tests/unit/core/test_target_detection.py 15-case parametrised test for can_dedup_agents_md_instructions + 6 target resolution regression tests
tests/unit/compilation/test_compile_no_dedup_flag.py 5 AGENTS.md dedup scenario tests (codex, multi-target, copilot-only, no-dedup override, all)
tests/unit/compilation/test_compile_target_flag.py Updated existing test to reflect new frozenset preservation for [windsurf, copilot]

Trade-offs

  • Copilot-only dedup preserved: When target="vscode" (solo Copilot), dedup still fires as before -- no regression for existing Copilot-only users.
  • Conservative approach: can_dedup_agents_md_instructions returns False for "all", "minimal", and any frozenset containing "agents". This errs on the side of including instructions rather than risking silent suppression.

Validation evidence

  • Unit tests: 2091 passed (18 new), 0 failed
  • Lint chain: ruff check + format, pylint R0801, auth-signals -- all green
  • Regression coverage: Tests explicitly verify that [copilot, codex] preserves frozenset and that codex/all/multi-target scenarios include instructions in AGENTS.md

How to test

# Run the new and existing tests
uv run --extra dev pytest tests/unit/core/test_target_detection.py tests/unit/compilation/test_compile_no_dedup_flag.py tests/unit/compilation/test_compile_target_flag.py -x -q

# Manual verification: create a project with both targets
mkdir /tmp/test-1678 && cd /tmp/test-1678
mkdir -p .apm/instructions .github/instructions
echo -e "---\ndescription: Style\napplyTo: '**/*.py'\n---\n# Style\nUse type hints." > .apm/instructions/style.instructions.md
echo "# Style" > .github/instructions/style.md
echo "name: test\nversion: 1.0.0" > apm.yml

# Before fix: AGENTS.md would be empty of instructions
# After fix: AGENTS.md contains instruction content
apm compile --target codex
cat AGENTS.md  # should contain "Use type hints"

Closes #1678

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>
Copilot AI review requested due to automatic review settings June 6, 2026 22:56
@sergio-sisternes-epam sergio-sisternes-epam added the panel-review Trigger the apm-review-panel gh-aw workflow label Jun 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-dedup and (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.

Comment thread src/apm_cli/compilation/agents_compiler.py
Comment thread src/apm_cli/core/target_detection.py
Comment thread tests/unit/compilation/test_compile_no_dedup_flag.py Outdated
Comment thread tests/unit/compilation/test_compile_no_dedup_flag.py Outdated
Comment thread tests/unit/compilation/test_compile_no_dedup_flag.py Outdated
Comment thread tests/unit/compilation/test_compile_no_dedup_flag.py Outdated
Comment thread tests/unit/compilation/test_compile_no_dedup_flag.py Outdated
- 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>
@github-actions github-actions Bot mentioned this pull request Jun 6, 2026
@danielmeppiel danielmeppiel merged commit 3c43821 into main Jun 8, 2026
29 checks passed
@danielmeppiel danielmeppiel deleted the sergio-sisternes-epam/fix-issue-1678-target-aware-instruction branch June 8, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

panel-review Trigger the apm-review-panel gh-aw workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Regression instruction deduplication suppresses Codex AGENTS.md when .github/instructions exists

3 participants