Skip to content

plan/apply P3: frozen flag read only by its owner (#4012) - #4016

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-animated-journey
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-animated-journey

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR. InstallService (install/service.py, the registered frozen-install-mutation-eligibility owner) is now the only code that reads the install frozen flag. It exposes one FrozenDisposition; cleanup, lockfile and service integration consume it instead of reading the flag. A new closed-world architecture guard rejects any other read anywhere in src/apm_cli. No behavior change.

Problem.

  • Nine modules read ctx.frozen / getattr(ctx, "frozen", False) directly (cleanup, lockfile, service integration, integrate, resolve, pipeline, dry-run plan, plan inputs, the install adapter). Each restated part of the frozen decision outside its owner.
  • Two of them (phases/lockfile.py, install/service_integration.py) used getattr(..., False), so a context missing the field silently ran as non-frozen (fail-open).
  • The existing guard only checked that named call sites existed (a caller list), so a new direct read anywhere else would pass.

Approach.

Seam Before After
Flag read 9 modules, 2 fail-open InstallService.frozen_disposition(source) only; reads source.frozen directly (missing field -> AttributeError)
Orphan cleanup if ctx.frozen: _run_cleanup(..., *, frozen_disposition) (required) -> .retain_package_orphans
Lockfile ledger getattr(self.ctx, "frozen", False) owner disposition -> .withhold_lockfile_writes
Native services getattr(ctx, "frozen", False) is True run_service_integrations(..., *, frozen_disposition) (required) -> .withhold_lockfile_writes
Preflight, hydration, resolver pins, replay lock, dry-run, update gate ctx.frozen InstallService.frozen_disposition(ctx).replay / frozen_replay_lockfile(ctx); logic unchanged

Implementation

File Change
install/service.py FrozenDisposition (replay, retain_package_orphans, withhold_lockfile_writes), frozen_disposition(), frozen_replay_lockfile()
install/phases/cleanup.py, phases/lockfile.py, service_integration.py consume the disposition; ServiceCommandContext no longer declares frozen
commands/install.py, pipeline.py, phases/integrate.py, phases/resolve.py, dry_run_plan.py, helpers/plan_inputs.py route the remaining reads through the owner
scripts/architecture_linter/checks/install_frozen_and_audit.py new rule install-deployment-frozen-flag-reader: AST scan of every src/apm_cli/**/*.py except the owner for .frozen loads, getattr/hasattr(x, "frozen"), ["frozen"], attrgetter/.get/.pop("frozen"), case X(frozen=...); a function parameter named frozen outside the Click origin and five owner-fed sites; sys.frozen (PyInstaller) allowed; no exemption marker. Also requires the disposition keyword-only with no default at the cleanup and service-integration seams
.apm/architecture/owners/install-deployment.json new guard on the existing owner record (no new authority)
other linter checks literal needles updated to the routed forms

Trade-offs

  • Bool accessor vs. richer object. Preflight, hydration and resolver pins need a plain yes/no, so the disposition carries replay. The two named facets map to the same value today; they exist so P1 (plan/apply P1: one orphan removal owner #4011) and [BUG] Stale cleanup still trusts a lockfile hash that matches a file APM never deployed #3701 can rebase onto named consumer contracts.
  • Fail-closed fakes. The owner reads source.frozen with no default, so eight SimpleNamespace test contexts gained frozen=False. That is the intended behavior: a missing field no longer means "not frozen".
  • LOC budget. phases/resolve.py grows to 1001 lines (one import); its budget entry is added in test_architecture_invariants.py. pipeline.py stays at 1000 via frozen_replay_lockfile.

Benefits

  1. One reader of the install frozen flag instead of nine.
  2. Zero fail-open defaults on the frozen path (was 2).
  3. A new out-of-owner read, in any module, fails bash scripts/lint-architecture-boundaries.sh.

Validation

  • bash scripts/lint-architecture-boundaries.sh: clean.
  • Lint contract (ruff check + format, pylint R0801, lint-auth-signals.sh): clean.
  • Frozen lifecycle suite (APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_frozen_*.py tests/integration/test_git_semver_subdirectory_frozen_replay_lifecycle.py tests/integration/test_local_single_file_frozen_lifecycle.py tests/integration/test_obsolete_dependency_claim_frozen_control.py tests/integration/test_tls_frozen_hook.py): 61 passed, 41 skipped (APM_E2E_TESTS network cases). Unchanged files; includes test_frozen_undeclared_package_retention_lifecycle.py (passed).
  • pytest tests/unit/scripts tests/integration/test_architecture_owner_rule_mutations.py: 1315 passed, 1 failed. The failure is test_independent_owner_additions_merge_without_instruction_or_lock_conflicts, which runs git commit and is rejected by this host's commit-signing service (environmental, unrelated).
  • Install/spec unit tests: all failures traced to this host (commit signing, root user) and reproduced on origin/main. The 10 tests touched by this change pass.
  • orphan_check: OK; Mode B: satisfied by the new req-lk-006 conformance test; CONFORMANCE.{md,json} regenerated.
Scenario evidence
Scenario Test Principle
--frozen keeps an undeclared package's files, checkout and claims tests/integration/test_frozen_undeclared_package_retention_lifecycle.py (unchanged) reproducible installs
--frozen never rewrites the lock; consumers cannot omit the disposition tests/spec_conformance/test_lockfile_reqs.py::test_frozen_lock_withholding_is_decided_once_and_cannot_be_omitted (req-lk-006) fail closed
New out-of-owner read fails the guard (attribute) MutationCase install-deployment-frozen-flag-reader single owner
getattr, subscript outside install/, fail-open default, new bare frozen parameter test_frozen_flag_reads_outside_owner_fail_guard single owner

Known limits

  • The guard sees reads and parameters, not data flow. A value already taken from an allowed frozen parameter (e.g. if frozen: in commands/install.py, install/mcp/integration.py) or copied into a differently named local is not traced. Today every such value is the Click option or comes from the owner's disposition.

How to test

  • bash scripts/lint-architecture-boundaries.sh is clean.
  • Replace if frozen_disposition.retain_package_orphans: in install/phases/cleanup.py with if ctx.frozen:; rerun; the guard reports install-deployment-frozen-flag-reader.
  • Run the frozen lifecycle suite above; it passes unchanged.

Rebase after #4022

#4022 (#4013) lands first. It adds InstallService.enforce_frozen_restored(ctx.transitive_failures) inside the owner and calls it in phases/integrate.py, inside the block gated by the owner (if InstallService.frozen_disposition(ctx).replay and ... after this PR). It reads no flag, so the guard accepts it as-is. git merge-tree of this branch with #4022's head: no conflicts.

Issue and approved scope

Issue: Fixes #4012

Human scope-approval comment: #4012 (comment)

Does this PR complete the issue, or what remains? Completes it. Out of scope and unchanged: #3702, dry-run behavior, what --frozen refuses.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass (host-environment failures noted above; CI is authoritative)
  • Added tests for new functionality (if applicable)

Changelog

  • One line under ## [Unreleased] -> ### Changed (internal; required by the approved scope).
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit: @pytest.mark.req("req-lk-006") 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]

…ag (#4012)

The frozen-install-mutation-eligibility owner exposes one FrozenDisposition.
Cleanup, lockfile and service integration consume it instead of reading the
flag; service integration requires it keyword-only with no default.

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

install-deployment-frozen-flag-reader rejects any read of the install frozen
flag (attribute, getattr/hasattr, subscript, attrgetter, class pattern)
outside InstallService, and requires the disposition keyword-only with no
default at the cleanup and service-integration seams. sys.frozen stays
allowed. Registered on the existing frozen-install-mutation-eligibility
owner with a mutation case and focused bypass tests.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ers (#4012)

A bare boolean can carry the flag past the attribute scan. Only the Click
option origin and the five owner-fed parameters may declare 'frozen'; any
other function parameter named 'frozen' now fails the guard.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…tion (#4012)

The lockfile content-hash stream promotion added on main (#4000) read
getattr(ctx, "frozen", False). Route it through
InstallService.frozen_disposition (withhold_lockfile_writes), which the
closed-world frozen-flag guard requires. run_service_integrations gains a
PLR0913 noqa: main added claude_native_keys beside the required disposition.

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.

🟡 Changes recommended

The guard misses frozen-flag reads in mapping patterns while incorrectly rejecting write-only subscripts and get/pop fallback values, requiring detection fixes and regression coverage.

3 open issues
What changed in this PR

This refactor centralizes install --frozen flag reads in InstallService, supporting the plan/apply ownership work in #4012 and preparing named contracts for subsequent cleanup changes. It is intended to preserve existing install behavior.

Changes:

  • Introduces FrozenDisposition and routes install consumers through the owner.
  • Adds a source-wide architecture guard and required disposition arguments at cleanup and service-integration boundaries.
  • Updates regression tests, test contexts, ownership metadata, and conformance records.
File Description
tests/​unit/​scripts/​test_architecture_runner.py Registers the new guard in the expected inventory.
tests/​unit/​install/​test_lsp_integration.py Supplies dispositions to service-integration tests.
tests/​unit/​install/​test_frozen_service_boundary.py Passes the owner-derived disposition.
tests/​unit/​install/​test_architecture_invariants.py Adjusts module line budgets.
tests/​unit/​install/​test_absent_dependency_claim_reconciliation.py Makes the test context explicitly non-frozen.
tests/​unit/​install/​phases/​test_lockfile_union.py Adds explicit frozen fields to test contexts.
tests/​unit/​install/​phases/​test_lockfile_cross_package_reconcile.py Adds an explicit frozen field.
tests/​spec_conformance/​test_lockfile_reqs.py Tests disposition facets and missing-input rejection.
tests/​integration/​test_skipped_integration_preserves_deployments.py Updates the context for strict flag access.
tests/​integration/​test_cross_package_collision_file_survival.py Updates the context for strict flag access.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds guard mutations and updates existing checks.
src/​apm_cli/​install/​service.py Defines the disposition and owner accessors.
src/​apm_cli/​install/​service_integration.py Requires and consumes the disposition.
src/​apm_cli/​install/​pipeline.py Obtains the replay lockfile through the owner.
src/​apm_cli/​install/​phases/​resolve.py Uses the owner-derived resolver flag.
src/​apm_cli/​install/​phases/​lockfile.py Uses the disposition for reconciliation eligibility.
src/​apm_cli/​install/​phases/​integrate.py Routes frozen validation gating through the owner.
src/​apm_cli/​install/​phases/​content_hash_stream.py Uses the disposition to withhold hash promotion.
src/​apm_cli/​install/​phases/​cleanup.py Requires the disposition for orphan retention.
src/​apm_cli/​install/​helpers/​plan_inputs.py Routes update gating through the owner.
src/​apm_cli/​install/​dry_run_plan.py Obtains frozen planning state from the owner.
src/​apm_cli/​commands/​install.py Derives and forwards the disposition.
scripts/​architecture_linter/​checks/​install_uninstall_and_resolution.py Updates resolver-routing checks.
scripts/​architecture_linter/​checks/​install_package_content_hash.py Updates hash-promotion guard checks.
scripts/​architecture_linter/​checks/​install_frozen_and_audit.py Adds flag-read and required-argument checks.
scripts/​architecture_linter/​checks/​install_deployment_analyzers.py Registers the flag-reader rule.
scripts/​architecture_linter/​checks/​install_base_integrator_and_contraction.py Updates replay and cleanup call checks.
CONFORMANCE.md Updates the frozen requirement's test count.
CONFORMANCE.json Records the new conformance test.
CHANGELOG.md Describes the internal ownership refactor.
.apm/​architecture/​owners/​install-deployment.json Extends the existing owner record and guard list.

Review effort: Balanced

Review fold on the closed-world guard:
- Subscripts count only in Load context, so options["frozen"] = False and
  del options["frozen"] are not reads; augmented assignments still are.
- Mapping patterns (case {"frozen": value}) are reads.
- For get/pop only the first argument is the key; defaults are ignored.
Mutation cases cover the mapping and augmented forms; a regression case
proves writes, deletes and defaults pass.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-animated-journey branch 2 times, most recently from dad9c2b to 82423e9 Compare November 20, 2026 09:06
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
main's own pipeline.py budget (1005, #3701) now covers the frozen
replay accessor, so #4012's duplicate entry is dropped.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 640e8c0 into main Nov 20, 2026
36 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-animated-journey branch November 20, 2026 10:02
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.

plan/apply P3: frozen flag read only by its owner

2 participants