Skip to content

fix(audit): name unrecorded files at a withheld package's hook path - #4767

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-p1-hook-path-detection
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-p1-hook-path-detection

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR. When the executables gate withholds a package's hooks (a deny, or no approval), a file sitting at one of that package's own hook destinations that apm.lock.yaml does not record is now named: apm install keeps it and warns with the path, and apm audit --ci fails hook-approval-pins naming the path. Nothing is deleted: without a lock record, APM cannot prove it wrote the file.

Problem (WHY)

  • A package-namespaced hook file (for example .github/hooks/<pkg>-<name>.json) can exist without a lock record, for example after a checkout restores it without apm.lock.yaml.
  • If that package's hooks are withheld, install said only that hooks were skipped and audit --ci passed, so nobody was told the file was there.

Approach and implementation

File Change
integration/copilot_hook_paths.py (new) Single owner of the Copilot hook file name (copilot_hook_target), used by HookIntegrator; copilot_hook_destinations() computes the files a package would deploy through the read-only shared source selector, without writing.
install/withheld_hooks.py (new) withheld_hook_files() (one package), locked_withheld_hook_files() (every locked package, judged by current_exec_decision, the install gate's own verdict, on its effective targets via resolve_effective_package_targets), announce_withheld_hook_files() (install warning via kept_file_message). Paths that cannot be computed fail closed: audit fails naming the package, install warns.
install/services.py After the hooks-skipped warning and target reconcile, install announces such files. Exit code unchanged.
policy/ci_checks.py hook-approval-pins also fails on these files (path, lock key, denied / not approved). The check list and count are unchanged.
Docs reference/baseline-checks.md (hook-approval-pins), apm-usage/governance.md.
core/remediation.py New withheld-hook-file-unrecorded: delete each named file you did not write yourself, then run apm audit --ci.

Scope: per-file hook destinations (the Copilot hooks directory). Merge-based hook targets are a separate follow-up. No deletion, by design.

Trade-offs

  • Report, never delete. Equal bytes are not proof of ownership; deleting could remove a user's own file.
  • Folded into hook-approval-pins rather than a new check, so audit output and check counts stay stable.

Issue and approved scope

Issue: none; scope set by the maintainers. Design accepted by the program lead.

Human scope-approval comment: approved by the maintainers.

Does this PR complete the issue? Yes for detection and announcement; retirement stays out of scope by design.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass (targeted neighbours)
  • Added tests for new functionality

tests/lifecycle/scenarios/test_ownership_siblings.py::test_a_withheld_hook_a_checkout_brings_back_is_kept_announced_and_detected (installed CLI, lifecycle kit with I1-I9 oracles):
install, approve, deny, install (hook retired); the file comes back without a lock; install keeps it and says Kept <path>: ...; audit --ci exits 1 naming the path; the printed remedy (delete the file, run apm audit --ci) passes.

Owner tests tests/unit/install/test_withheld_hooks.py: a package with legacy per-target hook file names is still checked; a dependency restricted away from Copilot is not reported; uncomputable hook paths fail closed. Each fails on the previous behaviour (3 failed, 2 passed) and passes now (5 passed).

  • Failing-before (src at main, test kept): R: 'audit --ci' exited 0, expected [1] / All 15 check(s) passed.
  • Passing-after: 1 passed.
Validation commands and results
host_guard.sh --lane landing ... pytest tests/lifecycle/scenarios/test_ownership_siblings.py::test_a_withheld_hook_a_checkout_brings_back_is_kept_announced_and_detected -n 0
  -> 1 passed (156.8s); with src reverted to main -> 1 failed (audit --ci exited 0)
host_guard.sh --lane landing ... pytest tests/unit/integration/test_hook_integrator.py tests/unit/integration/test_hook_integrator_defect_regression.py tests/unit/install/test_services.py tests/unit/install/test_services_branches.py tests/unit/install/test_services_hook_scope.py tests/unit/policy/test_ci_checks.py tests/unit/test_audit_policy_command.py tests/unit/core/test_remediation_block_proofs.py tests/unit/core/test_remediation_w4_frozen_policy_catalog.py tests/unit/core/test_remediation_catalog_commands.py -n 0
  -> 1449 passed
uvx [email protected] check / format --check src/ tests/          -> clean
python scripts/check_complexity_ratchet.py --base-ref main  -> clean
python -m tests.quality.taxonomy --changed                   -> clean
python scripts/check_test_assertions.py                      -> clean
python scripts/lint_architecture_boundaries.py --root .      -> clean
bash scripts/lint-auth-signals.sh                            -> clean
python -m tests.lifecycle.generator --check                  -> up to date

How to test

  • Install a package with a hook for target copilot, approve, install; apm deny <pkg>; install (the hook is removed).
  • Put the hook file back, delete apm.lock.yaml, run apm install: it warns Kept .github/hooks/<pkg>-<name>.json: ... and keeps the file.
  • apm audit --ci exits 1 naming the path; delete the file and it passes.

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 -- audit and install diagnostics only; waiver in the fix commit.

Co-authored-by: Copilot [email protected]

When the executables gate withholds a package's hooks (a deny, or no
approval), a file at one of that package's own hook destinations that
apm.lock.yaml does not record is now named: apm install keeps it and
warns, and apm audit --ci fails the hook-approval-pins check naming the
path. Nothing is deleted, since no lock record proves APM wrote it.

apm-spec-waiver: audit and install diagnostics for executable hook files; no OpenAPM-observable contract changes.

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

Unresolved audit issues can miss restored denied hooks, recommend deleting files outside a dependency’s allowed targets, and cause quadratic lockfile-parsing overhead.

3 open issues
What changed in this PR

This PR extends APM's executable-gate diagnostics to identify unrecorded files at a withheld package's Copilot hook destinations without deleting files whose ownership cannot be proven.

Changes:

  • Shares hook destination naming between deployment and read-only inspection.
  • Adds install warnings and failures under the existing hook-approval-pins audit check.
  • Adds remediation guidance, documentation, and lifecycle regression coverage.
File Description
tests/​unit/​core/​test_remediation_w4_frozen_policy_catalog.py Links the new remedy to lifecycle coverage.
tests/​lifecycle/​scenarios/​test_ownership_siblings.py Covers restored-hook detection, preservation, and remediation.
src/​apm_cli/​policy/​ci_checks.py Includes unrecorded withheld hooks in audit results.
src/​apm_cli/​integration/​hook_integrator.py Adds read-only destination discovery and shared naming.
src/​apm_cli/​install/​services.py Triggers warnings when hooks are withheld.
src/​apm_cli/​install/​exec_gate.py Detects and announces unrecorded hook files.
src/​apm_cli/​core/​remediation.py Defines cleanup and audit guidance.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Updates packaged audit guidance.
docs/​src/​content/​docs/​reference/​baseline-checks.md Documents the expanded check and remedy.
changelog.d/​4767.fixed.md Records the user-visible diagnostic change.

Review effort: Balanced

Comment thread src/apm_cli/install/exec_gate.py Resolved
Comment thread src/apm_cli/policy/ci_checks.py Resolved
…opilot_hook_paths.py)

Keeps hook_integrator.py under the 2100-line cap.

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

Audit can recommend deleting a symlink’s referent and falsely flag hook destinations because its target filtering and approval checks diverge from install.

3 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Report the hook symlink path instead of its referent

src/​apm_cli/​install/​exec_gate.py:1028

For an unrecorded hook symlink, portable_relpath() reports the referent instead of the hook destination, including an absolute path when the referent is outside the project. Following the printed deletion remedy can then delete that file while leaving the hook symlink behind, so audit still fails. Preserve the lexical hook destination for the ownership lookup and diagnostics so the remedy names the link itself.

Medium severity Use per-hook approval when auditing announced destinations

src/​apm_cli/​install/​exec_gate.py:1073

With two hook sources and only one valid pin, this treats the entire package as withheld and fails audit for an unrecorded file at the approved hook's destination. Install's check_executable_approval() admits that hook and skips the new announcement branch, so audit incorrectly labels the path as unapproved and advises deleting it. Use the same hook-approval verdict as install rather than inferring package-wide rejection from the aggregate executable status.

Review effort: Balanced

…d when unknown

- Destinations come from the read-only shared hook source selector, so a
  package whose hook routing install refuses is still checked.
- Each package is checked only on the targets install deploys it to
  (resolve_effective_package_targets with its persisted selection).
- A hook path that cannot be computed fails audit --ci naming the package,
  and install warns.
- The detection moves to install/withheld_hooks.py (exec_gate.py stays at
  its size); audit resolves the trust context 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

Active issues allow permission errors to silently skip unchecked packages and symlink resolution to misidentify hook paths, potentially directing deletion at the referent instead of the link.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/withheld_hooks.py Resolved
Comment thread src/apm_cli/install/withheld_hooks.py Resolved

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

Unreadable hook directories can let unrecorded hooks bypass approval checks, while unsafe parent symlinks and misleading remediation advice risk external-file deletion or leave errors unresolved.

3 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/withheld_hooks.py Resolved
Comment thread src/apm_cli/install/withheld_hooks.py Resolved
Comment thread src/apm_cli/policy/ci_checks.py Resolved
…; unreadable hook sources fail closed

- A hook destination whose parent directory resolves outside the project
  is reported as unchecked (inspect manually), never as a file to delete.
- A hook source directory that exists but cannot be listed yields an
  unchecked row instead of reading as no hooks.
- Unchecked rows carry their own remediation; deletion advice only names
  actual files.

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 a supported external COPILOT_HOME configuration can break both install and audit, with path-containment and symlink-safety implications.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit ad4ec56 into main Nov 22, 2026
94 of 95 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p1-hook-path-detection branch November 22, 2026 18:50
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
#4767)

The withheld-hook checkout row already proves the pair: with the deny
recorded and no lock, install keeps the user's file at the hook path and
says so, and audit --ci fails naming it. Baseline 527 -> 526.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (51e2e65, main f53aa79). Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- strict known cells for an MCP entry of a runtime no longer targeted (#4784)
  and a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Ledger regenerated (baseline 3, known-failing 1, required 2419).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (2e8592d, main acb0423). Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- strict known cells for an MCP entry of a runtime no longer targeted (#4784)
  and a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Ledger regenerated (baseline 3, known-failing 1, required 2419).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (2e8592d) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
  row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Ledger regenerated (baseline 3, known-failing 1, required 2419).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
  row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin and source-machine bundle identity oracles tightened.
Ledger regenerated (baseline 3, known-failing 1, required 2419).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
  row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
  row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened; the self_defined warn row is a real
warn-mode policy now and is strict known on #5070. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
  row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened; the self_defined warn row is a real
warn-mode policy now and is strict known on #5070; the #4826 refusal row checks rollback. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…C, v0.38 sweep)

Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
  deny, self_defined, max_depth, require_resolution, source_attribution,
  unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
  transitive MCP trust, content types); the #4826 install refusal is required
  now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
  row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
  install writes nothing (#4790), hook bundle approval pin (#4688), a registry
  URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
  provenance-unknown x denied-executable (#4767), audit --ci judges locked
  content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened; the self_defined warn row is a real
warn-mode policy now and is strict known on #5070; the #4826 refusal row checks rollback; no-write stamps add the POSIX change time. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).

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.

2 participants