Repository navigation
fix(install): retire a package's hooks when apm deny or a removed approval gates them - #3944
Conversation
…gate withholds them apm deny (or an approval removed while the gate is on) made install skip the package's hooks but left the entries it had deployed earlier in merged harness configs such as .claude/settings.json. Install now retires them through HookIntegrator.reconcile_package_target_restriction, the same source-marker retirement used for target restrictions and local bundles; copied scripts already leave via stale-file cleanup. apm audit --ci replay now applies the same deny-wins allow-map for lock entries recorded as gated or denied, so it no longer replays withheld hooks. A hard-denied package is reported as denied and is not parked for approval. Refs #3924 apm-spec-waiver: executables-gate hook retirement is CLI behavior with no OpenAPM requirement Co-authored-by: Copilot App <[email protected]>
…4-deny-retires-hooks
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…4-deny-retires-hooks
There was a problem hiding this comment.
🟡 Changes recommended
Audit replay can miss denied hooks left registered in Claude and falsely report drift by misinterpreting hook approvals and ignoring the caller’s policy context.
3 open issues
When the last hook-producing dependency is denied, replay emits no shared hook config or ownership… · Newexec_statuscombines all executable types, so a package can deploy personally approved hooks… · New This resolver defaults tono_policy=False, so auditing a gated or denied dependency discovers and… · New
What changed in this PR
This PR addresses #3924 by retiring previously deployed package hooks when denial or removed approval blocks them. It reuses the existing hook retirement mechanism and updates audit replay to account for gated dependencies.
Changes:
- Retire gated hooks through the hook integrator and distinguish hard denial from missing approval.
- Apply executable approval checks during audit replay for gated lock entries.
- Add lifecycle and architecture regression tests, plus user-facing documentation.
| File | Description |
|---|---|
tests/integration/test_executables_deny_retires_hooks_lifecycle.py |
Tests hook retirement, user-hook preservation, messaging, and audit results. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds mutations checking required retirement and trust routing. |
src/apm_cli/security/executables.py |
Adds hard-denied executable type classification. |
src/apm_cli/integration/hook_integrator.py |
Broadens the retirement method's docstring; no functional change. |
src/apm_cli/install/services.py |
Invokes hook retirement when approval blocks deployment. |
src/apm_cli/install/exec_gate.py |
Adds denial-aware messaging and lazy replay approval resolution. |
src/apm_cli/install/drift.py |
Passes approval maps into gated dependency replay. |
src/apm_cli/install/context.py |
Tracks denied executable types for package diagnostics. |
scripts/architecture_linter/checks/install_lsp_plugin.py |
Requires canonical trust and retirement routing. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Documents hook retirement after denial or revoked approval. |
docs/src/content/docs/reference/cli/deny.md |
Explains retirement on the next install. |
CHANGELOG.md |
Records hook cleanup and denial messaging changes. |
Review effort: Balanced
…y selection in replay Folds Copilot review on #3944: - A shared hook config that replay no longer produces but that still holds APM-owned (non-local-bundle) entries is reported as drift, so a denied hook left registered fails apm audit --ci. - The replayed executables gate uses the audit's --no-policy / --policy selection instead of discovering policy on its own. Refs #3924 apm-spec-waiver: audit replay executables gate follows CLI policy flags; no OpenAPM requirement Co-authored-by: Copilot App <[email protected]>
…partial denies Folds the lean panel on #3944: - apm audit --ci discovers org policy once and hands it to the drift replay through a provider; replay builds the gate via effective_exec_map_for_project without migrating user consent. - apm deny tells the user to run apm install to remove executables that are already deployed. - Lifecycle coverage for cursor, codex, gemini and windsurf merge configs; partial-deny parking tests; audit plumbing guard tokens. - Update prepare_ci_audit_replay fakes for the new keyword. Refs #3924 apm-spec-waiver: audit replay executables gate follows CLI policy flags; no OpenAPM requirement Co-authored-by: Copilot App <[email protected]>
…4-deny-retires-hooks
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Supply Chain Security Expert | 0 | 3 | 0 | Install-side retirement is sound: markers are APM-assigned, so a package cannot spoof them. Audit still trusts the lock's own exec_status, so a stale or edited lock hides a denied hook. |
| Test Coverage Expert | 0 | 3 | 0 | Deny/revoke retirement is proven by an installed-CLI lifecycle test. Gaps: the partial-deny parking split, the cursor/codex/gemini merge configs, and how audit threads its policy flags into replay. |
| Python Architect | 0 | 3 | 0 | The owner calls are correct: hooks retire through _retire_source_markers and both gates build their maps through the trust owner. Audit replay fetched org policy a second time and re-checks trust only for gated lock entries. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 3 follow-ups
- [Supply Chain Security Expert] Add an audit/CI check that compares each lock entry's
exec_statuswith the committed project and org deny layers. -- Today a deny committed without a re-install passesapm audit --ci. - [Supply Chain Security Expert] Make hook ownership fail closed on a missing, unreadable or relabelled sidecar. -- Deleting or relabelling the sidecar can hide denied hooks from drift detection.
- [Python Architect] Record per-type withheld-exec evidence in the lockfile. -- Replay would stop keying its re-check on the aggregate
exec_status, matching fix(install): --frozen applies the executables gate and MCP omission evidence #3938; plan it together with item 1.
Recommendation
Merge once CI is green on head 7dfb5d6. All in-scope findings are folded and the seven-harness lifecycle test passes. Track the stale-lock audit check (highest priority), sidecar fail-closed ownership, and per-type lock evidence as follow-ups.
Folded in this run
- (copilot) Flag project-only shared hook configs that still hold APM-owned entries -- resolved in abccb03.
- (copilot) Replay honors the audit's policy selection -- resolved in abccb03.
- (panel) [python-architect] One policy fetch per audit via
policy_provider; no user-config migration; dead APMPackage load removed -- resolved in f5a6730. - (panel) [supply-chain-security-expert]
apm denyprints a hint to runapm install-- resolved in f5a6730. - (panel) [test-coverage-expert] Partial-deny parking tests with a real ExecTrustContext -- resolved in f5a6730.
- (panel) [test-coverage-expert] Lifecycle rows for cursor, codex, gemini and windsurf, including the leftover-audit failure -- resolved in f5a6730.
- (panel) [test-coverage-expert] Guard tokens and mutation cases for the audit-to-replay plumbing -- resolved in 7dfb5d6.
Copilot signals reviewed
src/apm_cli/install/drift.py:720-- LEGIT: replay emitting no shared hook config hid leftover denied hooks (resolved in abccb03).src/apm_cli/install/exec_gate.py:289-- LEGIT: replay ignored the audit's--no-policy/--policy(resolved in abccb03, refined in f5a6730).src/apm_cli/install/exec_gate.py:282-- NOT-LEGIT for this PR: replay mirrors install on the auditing machine; per-type lock evidence needs a lockfile schema change (deferred).
Deferred (out-of-scope follow-ups)
- (panel) [supply-chain-security-expert] Audit check comparing lock
exec_statuswith committed deny layers -- scope boundary: new audit check beyond [BUG] apm deny + reinstall leaves the package's already-deployed hooks registered #3924 done-when (after deny AND install). - (panel) [supply-chain-security-expert] Hook ownership fails closed on a missing or tampered sidecar -- scope boundary: hook ownership trust model, not executables-gate retirement.
- (panel) [python-architect] Per-type withheld-exec evidence in the lockfile -- scope boundary: lockfile schema change.
Regression-trap evidence (mutation-break gate)
tests/integration/test_executables_deny_retires_hooks_lifecycle.py-- ran on unfixed main 0e19cce; 3 of 3 rows FAILED as expected.test_gating_a_package_retires_its_deployed_hooks[claude-deny]-- deleted the drift leftover-hook branch; test FAILED as expected; guard restored.test_hard_denied_types_do_not_hide_approvable_ones-- deleted the per-type parking check; test FAILED as expected; guard restored.
Lint contract
uvx [email protected] check and format --check (CI paths), pylint R0801, lint-auth-signals.sh, lint-architecture-boundaries.sh, and the file-length and relative_to guards all ran clean on HEAD merged with main.
CI
gh pr checks 3944 at 7dfb5d6: 31 pass, 3 skipping, 0 failing (after 1 CI fix iteration: Build & Test Shard 1 fakes).
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3944 | 7dfb5d6 | ship_with_followups | 2 | 7 | 3 | 1 | green | MERGEABLE | BLOCKED | pending required review |
Full per-persona findings
Supply Chain Security Expert
- [recommended] Audit replay decides whether to apply the gate from the lock's
exec_status, so a stale or hand-edited lock masks a committed deny. Atsrc/apm_cli/install/exec_gate.py
The record being audited decides whether the audit enforces the deny. A deny added to apm.yml (or by org policy) without re-install, or exec_status edited to deployed, passes audit. Not a regression versus main. (Deferred.) - [recommended]
apm denydoes not say deployed hooks keep firing until the nextapm install. Atsrc/apm_cli/commands/approve.py:257
(Folded: deny now prints the hint.) - [recommended] Hook ownership comes only from a committed, editable sidecar, so deleting or relabelling it hides a denied package's hooks from retirement and audit. At
src/apm_cli/integration/hook_ownership.py:247
Package content cannot spoof markers. The gap is project-side tampering, and unreadable JSON fails open. (Deferred.)
Test Coverage Expert
- [recommended] No regression trap for a package with hooks denied but another type approvable. At
src/apm_cli/install/exec_gate.py:89
(Folded: partial-deny tests with a real ExecTrustContext, mutation-proven.) - [recommended] Lifecycle covered only claude (merge config) and copilot (per-file). At
tests/integration/test_executables_deny_retires_hooks_lifecycle.py:92
(Folded: cursor, codex, gemini and windsurf rows added.) - [recommended] No proof that
audit --ci --policy/--no-policyreaches the replay gate. Atsrc/apm_cli/commands/audit.py:629
(Folded: guard tokens and mutation cases on audit.py, audit_replay.py, ci_checks.py and drift.py.)
Python Architect
- [recommended] Audit replay discovered org policy separately from the audit's own fetch. At
src/apm_cli/install/exec_gate.py:292
(Folded: single cached fetch passed aspolicy_provider.) - [recommended] Replay re-checks trust only for lock entries recorded as gated or denied, which is a mixed contract versus fix(install): --frozen applies the executables gate and MCP omission evidence #3938. At
src/apm_cli/install/exec_gate.py:280
(Contract documented in the docstring; per-type lock evidence deferred.) - [recommended] ReplayExecAllowMap parsed APMPackage for nothing and could migrate user config during audit; the guard token names a local alias. At
src/apm_cli/install/exec_gate.py:289
(Folded: owner called directly withmigrate_user_legacy=False.)
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.
…cell Deny wins (#3944): frozen retires a gated hook through ordinary cleanup and, because it may not rewrite apm.lock.yaml, now exits 1 naming the missing file. I7 (a failed command preserves state) therefore fires on exactly the cell gate-cell-c-lock already tracks; record it the same way so the GATE spine stays strict. Co-authored-by: copilot-swe-agent[bot] <[email protected]>


Description
After
apm deny <pkg>(or an approval removed while the executables gate is on),apm installskipped the package's hooks but left the entries it had deployed earlier in merged harness configs such as.claude/settings.json. The hooks kept firing, often pointing at a copied script that stale-file cleanup had already deleted.apm audit --cidisagreed in both directions: its drift replay ignored the gate, so it replayed denied hooks. That hid the Claude leftover and flagged a correctly cleaned Copilot project asunintegrated.What changed:
install/services.py). When the gate withholds hooks, install callsHookIntegrator.reconcile_package_target_restrictionfor every active target. This is the existing source-marker retirement that target restrictions and local-bundle hooks (fix(install): register local plugin bundle hooks through the hook integrator #3897) use, so no second removal path was added. Per-file Copilot hooks and copied scripts are still removed by stale-file cleanup. User-authored and sibling-package entries stay.install/drift.py,install/exec_gate.py). For lock entries whoseexec_statusisgated_pending_approvalordenied, replay passes the deny-wins allow-map fromresolve_project_exec_allow_map. Entries recorded as fully deployed replay exactly as before, so CI machines without user approvals see no change for them.exec_gate.py,security/executables.py). A newdenied_exec_typesin the trust owner classifies hard denies. The skip line now readshooks skipped (denied). Run 'apm policy explain <pkg>' ...instead of telling the user to approve. A package whose only blocked types are hard-denied is no longer parked for approval.install/drift.py,integration/hook_ownership.py). A shared hook config that replay no longer produces but that still holds APM-owned (non-local-bundle) entries is reported as drift, so a denied hook left registered failsapm audit --ci.commands/audit.py,install/audit_replay.py,policy/ci_checks.py). The audit fetches org policy once and passes it to replay through apolicy_provider, so--no-policyand--policyapply to the replayed gate too. Replay never migrates user consent.apm denyhint: it now printsRun 'apm install' to remove executables already deployed.install-deployment-executable-trust-contextnow requires these routings, and a parametrized mutation test proves each one has teeth.Before (main 0e19cce): deny + reinstall leaves
bash "${CLAUDE_PROJECT_DIR}/.claude/hooks/hooky/scripts/hi.sh"in.claude/settings.jsonwith the script gone.apm audit --ciexits 0 for one target and 1 for another.After: the entry and its sidecar record are removed, the user's own hook stays, and
apm audit --cireports no drift.Issue and approved scope
Issue: Fixes #3924
Human scope-approval comment: #3924 (comment) (Review contact Daniel Meppiel (@danielmeppiel))
Does this PR complete the issue, or what remains? It completes the scope. Out of scope per the record: MCP/LSP/bin/canvas retirement under deny, local-bundle hooks, and the precedence ladder.
Type of change
Testing
Validation evidence (macOS arm64, head 7dfb5d6 merged with main):
APM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest tests/integration/test_executables_deny_retires_hooks_lifecycle.py -p no:xdist -qon unfixed main.venv/bin/python -m pytest tests/unit/install/test_replay_exec_allow_map.py tests/integration/test_executables_gate_integration.py tests/unit/install/test_ci_audit_materialization.py tests/unit/policy/test_ci_checks.py tests/integration/test_hook_sidecar_drift_e2e.py tests/unit/test_drift_detection.py -p no:xdist -q(one file at a time).venv/bin/python -m pytest tests/unit/install -p no:xdist -q(earlier head)test_drift_perfpasses alone (host load)tests/integration/test_architecture_owner_rule_mutations.py -k "gated_hooks_retire or executable-trust or covers_every or deterministic"+tests/unit/scripts/test_architecture_runner.pyuvx [email protected] check/format --check, pylint R0801,lint-auth-signals.sh,lint-architecture-boundaries.sh, file-length andrelative_toguardsgh pr checks 3944Panel advisory: #3944 (comment)
Changelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.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.