Skip to content

policy: route a rejected inheritance chain in trust-policy discovery - #4947

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
fix-4925-trust-policy-inheritance
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
fix-4925-trust-policy-inheritance

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

discover_trust_policy caught only OSError, ValueError and RuntimeError. A PolicyInheritanceError (an extends cycle, a cross-host extends, or chain depth over the limit) therefore escaped every executables-trust reader (apm install bundle preflight, apm approve, MCP admission and related readers) as a Python traceback.

discover_trust_policy now catches the owner's POLICY_DISCOVERY_ERRORS and converts them with discovery_failure_result, the same path apm audit uses. A rejected chain routes as the existing always-block incomplete_chain outcome. Readers then print one named line, [x] Blocked by org policy: org policy inheritance chain is incomplete ..., exit non-zero and write nothing. No new routing path: the error tuple, the conversion and the incomplete_chain route already exist in policy/outcome_routing.py.

The printed hint apm policy status --no-cache names the underlying cause (for example Cycle detected in policy extends chain: ...); this was checked by running it.

Issue and approved scope

Issue: Fixes #4925

Human scope-approval comment: issue carries status/accepted.

Does this PR complete the issue, or what remains? Completes it.

Type of change

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

Testing

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

New module tests/unit/policy/test_trust_policy_discovery_errors.py (component, P-OWN-policy-outcome-routing). Only discovery (the network boundary) is replaced.

Cell before this PR
apm approve --recommended with a rejected chain -> exit 1, one [x] line, no traceback, apm.yml unchanged FAIL (traceback) pass

Validation:

  • uv run --extra dev pytest -n 0 tests/unit/policy/test_trust_policy_discovery_errors.py: 1 passed (fails against main's outcome_routing.py)
  • uv run --extra dev pytest -n 4 tests/unit/policy/test_outcome_routing.py tests/unit/policy/test_trust_policy_discovery_errors.py tests/unit/commands/test_approve_deny.py tests/unit/test_audit_unresolved_policy.py: 163 passed
  • uvx [email protected] check / format --check (changed files): passed
  • python scripts/check_test_assertions.py: clean; python scripts/lint_architecture_boundaries.py --root .: clean; python -m tests.quality.taxonomy --changed: clean

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 -- this PR does not change OpenAPM-observable behaviour (error rendering for an outcome that already fails closed).

discover_trust_policy caught only OSError, ValueError and RuntimeError, so
a PolicyInheritanceError (extends cycle, cross-host extends, chain depth)
escaped every executables-trust reader as a traceback. It now catches the
owner's POLICY_DISCOVERY_ERRORS and converts them with
discovery_failure_result, so a rejected chain routes as the always-block
incomplete_chain outcome: one named [x] line, non-zero exit, nothing
written.

Fixes #4925

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.x milestone Nov 23, 2026
Copilot AI balanced review requested due to automatic review settings November 23, 2026 08:17
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[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.

🟢 Approval recommended

No active review issues are reported for the rejected policy inheritance error-handling change.

No open issues 🎉

What changed in this PR

This PR fixes #4925 by routing rejected policy inheritance chains through the existing policy-outcome handler, so trust-policy readers report a named error instead of a Python traceback.

Changes:

  • Catch the canonical POLICY_DISCOVERY_ERRORS in trust-policy discovery.
  • Add a regression test checking that apm approve --recommended exits with a named error and leaves apm.yml unchanged.
  • Document the user-visible fix in a changelog fragment.
File Description
tests/​unit/​policy/​test_trust_policy_discovery_errors.py Tests rejected-chain error handling and manifest preservation.
src/​apm_cli/​policy/​outcome_routing.py Uses the shared discovery-error tuple to catch inheritance failures.
changelog.d/​4947.fixed.md Records clearer errors for rejected policy inheritance chains.

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 7fabe19 into main Nov 23, 2026
71 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the fix-4925-trust-policy-inheritance branch November 23, 2026 13:33
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
CI durations: main's file plus the train's parity-kit entries.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] install shows a traceback instead of a policy error when the org policy chain has an inheritance error

2 participants