Repository navigation
fix(codex): resolve package-relative links in converted agent instructions - #3611
Conversation
…tions Codex agent conversion serialized the Markdown body into developer_instructions without the shared install-time link resolver, so valid in-package links (e.g. ../skills/<name>/SKILL.md) pointed at nonexistent paths under .codex/. Route the body through the existing BaseIntegrator.resolve_links owner for the generated agent location before TOML serialization, and report links_resolved like other agent targets. Native fields, diagnostics, containment and URL/anchor/ unsupported-link pass-through are unchanged. Fixes #2966 Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
A missing registered architecture guard for Codex link-rewriting delegation could let the shared-resolver bypass return without architecture-boundary lint detecting it.
1 open issue
What changed in this PR
Fixes #2966 by routing converted Codex agent instructions through the shared link resolver, so valid package-relative links remain usable from the generated TOML location.
Changes:
- Resolves Markdown body links before TOML serialization and reports the resolved-link count.
- Adds regression coverage for Codex/Copilot parity, pass-through behavior, reinstall, and source updates.
- Documents the Codex link behavior and records the fix in the changelog.
| File | Description |
|---|---|
tests/unit/integration/test_agent_integrator.py |
Adds link-resolution and reinstall/update regression tests. |
src/apm_cli/integration/agent_integrator.py |
Delegates Codex body-link rewriting to the shared resolver. |
packages/apm-guide/.apm/skills/apm-usage/package-authoring.md |
Clarifies link rewriting in Codex instructions. |
docs/src/content/docs/producer/package-relative-links.md |
Includes Codex TOML in the shared link contract. |
docs/src/content/docs/producer/author-primitives/instructions-and-agents.md |
Documents links relative to the generated agent location. |
CHANGELOG.md |
Records the Codex link-resolution fix. |
Review effort: Balanced
Register install-deployment-codex-agent-link-resolution on the BaseIntegrator owner record. The production Codex branch must pass _write_codex_agent a resolve_body_links callback bound to self.resolve_links with source_file/target_path, report the returned count as links_resolved, and the writer must apply it before TOML serialization. Direct static writer callers stay exempt. Without this guard, dropping the callback would silently restore the #2966 bypass while boundary lint passed. Addresses Copilot inline on src/apm_cli/integration/agent_integrator.py:286. Mutation-break: source rebinding, dropped keyword, wrong callee, discarded count, and skipped writer application each fail the rule. Co-authored-by: Copilot App <[email protected]>
The Codex writer now takes the shared ResolveLinks hook (the shape skill_integrator already uses) and calls it with its own source and target, so the call site cannot bind a mismatched source/target pair. The architecture guard now also requires the resolved body to be what gets serialized, and the BaseIntegrator owner record names install-time link rewriting. Addresses panel follow-ups (python-architect FU-3, FU-5, FU-6). Co-authored-by: Copilot App <[email protected]>
Adds a real-binary Copilot+Codex row to test_link_rewrite_e2e.py: the converted TOML's developer_instructions link reaches the same installed skill as the Copilot agent, and reinstall is byte-identical. Adds a unit test proving a managed TOML written before #2966 is repaired on the next install. Both fail when the Codex branch bypasses resolve_links. Addresses panel follow-ups (test-coverage-expert FU-1, FU-2). Co-authored-by: Copilot App <[email protected]>
Kiro agents do not rewrite links, so "the other agent targets" overstated parity. Name the Markdown/verbatim targets instead. Addresses panel follow-up (doc-writer FU-4). Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | FU-3, FU-5 and FU-6 are folded correctly; the writer calls the shared owner with its own source and target and serializes the resolved body. |
| Test Coverage Expert | 0 | 0 | 0 | FU-1 and FU-2 are folded correctly; the real-binary Codex+Copilot row and the stale-TOML repair test assert the user-visible fix. |
| Doc Writer | 0 | 0 | 0 | FU-4 is folded correctly; CHANGELOG and apm-guide compare Codex only to Markdown/verbatim agent targets. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
Ready to land as is. All six lean-pass follow-ups are folded and backed by tests that run the real binary, and the delta panel found nothing new. Whether the native Codex model follows these links stays unverified and out of scope, as the scope record says.
Folded in this run
- (copilot) Registered guard
install-deployment-codex-agent-link-resolutionon the BaseIntegrator owner record, with MutationCase and expected rule id -- resolved in 5756541. - (panel FU-1) Real-binary Copilot+Codex row in
tests/integration/test_link_rewrite_e2e.py; reinstall byte-identical -- resolved in 28b06b6. - (panel FU-2) Unit test: stale pre-fix managed Codex TOML repaired on reinstall -- resolved in 28b06b6.
- (panel FU-3) Guard requires the resolved body to be what is serialized -- resolved in 21d9753.
- (panel FU-4) CHANGELOG / apm-guide wording scoped to Markdown/verbatim agent targets (Kiro does not rewrite links) -- resolved in 4ab5288.
- (panel FU-5) Writer takes the
ResolveLinkshook and calls it with its own source/target -- resolved in 21d9753. - (panel FU-6) BaseIntegrator owner text names link rewriting via
resolve_links-- resolved in 21d9753.
Copilot signals reviewed
src/apm_cli/integration/agent_integrator.py:286-- LEGIT: a routed-through-owner change needs a registered static guard; same surface as this PR. Thread replied and resolved (resolved in 5756541).
Regression-trap evidence (mutation-break gate)
TestCodexAgentIntegrationlink tests (4) -- deletedresolve_links=self.resolve_linksat the Codex call site; tests FAILED as expected; guard restored.test_link_rewrite_e2e.py::TestMultiTargetLinkRewriting::test_codex_and_copilot_agent_links_reach_same_installed_skill-- same deletion; test FAILED (reviewer.toml link not rewritten); guard restored.install-deployment-codex-agent-link-resolution-- 7 source mutations (bypass, dropped keyword, wrong callee, discarded count, skipped application, discarded body, source/target swap) each produce a rule violation.
Lint contract
ruff check and ruff format --check (CI path set) silent; pylint R0801 10.00/10; lint-auth-signals.sh and lint-architecture-boundaries.sh exit 0; file-length, YAML-IO and relative_to guards clean, all at 66cd5aa (PR merged with current main).
CI
Previous head 2c6ac25 (same PR content before the final main merge): 23 checks pass, 3 skipping, 0 failing. Final head 66cd5aa was pushed after merging current main; its CI run is in progress at posting time.
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3611 | 66cd5aa |
ship_now | 2 | 7 | 0 | 2 | yellow | MERGEABLE | BLOCKED | pending required review; CI running |
Full per-persona findings
Python Architect
No findings in the delta pass. Lean pass raised three recommended items (FU-3, FU-5, FU-6), all folded above.
Test Coverage Expert
No findings in the delta pass. Lean pass raised two recommended items (FU-1, FU-2), both folded above.
Doc Writer
No findings in the delta pass. Lean pass raised one recommended item (FU-4), folded above.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
…esolution-2966 Co-authored-by: Copilot App <[email protected]>
Avoids landing-order conflicts with other queued PRs. Co-authored-by: Copilot App <[email protected]>
Lane L: main merged for landing
This comment was generated by an AI agent (Lane L landing desk) on behalf of Daniel Meppiel (@danielmeppiel). |
Clean merge of eight main commits (#3408, #2231, #2602, #3640, #3611, #3645, #3602, #3646); no lockfile or autopilot package conflicts and apm audit --ci passes with no drift. Co-authored-by: sergio-sisternes-epam <[email protected]> Co-authored-by: Copilot App <[email protected]>

Description
TL;DR
Codex agent conversion now routes the Markdown body through the shared install-time link resolver (
BaseIntegrator.resolve_links) before serializingdeveloper_instructions. A valid in-package link such as../skills/msbuild-antipatterns/SKILL.mdnow reaches the retained installed file from.codex/agents/, exactly as the Copilot output already did. Nothing else in the TOML changes.Fixes #2966
Note
Thanks Shuai Zhang (@hcoona) for isolating this with the same pinned package installed for both clients.
Sergio Sisternes (@sergio-sisternes-epam) please review — the issue stays assigned to you; this PR does not change that.
Problem (WHY)
integrate_agents_for_targetcalled_write_codex_agent(...)and hard-codedlinks_resolved = 0; the writer serializedbody.strip()unchanged, while every other agent target goes throughcopy_agent→resolve_links.main(2794714dca) with the reported pindotnet/skills/plugins/dotnet-msbuild#4c72b17…: parsed Codexdeveloper_instructionskept../skills/msbuild-antipatterns/SKILL.md, which from.codex/agents/points at a nonexistent.codex/skills/…. The Copilot output for the same install pointed at the retainedapm_modules/…/.apm/skills/msbuild-antipatterns/SKILL.md.Approach (WHAT)
.tomlpath, and resolve the body before TOML serialization.links_resolvedlike other agent targets.developer_instructionsfollows the existing package-relative link contract.Implementation (HOW)
src/apm_cli/integration/agent_integrator.py—_write_codex_agentgains an optional keywordresolve_body_linkscallable and returnsint. The Codex branch passesfunctools.partial(self.resolve_links, source=source_file, target=target_path). The writer stays astaticmethod; existing direct callers (tests, spec conformance) keep their behavior because the parameter defaults toNone. Frontmatter parsing, nativemodel/model_reasoning_effortfields, lossy-compilation diagnostics, symlink refusal and the target containment check are untouched.tests/unit/integration/test_agent_integrator.py— three regression tests on an installed-dependency fixture (apm_modules/owner/pkg) with a retained sibling skill: link resolution from the generated location (with#fragmentkept and native fields preserved), Codex-vs-Copilot parity on the same package, and reinstall + source update. The same fixture asserts the resolver's existing pass-through for URL,#anchor, missing-file and out-of-package (../../../../../outside.md) links.producer/package-relative-links.md,producer/author-primitives/instructions-and-agents.md, andpackages/apm-guide/.apm/skills/apm-usage/package-authoring.md: one clause each.Diagram
Legend: the Codex branch now joins the same resolver call that
copy_agentalready used; the boxed step is the new behavior.flowchart LR A["integrate_agents_for_target"] --> B{"format_id == codex_agent"} B -->|"no"| C["copy_agent"] --> R["BaseIntegrator.resolve_links"] B -->|"yes"| D["_write_codex_agent"] D --> E["parse frontmatter + diagnostics"] E --> F["resolve body links (NEW)"] F --> R F --> G["toml.dumps -> .codex/agents/NAME.toml"] style F stroke-width:3pxTrade-offs
resolve_body_linkscallable so existing direct static callers stay unchanged; rejected a second Codex-specific rewrite because the resolver already owns containment and URL/anchor rules.developer_instructions; frontmatter links never reach the TOML.apm_modules/like every other agent target; no duplication into.codex/skills, no symlinks, no new setting (all out of scope per the record).Benefits
SKILL.md(verified below with a TOML parser + filesystem check).links_resolvedis now accurate for Codex installs.Issue and approved scope
Issue: Fixes #2966
Human scope-approval comment: #2966 (comment) (review contact Daniel Meppiel (@danielmeppiel)).
eligibility.cjsfrom a trustedorigin/maincopy (2794714dca) returnedstate: record-present,authorizes_implementation: false.Important
The record lists "PR actions … automated implementation dispatch" and "assignment or relationship changes" as out of scope. On 2026-11-12 Daniel Meppiel (@danielmeppiel) directed delivery to proceed now (see the expedite note on the issue) — that direction supersedes the dispatch exclusion. Assignment is unchanged: the issue stays with Sergio Sisternes (@sergio-sisternes-epam), who is requested as reviewer.
Completes the issue: generated-file correctness for Codex is fixed with Copilot preserved. Native-model behavior (whether a Codex model follows the link) was not exercised and is not claimed.
Type of change
Testing
Note
Local preflight skipped by maintainer instruction (2026-11-12); CI is the gate.
Scenario evidence
.codex/agents/test_codex_relative_link_resolves_from_generated_agent_location; installed CLI on pinned dotnet-msbuildtest_codex_and_copilot_links_reach_same_resource; installed CLItest_codex_relative_link_survives_reinstall_and_update;apm install×2 andapm update8a52700→4c72b17Installed-CLI evidence (reported pinned package, real network install)
Checker parses each
.codex/agents/*.tomlwithtomllib, extracts relative links fromdeveloper_instructions, and resolves them from the TOML's directory (Copilot: from the.agent.mddirectory).Local tests, mutation check and lint mirror
How to test
apm.ymlwith dependencydotnet/skills/plugins/dotnet-msbuild#4c72b17fa2c2aaa307d8f1e337ec75cab45ac5c7.apm install --target copilot,codex.codex/agents/msbuild-code-review.toml; themsbuild-antipatterns skilllink resolved from.codex/agents/exists..github/agents/msbuild-code-review.agent.md; both links reach the sameSKILL.md.uv run --extra dev pytest tests/unit/integration/test_agent_integrator.py -k "relative_link or same_resource"Spec conformance (OpenAPM v0.1)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
Co-authored-by: Copilot [email protected]