Skip to content

fix(compile): apply the org dependency policy before compiling installed content - #4724

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-policy-render-gate
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-policy-render-gate

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

apm compile renders installed dependency content into agent context: packages under apm_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 install refused with "Nothing was changed", yet apm compile still 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_policy in commands/compile/cli.py) before it writes anything. It reuses the existing owners rather than adding a new check:

  • Policy resolution: resolve_trust_policy routes the policy outcome as install does, so an unusable policy fails closed under fetch_failure_default: block.
  • Package check: policy_denied_locked_packages is the dependency check apm update and apm uninstall already 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=1 skips the check, as for every policy reader. --validate writes 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

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

tests/integration/test_compile_dependency_policy_lifecycle.py runs 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_dependency covers plain compile, --force-instructions and --local-only --force-instructions. The first two fail on main and pass here.
  • test_compile_renders_a_dependency_the_org_policy_allows is a no-regression check.

tests/unit/commands/compile/test_compile_dependency_policy.py covers block, warn, off, and no recorded packages (where policy is never resolved).

Local results:

  • Compile unit and commands tests: 2385 passed.
  • Compile integration suites: 72 passed.
  • Lint contract, quality baselines and lifecycle generator: green. Rule citations were re-anchored and the obligations ledger regenerated.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- applies the existing dependency policy to one more command; no new contract.

apm-spec-waiver: applies the existing org dependency policy check to apm compile; no new contract.

…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]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 08:59
apm-spec-waiver: applies the existing org dependency policy check to apm compile; no new contract.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread src/apm_cli/commands/compile/cli.py Resolved
Comment thread src/apm_cli/commands/compile/cli.py Resolved
…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread src/apm_cli/commands/compile/cli.py Resolved
Comment thread src/apm_cli/commands/compile/cli.py Resolved
Comment thread src/apm_cli/commands/compile/cli.py Resolved
…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread src/apm_cli/commands/compile/cli.py Resolved
Comment thread src/apm_cli/commands/compile/cli.py Resolved
… 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread src/apm_cli/commands/compile/watcher.py Resolved
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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit ae226f6 into main Nov 22, 2026
66 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-policy-render-gate branch November 22, 2026 16:21
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…_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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants