Skip to content

[0.38] fix(pack): honour a package's own targets: exclusion when its cache is missing (#4850) - #4858

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-p2-4850-pack-own-target-exclusion
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-p2-4850-pack-own-target-exclusion

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Since #4824, apm pack in a Claude+Copilot project refuses when a dependency's apm_modules/<dep> copy is missing unless the lock records the dependency edge excluding Claude. A package that excludes Claude through its own targets: (for example an instruction-only package with targets: [copilot]) was refused too, although it has no Claude guidance to lose.

  • src/apm_cli/install/target_filter.py (owner of package target authorization) gains two functions. recorded_package_targets(package) returns the package's own restriction: canonical targets:, or empty when absent or all, the same rule resolve_effective_package_targets applies. recorded_targets_exclude(target, recorded) judges a recorded restriction with package_allows_target, the same function install uses.
  • Install records the restriction at each acquire site (source_helpers.record_package_targets, next to the declared-licence recorder) and attaches it to the lock row as package_targets, like package_type.
  • _lock_proves_claude_excluded (pack) now accepts either the edge's target subset or the recorded package_targets.
  • Old lockfiles load unchanged. An absent package_targets proves nothing, so pack still fails closed and apm install records the field. OpenAPM Section 5.2 requires consumers to preserve unknown entry fields, and the lockfile schema admits additional entry properties.
  • _copy_subset_pairings moves verbatim to models/dependency/subsets.copy_subset_pairings so lockfile.py stays under its 2100-line cap.

Issue and approved scope

Issue: Fixes #4850

Human scope-approval comment: the accepted record on #4850 (status/accepted, milestone 0.38.0).

This PR completes the issue.

Type of change

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

Testing

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

Local pytest is suspended for this team (rule 17); the evidence is PR CI and ci-integration. Failing-before is shown by reasoning: before this change install wrote no package_targets, so the new cell's lock assertion fails, and pack refused with "apm_modules/guard-kit is missing" because the edge declares no targets:.

promise: P-OWN-claude-agents-md-instruction-routing -- pack refuses only a dependency whose Claude guidance could be lost; a package excluding Claude by its own targets: has none (source: #4850 record)
cell: OP=pack SRC=git PRIM=instruction CACHE=missing TGT=claude+copilot PKG-TARGETS=[copilot] EDGE-TARGETS=none   owner: install/target_filter.py
instrument: today test -> tests/integration/test_claude_agents_md_pack_lifecycle.py::test_pack_keeps_packing_a_package_whose_own_targets_exclude_claude (extends the #4755 module)
oracles: [lock row records package_targets: [copilot], both pack formats exit 0 with no missing-cache refusal, no Claude rule shipped]
control: test_pack_refuses_a_claude_dependency_whose_cache_directory_is_missing and test_pack_refuses_when_only_a_prompt_was_deployed_without_its_cache (non-excluding packages still refuse, both formats)
owner table: tests/unit/integration/test_pack_claude_exclusion_proof.py (edge / own / includes-claude / all / precedence; old rows load and round-trip)
ledger: tests/fixtures/lifecycle_bug_ledger/bugs/4850.json

Lint mirror clean locally: ruff check/format (0.15.12), pylint R0801, lint-auth-signals, complexity ratchet, assertion-quality ratchet, tm006, architecture boundaries, Mode B (no critical-path diff).

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 (an implementation lock-entry field, preserved as unknown per Section 5.2).

…s missing (#4850)

Since #4824, pack refused a missing apm_modules/<dep> unless the lock
recorded the edge excluding Claude, so a package excluding Claude through
its own targets: was over-refused. Install now records that restriction on
the lock row (package_targets, decided by target_filter.recorded_package_targets),
and pack consults it through target_filter.recorded_targets_exclude. Old
lockfiles load unchanged (an absent field proves nothing, so pack still
fails closed). _copy_subset_pairings moves to models/dependency/subsets.py
to keep lockfile.py under its size cap.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 22, 2026
Copilot AI balanced review requested due to automatic review settings November 22, 2026 23:59

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

Critical target-metadata validation and stale-manifest issues can falsely establish Claude exclusion, allowing pack to omit guidance rather than refuse when dependency caches are missing.

2 open issues
What changed in this PR

This PR addresses #4850 by recording a package's own target restrictions during install, allowing apm pack to recognize Claude exclusions when the dependency cache is missing.

Changes:

  • Persist package target restrictions in lock entries and consult them during pack.
  • Add regression coverage for both pack formats and older lock entries.
  • Relocate the subset-pairing copy helper without changing its behavior.
File Description
tests/​unit/​integration/​test_pack_claude_exclusion_proof.py Tests exclusion evidence and lock-entry compatibility.
tests/​integration/​test_claude_agents_md_pack_lifecycle.py Tests package-level exclusion with missing cache in both formats.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4850.json Records the regression and its coverage.
src/​apm_cli/​models/​dependency/​subsets.py Hosts the relocated subset-pairing copy helper.
src/​apm_cli/​integration/​instruction_integrator.py Consults recorded package restrictions before refusing pack.
src/​apm_cli/​install/​target_filter.py Adds helpers to record and evaluate target restrictions.
src/​apm_cli/​install/​sources.py Records restrictions at three acquisition sites.
src/​apm_cli/​install/​source_helpers.py Adds package-target recording.
src/​apm_cli/​install/​phases/​lockfile.py Attaches recorded restrictions to lock entries.
src/​apm_cli/​install/​context.py Stores restrictions during install.
src/​apm_cli/​deps/​lockfile.py Serializes and loads package_targets.
changelog.d/​4858.fixed.md Documents the user-visible pack fix.

Review effort: Balanced

Comment thread src/apm_cli/deps/lockfile.py Resolved
Comment thread src/apm_cli/install/source_helpers.py Resolved
The consumer round-trip fixture and the property generator now cover the
new LockedDependency field.

apm-spec-waiver: package_targets is an APM implementation lock-entry field that OpenAPM Section 5.2 requires consumers to preserve as unknown; no req governs per-entry implementation fields and no normative behaviour 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.

🔵 Needs a closer look

Stale manifest target recording and malformed lockfile target values can falsely exclude Claude, allowing dependencies to be packed without required Claude guidance when their cache is missing.

2 open issues

Review effort: Balanced

…ialized manifest (#4850)

A scalar package_targets decoded into single letters and falsely proved
Claude excluded; only a list of strings is a recorded restriction now.
record_package_targets drops the parse-cache entry first, so a manifest
rewritten in this run is re-read.

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 findings expose a missing-guidance safeguard bypass through blank target restrictions, quadratic cache scanning during install, and a plugin exclusion test that checks the wrong output path.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Reject blank package targets as proof of Claude exclusion

src/​apm_cli/​deps/​lockfile.py:439

The decoder accepts package_targets: [""] or [" "] as a non-empty restriction, which recorded_targets_exclude() treats as proof that Claude is excluded. With an attested dependency's cache missing and no edge exclusion, pack then skips the missing-guidance refusal despite the malformed restriction. Reject blank elements as no proof and add blank-list cases alongside the scalar controls.

Medium severity Assert the plugin-format Claude rule output path

tests/​integration/​test_claude_agents_md_pack_lifecycle.py:472

For the plugin-format iteration, this assertion checks the wrong location: Claude rules are exported to instructions/guard.md, not .claude/rules/guard.md (src/apm_cli/bundle/plugin_exporter.py:663-706). The assertion therefore passes even if the plugin incorrectly ships the Claude rule. Check the format-specific output path so both iterations protect the no-Claude-rule requirement.

2 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/source_helpers.py Resolved
…ache invalidation (#4850)

invalidate_apm_yml_cache_entry scans the whole parse cache, so calling it per
dependency made install O(N^2). Parse the manifest fresh with from_mapping
instead; behaviour is unchanged.

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 an unpublished critical finding shows malformed exclusion evidence can bypass refusal safeguards and omit an attested dependency’s Claude guidance.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 0cfcfc9 into main Nov 23, 2026
72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-4850-pack-own-target-exclusion branch November 23, 2026 06:41
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Fold the changelog.d fragments for #4858, #4868, #4870, #4880 and #4908 into [0.38.1].

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] pack refuses a missing cache for a package whose own targets exclude Claude

2 participants