Skip to content

fix(sleep): don't write the same learned item twice on replace - #442

Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix/sleep-replace-duplicate-lines
Open

Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix/sleep-replace-duplicate-lines

Conversation

@Shizoqua

Copy link
Copy Markdown
Contributor

Summary

apply_edits_detailed in skillopt_sleep/memory.py skips an add whose item is already in the learned block, but replace wrote its replacement once for every line the anchor matched and never checked the other lines. A replacement equal to an existing item, or an anchor that matched several items, left duplicate bullets in the block.

Changes

  • replace now writes the replacement once, at the first matching line. Later matching lines are dropped, and so is the matching line itself when an unmatched line already holds the replacement.
  • A replace that changes nothing (no anchor match, or a replacement equal to the single line it matches) is still reported in unmatched. Duplicates that were already in an older block are left alone.
  • An empty replacement still removes the matched lines, as before.
  • CHANGELOG.md: entry under Fixed.

Tests

New tests/test_learned_replace_dedup.py:

  • a replacement that already exists in the block is not duplicated, and the edit is reported as applied
  • an anchor matching several items writes the replacement once and keeps the unmatched item
  • a replace whose anchor matches nothing is still unmatched and leaves the block as it was

The first two fail on main and pass with the fix. tests/test_learned_block_roundtrip.py passes unchanged. Full suite: 2397 passed, 12 skipped, 4 xfailed. ruff check passes on the changed files.

Fixes #441

apply_edits_detailed skips an add whose item is already in the learned
block, but replace wrote its replacement once per line the anchor
matched and never checked the other lines. A replacement equal to an
existing item, or an anchor that matched several items, left duplicate
bullets in the block.

Place the replacement once, at the first matching line, and drop it
when an unmatched line already holds it. A replace that changes
nothing is still reported as unmatched.

This branch has not been deployed

No deployments
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.

SkillOpt-Sleep replace edit can write the same learned item twice

1 participant