Skip to content

fix(frozen): frozen fails when a gated hook was retired but the lock still claims it (#4043) - #4054

Merged
Daniel Meppiel (danielmeppiel) merged 26 commits into
mainfrom
danielmeppiel-frozen-retired-hook-4043
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 26 commits into
mainfrom
danielmeppiel-frozen-retired-hook-4043

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR. After apm deny (or a removed approval), apm install --frozen removed the package's hook but kept its lock record and exited 0, while apm audit --ci exited 1. Frozen post-deploy verification in InstallService now runs the same deployed-file presence check that audit uses. Frozen now exits 1, names each recorded file that is missing, and says to run apm install without --frozen and commit apm.lock.yaml. Deny still wins and the lockfile is never written.

Important

Stacked on #4016 (base danielmeppiel-animated-journey). CI does not run on a non-main base, so the evidence below is the local CI mirror.

Problem.

  • install/phases/cleanup.py (in-package stale pass) retires a hook that the gate stops deploying, as fix(install): retire a package's hooks when apm deny or a removed approval gates them #3944 intends, including under --frozen.
  • _enforce_frozen_no_rewrite checked selections, unrecorded claims and hash drift. It did not check presence, and verify_deployed_file_hashes deliberately skips missing files.
  • Audit's _check_deployed_files_present did check presence, so install --frozen && audit --ci gave two answers. The lock still claimed a file that was gone.

Approach.

Decision Choice
Owner InstallService frozen post-deploy verification (frozen-install-mutation-eligibility)
Shared verifier Audit's presence loop becomes public find_missing_deployed_files() in policy/ci_checks.py; audit deployed-files-present and frozen both call it (same path resolution, URI skip, gitignore filter)
Order unrecorded claims -> missing files -> hash drift
Deny still wins; retirement uses the existing cleanup path and its safety checks; no frozen cleanup ban
Lockfile never written (req-lk-006); repair is apm install without --frozen, then commit apm.lock.yaml

Implementation

File Change
policy/ci_checks.py find_missing_deployed_files(project_root, lock, targets) -> (missing, gitignored_skipped); _check_deployed_files_present delegates to it (output unchanged)
install/service.py _enforce_frozen_no_rewrite raises FrozenInstallError("--frozen: files recorded in apm.lock.yaml are missing from disk.") listing each path, with the repair tip; docstring now lists three checks
.apm/architecture/owners/install-deployment.json decision/owner text covers presence and hashes
scripts/architecture_linter/checks/install_frozen_and_audit.py install-deployment-frozen-mutation-eligibility requires the shared presence verifier in the owner and in audit
tests/integration/test_executables_deny_retires_hooks_lifecycle.py installed-CLI case (copilot, local hook package, deny / revoke)
tests/unit/install/test_frozen.py fixtures now leave claimed files on disk (they recorded claims they never deployed); presence case added
tests/spec_conformance/test_lockfile_reqs.py req-lk-017 case: a missing recorded file fails frozen and audit; lock bytes unchanged
docs install reference "Frozen mode fails rather than rewriting" (3 checks), deny reference retirement note (last commit, isolated)

Trade-offs

Benefits

  1. apm install --frozen && apm audit --ci give one answer on deployed-file presence (both use find_missing_deployed_files).
  2. A gated hook can no longer leave a lock that claims a file that is gone while frozen exits 0.
  3. A future bypass of the shared verifier fails the architecture linter (2 new mutation cases).

Validation

New test fails on main 67936cd (CLI version line 0.36.1 (67936cd7d)), both cases at the frozen step:

E       assert 0 == 1      # apm install --frozen exited 0 (deny)
E       assert 0 == 1      # apm install --frozen exited 0 (revoke)
2 failed, 13 deselected

On this branch:

Command Result
APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_executables_deny_retires_hooks_lifecycle.py 15 passed
pytest tests/unit/install/test_frozen.py 35 passed
pytest tests/integration/test_architecture_owner_rule_mutations.py -k frozen 34 passed
pytest tests/unit/policy tests/unit/install tests/spec_conformance + frozen lifecycle suite (incl. undeclared-retention, deployed-hash) no failures beyond host environment (git commit signing, root user, missing pwsh)
pytest tests/unit tests/integration -k "frozen or audit or deny or executables or gate" 2717 passed; 3 failed (audit-policy-discovery, audit-replay-config-modules-root mutation fixtures, which fail identically on main 67936cd); 44 errors (host git signing)
ruff check + format, pylint R0801, lint-auth-signals.sh, lint-architecture-boundaries.sh clean
orphan_check, gen_statement (committed), Mode B vs main and vs stack base OK
Scenario evidence
Scenario Test Principle
Deny / removed approval retires the hook; frozen exits 1 naming each hook path and the repair; hook absent; lock bytes unchanged; audit exits 1 test_frozen_fails_when_a_gated_hook_retires_but_the_lock_still_claims_it[deny|revoke] fail closed; one answer
Plain install then drops the claims, records denied / gated_pending_approval; frozen and audit both exit 0 same test lockfile matches deployed state
Hermetic: missing recorded file fails frozen and audit identically test_frozen_fails_closed_when_a_recorded_deployed_file_is_missing (req-lk-017) fail closed
Existing orphan retention and deployed-hash behavior unchanged test_frozen_undeclared_package_retention_lifecycle.py, test_frozen_deployed_hash_lifecycle.py, TestEnforceFrozenDeployedHashes no regression

How to test

  • APM_BINARY_PATH=$PWD/.venv/bin/apm uv run --extra dev pytest tests/integration/test_executables_deny_retires_hooks_lifecycle.py -k frozen
  • In install/service.py, replace find_missing_deployed_files(deploy_root, committed, targets) with ([], False); the test above and bash scripts/lint-architecture-boundaries.sh both fail.

Pre-merge

Issue and approved scope

Issue: Fixes #4043

Human scope-approval comment: #4043 (comment)

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 (host-environment and pre-existing main failures noted above)
  • Added tests for new functionality (if applicable)

Changelog

  • One line under ## [Unreleased] -> ### Fixed.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit: @pytest.mark.req("req-lk-017") test added under tests/spec_conformance/.
  • CONFORMANCE.{md,json} regenerated and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

Co-authored-by: Copilot [email protected]

@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
@danielmeppiel Daniel Meppiel (danielmeppiel) changed the title [0.38] fix(frozen): frozen fails when a gated hook was retired but the lock still claims it (#4043) fix(frozen): frozen fails when a gated hook was retired but the lock still claims it (#4043) Nov 20, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-frozen-retired-hook-4043 branch from e96841b to d6f545f Compare November 20, 2026 08:03
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-frozen-retired-hook-4043 branch from d6f545f to 51e6e34 Compare November 20, 2026 08:15
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-frozen-retired-hook-4043 branch from 51e6e34 to fa87f1b Compare November 20, 2026 08:24
Base automatically changed from danielmeppiel-animated-journey to main November 20, 2026 10:02
… it (#4043)

audit --ci and install --frozen now share one deployed-file presence
verifier (find_missing_deployed_files in policy/ci_checks.py). Frozen
post-deploy verification fails, naming each recorded file now missing and
the repair command, instead of exiting 0 while the lock still claims a hook
the executables gate retired. Deny still wins; the lock is never written.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
)

The frozen no-rewrite unit fixtures recorded claims they never deployed;
the shared presence verifier now (correctly) reports those as missing.
Adds the CHANGELOG Fixed line.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-frozen-retired-hook-4043 branch 2 times, most recently from 2b09cf3 to a9679af Compare November 20, 2026 10:50
…4043)

Steward ruling I7-X1: a failed command preserves durable state except
removing a deployed executable whose current decision is deny or revoked;
that removal is always applied and reported by path with remediation.

- install --frozen names each retired file and its decision source
  (org policy denies <pkg>, <pkg> is denied locally, <pkg> is no longer
  approved locally) through the exec gate owner (withheld_executable_sources
  over trust.package_withholding_layers), with the runnable repair command.
- --dry-run previews the retirement without removing anything.
- The GATE oracle encodes I7-X1 as a closed exception (lock never changes,
  no allowed surface goes, no file beyond the retired ones and their
  receipts) and drops the strict gate-cell-c-retire cell.
- The frozen-mutation-eligibility guard requires the closed exception and
  the owner routing, with four mutation cases.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-frozen-retired-hook-4043 branch from a9679af to 4c0cf56 Compare November 20, 2026 11:01
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 20, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 20, 2026 11:23
Copilot AI balanced review requested due to automatic review settings November 20, 2026 11:23

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 retirement preview reads the wrong manifest for --root installs and excludes partially admitted packages, causing incorrect approval decisions and missed executable retirements.

2 open issues
What changed in this PR

This PR aligns frozen-install verification with audit when a denied or unapproved hook is removed but remains recorded in apm.lock.yaml. It adds a shared presence check while preserving hook retirement and leaving the lockfile unchanged.

Changes:

  • Add missing-file verification, retirement diagnostics, and dry-run retirement previews.
  • Extend lifecycle, unit, conformance, and architecture-guard coverage.
  • Update CLI documentation, the changelog, and generated conformance records.
File Description
tests/​utils/​lifecycle_oracle.py Adds a failure-state exception for executable retirement.
tests/​unit/​install/​test_frozen.py Adds missing-file coverage and realistic deployed-file fixtures.
tests/​spec_conformance/​test_lockfile_reqs.py Checks frozen refusal, audit agreement, and unchanged lock bytes.
tests/​integration/​test_executables_deny_retires_hooks_lifecycle.py Exercises deny/revoke, preview, frozen refusal, and recovery.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds verifier-routing and retirement-exception mutation cases.
tests/​integration/​_gate_machine_kit.py Maps executable artifacts and removes the frozen/audit mismatch expectation.
src/​apm_cli/​security/​trust.py Exposes the policy layers withholding executables.
src/​apm_cli/​policy/​ci_checks.py Extracts the shared deployed-file presence verifier.
src/​apm_cli/​install/​service.py Checks missing recorded files before post-deploy hash verification.
src/​apm_cli/​install/​presentation/​dry_run.py Displays executable retirement previews.
src/​apm_cli/​install/​frozen_retirement.py Builds retirement reasons and frozen-error diagnostics.
src/​apm_cli/​install/​exec_gate.py Resolves withholding reasons through executable-trust decisions.
src/​apm_cli/​commands/​install.py Passes --no-policy into dry-run presentation.
scripts/​architecture_linter/​checks/​install_frozen_and_audit.py Guards shared verification and retirement-exception checks.
docs/​src/​content/​docs/​reference/​cli/​install.md Documents missing-file refusal, retirement previews, and recovery.
docs/​src/​content/​docs/​reference/​cli/​deny.md Describes frozen and dry-run behavior after denial.
CONFORMANCE.md Updates the deployed-file verification test count.
CONFORMANCE.json Registers the new conformance test.
CHANGELOG.md Records the frozen-install behavior change.
.apm/​architecture/​owners/​install-deployment.json Extends the frozen owner’s contract to file presence.

Review effort: Balanced

… read-only (#4043)

Frozen keeps an undeclared package's lock claims without deploying it
(#3662), so the post-deploy presence check now covers only the packages
the install resolved (InstallResult.active_package_keys).

The dry-run retirement preview replays packages through
drift._build_package_info, which loaded apm.yml with create_config=True
and created ~/.apm/config.json. Replay now reads config without creating
it, so dry-run stays read-only.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…e2e (tm006)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…n_retirement

#4272 grew install/service.py, so the frozen presence step moves out of the
owner into install/frozen_retirement.enforce_frozen_presence; the owner
keeps one call. The closed-world guard fragments and mutation cases follow
the move, with a new case for the owner skipping the presence step.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
#4093/#4095 moved the cross-cutting oracle to tests/lifecycle/oracles.py
and the GATE kit to tests/lifecycle/machines/_gate_kit.py, and I7 now also
rejects any changed durable file. I7-X1 follows: a failed command may only
remove the retired executables' files, the directories their cleanup
emptied, and their receipts; gate-cell-c-pair stays removed. The guard
fragments and mutation cases point at the new oracle, with a case for
receipts written without a retirement.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…d types

Review fold on #4054:
- Trust grants come from the manifest the install gate reads (the source
  project under --root DIR, APM_HOME at user scope), while modules stay
  beside the lock.
- The exec gate owner judges only the types the lock records as deployed,
  so a partially admitted package (exec_allowed_types) whose approved type
  is revoked is named by --frozen and previewed by --dry-run.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Main replaced security.executables.project_manifest_path with the scope
owner's scope_manifest_path (1cfd9ac).

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ite exec_gate lines

- The GATE reference model expected install --frozen to exit 0 unless the
  lockfile is missing, encoding #4043. Frozen now also exits 1 after it
  retired a hook the lock still records (I7-X1).
- The generator rule citations into exec_gate.py follow its new lines.
- I7-X1 returns early when no surface changed.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…4053)

Rebased onto #4054 with main: service.py is at its 1000-line budget, so the
stale-decision refusal lives in install/frozen_retirement beside the
presence step, returned rather than raised outside the owner. Org policy
for the staleness check routes through classify_discovery_outcome; update
keeps main's classify_project_policy. The guard fragments and mutation
cases follow; the lifecycle module gets tm006 markers; generator citations
into exec_gate.py follow its lines.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
This was referenced Nov 20, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 78f1a2f into main Nov 21, 2026
56 of 59 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-frozen-retired-hook-4043 branch November 21, 2026 05:24
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.

install --frozen and audit --ci disagree after hooks are denied

2 participants