Skip to content

apm compile --target codex is a silent no-op in distributed mode, leaving stale AGENTS.md with missing dependency instructions #766

@OKKU-Okuda

Description

@OKKU-Okuda

Describe the bug
apm compile --target codex appears to be broken in the distributed Codex compile path.

In my real project, AGENTS.md already exists, but one dependency instruction is missing after Codex-targeted distributed compile. The missing content is from codex-sync.instructions.md, while another dependency instruction from forgebridge.instructions.md remains present.

After tracing the behavior, this looks less like partial instruction merging and more like a silent no-op:

  • apm compile --target codex exits successfully
  • the existing AGENTS.md is not rewritten at all
  • because the stale file remains in place, it looks like Codex distributed compile generated an incomplete result

This reproduces on both:

  • PyPI apm-cli 0.8.11
  • latest main source at 522c24690ea2f42aea5a2d80441c742f0a67d607

This initially looked similar to #631 / #642 because validate can see both instructions while normal compile appears to drop one. However, this repro still fails even when the instructions are already local, so it does not look like the dependency .github/ scan bug fixed by #642.

To Reproduce
Steps to reproduce the behavior:

  1. Create a minimal project with this layout:

    codex-compile-repro/
    ├─ apm.yml
    └─ packages/
       ├─ pkg-a/
       │  ├─ apm.yml
       │  └─ .apm/instructions/a.instructions.md
       └─ pkg-b/
          ├─ apm.yml
          └─ .apm/instructions/b.instructions.md
    
  2. Use this root apm.yml:

    name: codex-compile-repro
    version: 1.0.0
    dependencies:
      apm:
        - ./packages/pkg-a
        - ./packages/pkg-b
      mcp: []
    scripts: {}
  3. Put one simple instruction in each package:

    ---
    applyTo: "**"
    ---
    
    # Package A
    
    - Rule from package A.
    ---
    applyTo: "**"
    ---
    
    # Package B
    
    - Rule from package B.
  4. Run:

    apm install
    apm compile --validate -v
    apm compile --target codex --dry-run -v
    apm compile --target codex
  5. Observe that:

    • apm compile --validate -v reports 2 instructions
    • apm compile --target codex --dry-run -v only prints startup/progress lines and no AGENTS preview
    • apm compile --target codex exits successfully but does not create AGENTS.md in the minimal repro
  6. In a real project where AGENTS.md already exists, observe that:

    • the file hash and modified timestamp remain unchanged after apm compile --target codex
    • the stale AGENTS.md remains in place, which makes it look like one dependency instruction was skipped

Expected behavior

  • apm compile --target codex should generate or update AGENTS.md, because Codex reads instructions from AGENTS.md
  • distributed Codex compile should not exit successfully while doing nothing
  • if AGENTS.md already exists, it should be updated when the compiled instruction set changes

Environment (please complete the following information):

  • OS: Windows
  • Python Version: 3.14.3
  • APM Version: 0.8.11
  • VSCode Version (if relevant): N/A

Also reproduced against latest main source:

  • commit: 522c24690ea2f42aea5a2d80441c742f0a67d607

Logs
apm compile --validate -v

[*] Validating APM context...
[*] All primitives validated successfully!
[i] Validated 2 primitives:
[i]   * 0 chatmodes
[i]   * 2 instructions
[i]   * 0 contexts

apm compile --target codex --dry-run -v

[*] Starting context compilation...
[i] Compiling for AGENTS.md + CLAUDE.md - explicit --target flag
[i] [dry-run] showing placement without writing files
Verbose mode: showing source attribution and optimizer analysis

apm compile --target codex

[*] Starting context compilation...
[i] Compiling for AGENTS.md + CLAUDE.md - explicit --target flag
[+] Compilation completed successfully!

In my real project, the file was not updated:

before_hash=C7B6112B6523F85FF47A8C4C95AEC3F598E505B5A4263F4D9B01BA1CED59F32A
after_hash=C7B6112B6523F85FF47A8C4C95AEC3F598E505B5A4263F4D9B01BA1CED59F32A
before_time=2026-04-19T10:32:54.4094263Z
after_time=2026-04-19T10:32:54.4094263Z

Additional context
Tracing the source locally suggests target-routing drift.

  • detect_target() correctly returns codex
  • the compile CLI passes target="codex" into CompilationConfig
  • but AgentsCompiler.compile() only routes AGENTS compilation for ("vscode", "agents", "all")
  • codex never reaches _compile_agents_md()
  • _merge_results([]) returns a successful empty result, which explains the silent no-op

There is also a misleading progress message:

  • --target codex reports Compiling for AGENTS.md + CLAUDE.md
  • but no AGENTS compile branch actually runs for codex

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions