Skip to content

fix(install): do not treat an empty skill directory as an unmanaged collision - #3449

Merged
Daniel Meppiel (danielmeppiel) merged 11 commits into
microsoft:mainfrom
MohammedAlkindi:fix/empty-skill-dir-collision
Nov 11, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 11 commits into
microsoft:mainfrom
MohammedAlkindi:fix/empty-skill-dir-collision

Conversation

@MohammedAlkindi

Copy link
Copy Markdown
Contributor

Description

apm install treats an empty pre-existing skill directory as an unmanaged collision because target_path.exists() is true, skipping the skill while reporting success. check_collision and target_existed now verify whether a directory contains files, deploying into empty directory trees.

Issue and approved scope

Issue: Fixes #3441

Human scope-approval comment: #3441

Does this PR complete the issue, or what remains? 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)

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via uv run --extra dev python -m tests.spec_conformance.gen_statement and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sergio-sisternes-epam

Copy link
Copy Markdown
Collaborator

Thank you for contributing this fix. APM starts with an issue, not an implementation (https://github.com/microsoft/apm/blob/main/CONTRIBUTING.md). Please ask a maintainer to review and accept the scope in #3441 before implementation proceeds. This PR is labelled status/deferred until then. Current review requests include Daniel Meppiel (@danielmeppiel) and Sergio Sisternes (@sergio-sisternes-epam).


Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors.

@sergio-sisternes-epam Sergio Sisternes (sergio-sisternes-epam) added status/deferred Not invited for implementation now; no release commitment. triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented. labels Nov 3, 2026
@danielmeppiel Daniel Meppiel (danielmeppiel) removed the status/deferred Not invited for implementation now; no release commitment. label Nov 10, 2026
…ills

The scope record for microsoft#3441 requires both the native-skill and the .apm sub-skill paths to deploy into an empty pre-existing skill directory, while other primitive types stay out of scope. The generic BaseIntegrator.check_collision change leaked to every primitive and the sub-skill path (_promote_sub_skills) still used target.exists(). Move the predicate into skill_support.skill_dir_has_content, which fails closed on symlinks, any non-directory entry, and unreadable subtrees, and use it on both skill paths. Addresses scope-gap review of PR microsoft#3449.

Co-authored-by: Copilot App <[email protected]>
Proves the microsoft#3441 done-when through the CLI: install into a nested empty .agents/skills/NAME exits 0, deploys SKILL.md and records the deployment in apm.lock.yaml for both native and .apm sub-skill layouts, while a directory holding an unmanaged SKILL.md is still refused with exit 1.

Co-authored-by: Copilot App <[email protected]>
Document that an empty skill destination tree is deployed into, and add the CHANGELOG entry crediting the contributor for microsoft#3449.

Co-authored-by: Copilot App <[email protected]>
os.path.islink does not report NTFS junctions on older Pythons, so a junction to an empty directory would read as an empty skill tree and let install write through it. Check the FILE_ATTRIBUTE_REPARSE_POINT bit from lstat for the root and every subdirectory and fail closed on lstat errors. Addresses supply-chain-security-expert panel finding on PR microsoft#3449.

Co-authored-by: Copilot App <[email protected]>
test_copy_failure_only_rolls_back_new_empty_destination asserted that a pre-existing empty skill directory blocks a later unmanaged install, which is the exact silent-skip microsoft#3441 fixes. Completion now depends only on whether user content (the partial SKILL.md) survives; rollback assertions are unchanged.

Co-authored-by: Copilot App <[email protected]>
The fix restores conformance with existing normative text rather than adding behavior: OpenAPM v0.1 section 8.3.1 (req-pr-008) says a shared directory or skill name alone MUST NOT establish file ownership or an unmanaged-skill conflict. An empty pre-existing skill directory is exactly that case.

apm-spec-waiver: conformance fix for existing 8.3.1 text; empty dir alone is not a conflict

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_with_followups

Community fix for #3441: install now deploys into an empty (or nested-empty) pre-existing skill directory instead of reporting success while skipping it, with a fail-closed emptiness check.

panel-mode=lean then delta; personas=python-architect,test-coverage-expert,supply-chain-security-expert,apm-ceo

cc Mohammed Alkindi (@MohammedAlkindi) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

Thank you Mohammed Alkindi (@MohammedAlkindi) for the fix. Measured against the approved scope on #3441, the original change fixed the native-skill path but left the .apm sub-skill path (_promote_sub_skills) still skipping an empty directory, and it changed the generic BaseIntegrator.check_collision used by every primitive type (out of scope). The merge pass kept your approach and moved the predicate into skill_support.skill_dir_has_content, used on both skill paths. It now treats symlinks, NTFS junctions, any non-directory entry and unreadable subtrees as content. Generic collision semantics for other primitives are unchanged.

The panel agrees. The architect found one owner and consistent semantics on both paths. Test coverage found every "Done when" clause proven at unit and installed-CLI tiers. Supply-chain security raised one finding (NTFS junctions), which was folded and re-reviewed clean. The Spec conformance Mode B detector needed an apm-spec-waiver. That waiver is sound: OpenAPM v0.1 section 8.3.1 already says "A shared directory or skill name alone MUST NOT establish either file ownership or this conflict", so this PR restores conformance rather than extending behavior.

Aligned with: Secure by default: the emptiness check fails closed on symlinks, junctions, non-directory entries and unreadable subtrees. Pragmatic as npm: leftover empty directories no longer cause a silent no-op install. OSS community driven: the contributor's fix is preserved and credited.

Panel summary

Persona B R N Takeaway
Python Architect 0 0 0 Single-owner predicate in skill_support.py, consistent across both skill paths, no leak to BaseIntegrator.
Test Coverage Expert 0 0 0 All Done-when clauses covered at unit and lifecycle tiers; expectation update is a legitimate #3441 behavior change.
Supply Chain Security Expert 0 1 0 Junction gap raised and folded; fold fails closed; no security regression.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 2 follow-ups

  1. [Supply Chain Security Expert] Add ensure_path_within containment on the _promote_sub_skills target path. -- This gap existed before this PR and is unrelated to empty-directory handling. It deserves its own bounded hardening issue.
  2. [Test Coverage Expert] Define preflight semantics for non-empty skill directories that hold a non-colliding unmanaged file (for example notes.txt). -- Such a directory is still skipped with a warning and exit 0. The scope record leaves non-empty preflight semantics out of scope, so this needs a separate decision.

Recommendation

Ship after maintainer review. The panel agrees, the one security finding was folded with tests and mutation-break evidence, CI is green, and both deferred items are outside the approved scope. Track them as follow-up issues.

Folded in this run

  • (panel) Sub-skill (.apm/skills) path still skipped an empty pre-existing directory; now uses skill_dir_has_content -- resolved in bdea808.
  • (panel) Reverted the generic BaseIntegrator.check_collision change, because other primitive types are out of scope; the predicate moved to skill_support, failing closed on symlinks and walk errors -- resolved in bdea808.
  • (panel) Installed-CLI regression for both layouts: a nested empty directory deploys SKILL.md, the apm.lock.yaml deployment is recorded and install exits 0; a populated directory is still refused with exit 1 -- resolved in 48cbfed.
  • (panel) CHANGELOG entry crediting Mohammed Alkindi (@MohammedAlkindi); one sentence each in reference/cli/install.md and the apm-guide commands.md -- resolved in 7a20780.
  • (panel) NTFS junctions are now treated as content by checking FILE_ATTRIBUTE_REPARSE_POINT -- resolved in 176d49b.
  • (panel) test_copy_failure_only_rolls_back_new_empty_destination expected the [BUG] An empty pre-existing skill directory makes apm install silently skip the skill (exit 0, nothing deployed) #3441 silent skip; its expectation is updated and its rollback assertions are unchanged -- resolved in c33e051.
  • (panel) Spec conformance Mode B detector: added an apm-spec-waiver trailer citing OpenAPM 8.3.1 -- resolved in f0e37c2.

Copilot signals reviewed

  • (review) -- NOT-LEGIT: Copilot did not review this PR because the requester was out of quota; there was no content to act on.

Deferred (out-of-scope follow-ups)

  • (panel) A skill directory holding a non-colliding unmanaged file is skipped with a warning and exit 0. Out of scope because the scope record excludes unmanaged-content preflight semantics for non-empty directories.
  • (panel) ensure_path_within containment on the sub-skill target path. Out of scope because it is a separate, pre-existing path-containment hardening.

Regression-trap evidence (mutation-break gate)

  • test_skill_integrator_hermetic.py::...::test_empty_preexisting_tree_is_deployed_not_skipped -- deleted the sub-skill skill_dir_has_content guard; the test FAILED as expected; guard restored.
  • test_native_skill_collision.py::test_native_skill_deploys_into_empty_preexisting_directory -- deleted the native guard; the test FAILED as expected; guard restored.
  • test_empty_skill_dir_install_lifecycle.py::test_install_deploys_into_empty_nested_skill_directory[subskills,native] -- deleted both guards; both cases FAILED as expected; guards restored.
  • test_skill_dir_has_content.py symlink, unreadable-subtree and reparse-point tests -- deleted each fail-closed branch; each test FAILED as expected; branches restored.

Lint contract

ruff check, ruff format --check, pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh are all silent on HEAD merged with current main. skill_integrator.py is 2098 of the 2100-line cap.

CI

All 27 checks are green on f0e37c2, including Lint, Build & Test shards, Lifecycle Smoke, the Windows gates, Spec conformance gate and license/cla. This took 1 CI fix iteration. Locally, the full tests/unit suite passed (25679 tests).

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#3449 f0e37c2 ship_with_followups 1 7 2 2 green MERGEABLE BLOCKED pending required review

Convergence

1 outer iteration and 2 Copilot rounds. Final panel stance: ship_with_followups. Ready for maintainer review.

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-merge-worker. This comment is AI-generated and may contain errors.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 6d6ba4f into microsoft:main Nov 11, 2026
2 checks passed
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 11, 2026
#3532 added "and not new_path.is_symlink()" to migrate_lockfile_if_needed.
The contracts-tooling-lockfile-read rule checked that fragment anywhere in
lockfile.py, so removing it from resolve_lockfile_path_for_read no longer
tripped the guard; the mutation test failed with "assert 2 == 1" in the
release dry run (43039615994, macOS arm64). Check the resolver fragments
within the resolver's own body and anchor the mutation on its clause.

#3449 changed "if self.check_collision(" to
"if target_existed and self.check_collision(", turning the native skill
collision mutation into a no-op. Anchor it on "self.check_collision(".

Refs #3567

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@MohammedAlkindi
Mohammed Alkindi (MohammedAlkindi) deleted the fix/empty-skill-dir-collision branch November 15, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] An empty pre-existing skill directory makes apm install silently skip the skill (exit 0, nothing deployed)

4 participants