Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ All notable changes to SkillOpt are documented here. This project adheres to
value is rejected with a clear error.

### Fixed
- **SkillOpt-Sleep keeps learned rules after a stray end marker.**
`extract_learned` read up to the first `LEARNED END` marker anywhere in the
document, so an END marker before the learned block made the block read as
empty and the next edit rewrote it without the adopted rules. It now reads to
the first END marker after the START marker. (thanks @leninworld)
- `scripts/train.py` accepts `--slow_update_gate_with_selection`. The config key
`optimizer.slow_update_gate_with_selection` exists, but the flag was never
added, so `--slow_update_gate_with_selection true` failed with an
Expand Down
2 changes: 1 addition & 1 deletion skillopt_sleep/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def extract_learned(doc: str) -> str:
s = doc.find(LEARNED_START)
e = doc.find(LEARNED_END)
e = doc.find(LEARNED_END, s + len(LEARNED_START))
if s == -1 or e == -1:
return ""
return doc[s + len(LEARNED_START):e].strip()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_learned_block_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def _add(content: str) -> EditRecord:
return EditRecord(target="skill", op="add", content=content)


def test_stray_end_before_learned_block_does_not_drop_adopted_rules() -> None:
doc = LEARNED_END + "\nstray\n" + set_learned(
"# Skill", ["Keep tests deterministic"]
)
assert current_learned_lines(doc) == ["Keep tests deterministic"]

new_doc, applied, unmatched = apply_edits_detailed(doc, [_add("Run ruff")])

assert len(applied) == 1 and unmatched == []
assert "Keep tests deterministic" in new_doc
assert current_learned_lines(new_doc) == [
"Keep tests deterministic",
"Run ruff",
]


def test_legacy_multi_line_item_survives_the_next_edit() -> None:
doc = _legacy_doc(
"Always run tests before committing",
Expand Down