Repository navigation
fix(optimizer): skip edits whose target overlaps a protected region - #373
Merged
Yifan Yang (Yif-Yang) merged 2 commits intoNov 7, 2026
Merged
Conversation
_is_in_protected_region only checked where an edit target starts. A replace or delete target that began in editable text and ran into <!-- SLOW_UPDATE_START --> or <!-- APPENDIX_START --> passed the check, so applying it removed the start marker and left the protected content in the editable body with an orphaned end marker. An insert_after with such a target wrote into the protected region. Treat a target as protected when its span overlaps the region, markers included. Targets that only touch text before the region still apply.
Keep both CHANGELOG entries; no other change.
Contributor
|
Merged, thank you. Note: your branch and #375 each added an entry at the same place in |
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.
Summary
Fixes #372.
A step-level
replaceordeleteedit whose target starts in editable skill text and runs into a protected region's start marker was applied. That removed<!-- SLOW_UPDATE_START -->(or<!-- APPENDIX_START -->) and left the protected content in the editable body. Aninsert_afterwith such a target wrote into the protected region. These edits are now skipped withskipped_protected_region, the same as edits that target text inside the region.User impact: without this fix, a training run can silently lose its slow-update or appendix guidance: the marker disappears, the protected text becomes editable body text, and later steps can rewrite or duplicate it.
Proof: the regression test fails on upstream
eb959c3and passes with this change.Root cause
_is_in_protected_region()inskillopt/optimizer/skill.pyonly tested whether the target's start index was inside a region:A target that begins before the start marker and extends into it fails that test.
_apply_edit_with_report()then runsskill.replace(target, ..., 1)across the marker.Changes
_is_in_protected_region()now treats a target as protected when its span[target_idx, target_idx + len(target))overlaps[start_idx, region_end). A target that ends exactly where the region starts does not overlap and still applies._apply_edit_with_report()is the only caller, so this covers the trainer path (apply_patch_with_report) and the exportedapply_edit/apply_patch.tests/test_skill_aware_reflection.pynext to the existing protected-region tests, covering both regions and all three targeted ops, plus an adjacent edit that must still apply. It is also registered in the file's standalonemain()runner.Reproduction
Before:
applied_delete False, and the result is'# QA Skill\n\n## Rules\n\nPrefer exact spans.\n<!-- SLOW_UPDATE_END -->\n'.After:
skipped_protected_region True, and the skill is unchanged.Testing
python -m pytest tests/test_skill_aware_reflection.py -q: the new test fails on upstreameb959c3withAssertionError: delete across <!-- SLOW_UPDATE_START --> must not change the skill, and passes with the fix.python tests/test_skill_aware_reflection.py: 7/7 passed.python -m pytest tests/test_skill_aware_reflection.py tests/test_semantic_density.py tests/test_sleep_engine.py -q: 158 passed, 1 skipped.python -m pytest -q: 2034 passed, 12 skipped, 4 xfailed.python -m mkdocs build --strict: passed.python -m ruff checkon the changed files: no new findings. The 6 import-order findings are on lines that are unchanged frommain.Risk and compatibility
Only targets that overlap a protected region change behavior, and those previously broke the region. Edits fully outside the regions,
append, andinsert_afterfallbacks are unchanged; the existing byte-identical and coexistence tests still pass. No backend, role, config key, file format or CLI change.