Repository navigation
fix(sleep): read the learned block up to its own END marker - #480
Open
Lenin Mookiah (leninworld) wants to merge 1 commit into
Open
Lenin Mookiah (leninworld) wants to merge 1 commit into
Lenin Mookiah (leninworld) wants to merge 1 commit into
Conversation
extract_learned searched for the first LEARNED END marker anywhere in the document. A stray END before the learned block made the block read as empty, and the next edit rewrote it without the adopted rules. Search for END after the START marker, as _strip_learned already does. Fixes microsoft#479
This branch has not been deployed
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.
This PR fixes issue #479.
Summary
extract_learnedinskillopt_sleep/memory.pyread up to the firstLEARNED ENDmarker anywhere in the document, not the first one after the START marker. A stray END before the learned block (left by a merge conflict or a hand edit) made the block read as empty:current_learned_lines()returned[], and the next edit rewrote the block without the rules that were already adopted, while reporting the edit as applied.consolidateputs that document into the proposal, so adopting it drops those rules from the live file.This is the mirror of the orphan START case fixed in #414 (#412).
_strip_learnedalready searches for END after START.Changes
extract_learnedsearches for the END marker after the START marker it found:doc.find(LEARNED_END, s + len(LEARNED_START)). A document with no START, or a START with no END after it, still reads as no learned items, as before.CHANGELOG.md: entry under[Unreleased]→Fixed.The stray END itself stays where it was, outside the block, like any other text of the user's.
Tests
New
test_stray_end_before_learned_block_does_not_drop_adopted_rulesintests/test_learned_block_roundtrip.py(the reproduction from the issue): the adopted rule is read back, and after anaddedit both the old rule and the new one are in the block. It fails on main (current_learned_lines(doc)is[]) and passes with the fix.python -m pytest -q tests/test_learned_block_roundtrip.py→ 8 passed.python -m pytest -q→ 2617 passed, 23 skipped, 4 xfailed, 2 failed. The 2 failures are the tampered-manifest tests intests/test_sleep_adopt_skill_subset.py, which fail the same way on main on this machine (macOS, Python 3.11).ruff check skillopt_sleep/memory.py tests/test_learned_block_roundtrip.py→ all checks passed.Not changed here (same pattern, separate if you want them):
extract_slow_update_fieldinskillopt/optimizer/slow_update.pyandextract_slow_fieldinskillopt_sleep/slow_update.pyalso read to the first END marker anywhere.Fixes #479