Skip to content

fix(optimizer): insert_after a target that ends in a newline right after it - #408

Merged
Yifan Yang (Yif-Yang) merged 2 commits into
microsoft:mainfrom
1AbdullahButt:fix/insert-after-trailing-newline
Nov 17, 2026
Merged

Yifan Yang (Yif-Yang) merged 2 commits into
microsoft:mainfrom
1AbdullahButt:fix/insert-after-trailing-newline

Conversation

@1AbdullahButt

Copy link
Copy Markdown
Contributor

Fixes #407

insert_after found the end of the target's line by searching for the next \n from the end of the target. When the target already ends with \n, that search found the end of the following line, so the content landed one line too late: under the next heading, or inside a protected region whose start marker follows directly.

The fix inserts at the end of the target when the target already ends its line. Targets without a trailing newline behave as before.

Tests

  • New tests/test_insert_after_newline_target.py: the issue's repro, a check that "## Rules\n" and "## Rules" now give the same result, and a check that the content stays outside a slow-update region that follows directly. All three fail on main and pass here.
  • tests/test_skill_aware_reflection.py, tests/test_types.py and the other tests that apply edits still pass (Windows, Python 3.10). The only failures in that set are the pre-existing Windows ones in tests/test_sleep_engine.py, which does not use skillopt/optimizer.

Claude Code wrote this change.

🤖 Generated with Claude Code

…ter it

insert_after finds the end of the target's line by searching for the
next newline from the end of the target. When the target already ends
with "\n", that search found the end of the following line, so the
content landed one line too late: under the next heading, or inside a
protected region whose start marker follows directly.

Insert at the end of the target when it already ends its line.

Fixes microsoft#407

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep both CHANGELOG entries; no other change.
@Yif-Yang
Yifan Yang (Yif-Yang) merged commit 29d0a2c into microsoft:main Nov 17, 2026
1 check passed
@Yif-Yang

Copy link
Copy Markdown
Contributor

Merged, thank you. insert_after now inserts directly after a target that ends with a newline instead of one line later. On main, the new tests fail (3 failures) and pass here. Closes #407. Your branch and an earlier PR in this batch each added an entry at the same place in CHANGELOG.md, so I pushed one maintainer merge commit to your branch that keeps both entries and changes nothing else, then merged.

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.

insert_after puts the content one line too late when the target ends with a newline

2 participants