Repository navigation
fix(compile): apply the org dependency policy before compiling installed content - #4724
Conversation
…led content apm compile now applies the dependency check install, update and uninstall apply to the packages apm.lock.yaml records, routed through the trust policy owner. When a recorded package is no longer allowed and the policy enforces block, compile writes nothing and exits 1 naming the package; under warn it warns and compiles. Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: applies the existing org dependency policy check to apm compile; no new contract. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Critical policy-enforcement gaps allow denied packages to be rendered during later watch compilations and through the global compile path.
2 open issues
What changed in this PR
Adds an org dependency-policy preflight to project compilation, reusing existing policy resolution and locked-package checks to block denied content before generating agent context.
Changes:
- Adds block, warn, and off handling with actionable refusal guidance.
- Adds component and lifecycle tests for denied and allowed dependencies.
- Updates command documentation, the changelog, and lifecycle evidence references.
| File | Description |
|---|---|
tests/unit/core/test_remediation_w4_frozen_policy_catalog.py |
Links the new remediation entry to lifecycle coverage. |
tests/unit/commands/compile/test_compile_dependency_policy.py |
Tests enforcement modes and empty dependency records. |
tests/quality/lifecycle_obligations.json |
Refreshes compile evidence line references. |
tests/lifecycle/generator/rules.py |
Reanchors compile rule citations. |
tests/integration/test_compile_dependency_policy_lifecycle.py |
Exercises denied and allowed packages through the real CLI. |
src/apm_cli/core/remediation.py |
Adds recovery guidance for policy-blocked compilation. |
src/apm_cli/commands/compile/cli.py |
Adds the dependency-policy preflight before project compilation. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Documents compile refusal and warning behavior. |
docs/src/content/docs/reference/cli/compile.md |
Describes enforcement, bypass, remediation, and exit status. |
docs/src/content/docs/enterprise/apm-policy.mdx |
Adds compile behavior to policy troubleshooting guidance. |
changelog.d/4724.fixed.md |
Records the user-visible policy enforcement fix. |
Review effort: Balanced
…g dependency policy Covers apm compile -g, manifest dependencies installed without a lock row, local bundle staging, the redirected root of --root, and each --watch recompile. The lifecycle model now expects compile to refuse, as install does, under a dependency deny and when the org policy cannot be fetched under fetch_failure_default: block. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Critical policy gaps allow dependencies introduced after preflight or missed by redirected/global package checks to bypass enforcement and expose denied content in compilation output or agent context.
3 open issues
2 resolved since last review
Review effort: Balanced
…scripts With --root the renderer combines the source manifest with the redirected installation, so a package declared in one root and installed in the other is judged too. Packages a pre-compile script installs are judged before rendering. Re-anchor the compile citations the rules cite. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Two critical policy-check bypasses can allow denied content into generated context by overwriting lock-derived replacement sources or skipping checks for packages added or changed before rendering.
2 open issues
3 resolved since last review
Review effort: Balanced
… the lock's effective source Right before rendering, under the lifecycle lock, compile judges the current installed inventory again, whether or not pre-compile scripts ran, so a package installed while it waited, or a source swapped under an existing key, is judged. A warning is reported once per command. A declared entry never replaces the lock's effective (replace:) source for the same key. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because conflicting dependency references across roots can bypass policy checks and let the Claude formatter import a denied package.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
The recheck under the lock re-reads the installed inventory with the policy the early check resolved, so the policy outcome line prints once. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The watch handler retains cached policy across recompilations, allowing later edits to render content after an allow-to-deny change; the cache must be cleared before each check and covered by a regression test.
1 open issue
Review effort: Balanced
A watch session keeps one logger; reset the per-compilation policy cache before each recompile so an allow-to-deny change stops the next render. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because conflicting source and redirected inventory references can bypass denied-fork checks, allowing blocked CLAUDE.md content to reach agent context.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
…_reasons.py (exec_gate.py 1007 -> 945 LOC) Main 387ae90 failed test_no_install_module_exceeds_loc_budget after #4724 and #4729 both grew exec_gate.py. executable_skip_reason and withheld_executable_reason (the wording install and pack print for a parked executable) move to their own module under the executable-trust-context owner; callers import it directly. No budget raise. Co-authored-by: Copilot App <[email protected]>

Description
apm compilerenders installed dependency content into agent context: packages underapm_modules/, plus the files they deployed, which compile scans as local content. It did not consult org dependency policy. After the org policy stopped allowing an installed package,apm installrefused with "Nothing was changed", yetapm compilestill compiled that package's instructions (for example into AGENTS.md with--force-instructions, or through the deployed copies with--local-only) and exited 0.Compile now runs a dependency-policy preflight (
_enforce_dependency_policyincommands/compile/cli.py) before it writes anything. It reuses the existing owners rather than adding a new check:resolve_trust_policyroutes the policy outcome as install does, so an unusable policy fails closed underfetch_failure_default: block.policy_denied_locked_packagesis the dependency checkapm updateandapm uninstallalready apply to locked packages.Enforcement modes:
block: compile names each package and its reason, prints the catalog remediation (compile-dependency-denied), writes nothing and exits 1.warn: it warns and compiles.off, no lockfile, or no recorded packages: it does nothing. With no recorded packages, no policy is resolved.APM_POLICY_DISABLE=1skips the check, as for every policy reader.--validatewrites nothing and is not gated.Docs:
reference/cli/compile.md(description and exit codes),enterprise/apm-policy.mdx,apm-usage/commands.md.Issue and approved scope
Issue: none; scope set by the maintainers. Maintainer ruling: every command that writes agent context consults the dependency policy, and content the policy denies is never compiled in.
Human scope-approval comment: approved by the maintainers.
Does this PR complete the issue, or what remains? It completes the compile surface. Install, update, uninstall, unpack and pack already apply the dependency policy.
Type of change
Testing
tests/integration/test_compile_dependency_policy_lifecycle.pyruns the real binary in the hermetic lifecycle world with an org policy served through the project's git remote:test_compile_refuses_to_render_an_org_denied_dependencycovers plain compile,--force-instructionsand--local-only --force-instructions. The first two fail on main and pass here.test_compile_renders_a_dependency_the_org_policy_allowsis a no-regression check.tests/unit/commands/compile/test_compile_dependency_policy.pycovers block, warn, off, and no recorded packages (where policy is never resolved).Local results:
Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedapm-spec-waiver: applies the existing org dependency policy check to apm compile; no new contract.