fix: reconcile sub-directory AGENTS.md in managed_section mode and never write into nested Git worktrees (#2560) - #2578
Draft
Aryan Singh K. (aryansk) wants to merge 1 commit into
Conversation
…ver write into nested Git worktrees (microsoft#2560) Two data-loss bugs in the distributed AGENTS.md write path: - Case A: `_prepare_distributed_file` scoped managed-section reconciliation to the root AGENTS.md (`is_root` guard from microsoft#1764), so a sub-directory file with markers was overwritten whole, destroying hand-authored content outside the managed block even under `agents_md.mode: managed_section`. Drop the guard: marker presence now decides at any depth, and a file without markers raises instead of being silently replaced. - Case B: the write path never checked Git boundaries, so a placement whose parent directory is the root of a nested independent worktree (`.git` file) was written into a repository APM was never pointed at. Mirror the orphan-sweep check and skip such placements with a warning. Tests updated: the old "subdir ignores managed_section" test now asserts marker reconciliation, plus a new test that nested-Git-worktree placements are skipped.
|
Aryan Singh K. (@aryansk) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2560
Summary
Fixes two silent data-loss bugs in the distributed AGENTS.md write path, exactly as the triage panel's suggested action describes.
Case A — sub-directory AGENTS.md loses hand-authored content under
managed_section_prepare_distributed_filescoped managed-section reconciliation to the root AGENTS.md only (theis_rootguard added in #1764). A sub-directory file carrying the markers was overwritten whole, destroying content outside the managed block even though the user had opted intomanaged_section.Fix: drop the
is_rootguard. Marker presence now decides at any depth; a file without markers raisesManagedSectionErrorinstead of being silently replaced (the existing conservative behavior).Case B — writes into nested independent Git repositories
The write path never checked Git boundaries, so a placement whose parent directory is the root of a nested worktree (a
.gitfile, not directory) was written into a repository APM was never pointed at — leaving an uncommitted modification in a foreign repo.Fix: mirror the orphan-sweep boundary check (
distributed_compiler.py) on the write path: skip the placement with a warning.Changes
src/apm_cli/compilation/agents_compiler.py: drop theis_rootguard from themanaged_sectionbranch; add_is_nested_git_worktree()and apply it in both the batch write loop and_write_distributed_file.tests/unit/compilation/test_managed_section.py: the old "subdir ignores managed_section" test now asserts marker reconciliation (the [BUG] Sub-directory AGENTS.md is overwritten whole, ignoring managed_section and foreign Git roots #2560 regression); added a nested-Git-worktree skip test.Validation
pytest tests/unit→ 19,803 passed, 2 skipped, 21 xfailedruff check+ruff formatclean