SkillOpt icon indicating copy to clipboard operation
SkillOpt copied to clipboard

sleep: a learned block with no END marker makes the next edit delete the rest of CLAUDE.md

Open 1AbdullahButt opened this issue 2 weeks ago • 0 comments

If a CLAUDE.md (or SKILL.md) has the <!-- SKILLOPT-SLEEP:LEARNED START --> marker but no matching END marker, the next sleep edit throws away everything after the START marker. That includes the user's own sections and the learned items already there. The block's banner says "Hand-edits outside this block are never touched."

_strip_learned truncates the document at an orphan START (doc = doc[:s]), and extract_learned returns "" when END is missing, so the existing learned items are lost too. An END marker can go missing when someone hand-edits the file or resolves a merge conflict.

Code: https://github.com/microsoft/SkillOpt/blob/45f65ca04f5f6713bca7b9797b495696ba812751/skillopt_sleep/memory.py#L24-L44

Steps to reproduce

from skillopt_sleep.memory import LEARNED_START, apply_edits
from skillopt_sleep.types import EditRecord

doc = (
    "# Project notes\n\n"
    + LEARNED_START + "\n## Learned preferences & procedures\n\n- Run tests with -q\n\n"
    "## My own section\n\n- Never push to main\n"
)
new, applied = apply_edits(doc, [EditRecord(target="memory", op="add", content="Use ruff")])
print(new)

Expected

"## My own section" and "- Never push to main" are kept, and "- Run tests with -q" is not lost. Treating the orphan marker the way _strip_all_slow_update_fields in skillopt/optimizer/slow_update.py does (drop only the marker) would do it.

Actual

# Project notes

<!-- SKILLOPT-SLEEP:LEARNED START -->
## Learned preferences & procedures

_This block is maintained by SkillOpt-Sleep. ..._

- Use ruff
<!-- SKILLOPT-SLEEP:LEARNED END -->

The user's section and the earlier learned item are gone. consolidate puts this document into proposed_CLAUDE.md, and adopting that proposal writes it over the live CLAUDE.md.

Environment

main at 45f65ca, Python 3.10, Windows 11.

Happy to send a fix if that helps.

1AbdullahButt avatar Nov 12 '26 12:11 1AbdullahButt