Skip to content

sleep: match feedback phrases as whole words, so ordinary requests aren't mined as failures - #457

Open
Vidwaan Singhania (Vidwaansinghania) wants to merge 3 commits into
microsoft:mainfrom
Vidwaansinghania:sleep-feedback-whole-words
Open

Vidwaan Singhania (Vidwaansinghania) wants to merge 3 commits into
microsoft:mainfrom
Vidwaansinghania:sleep-feedback-whole-words

Conversation

@Vidwaansinghania

Copy link
Copy Markdown

What this changes

_detect_feedback in skillopt_sleep/harvest.py decides whether a user turn approves or rejects the agent's previous output. Every harvester (Claude Code, Codex, Copilot, Copilot CLI, Cursor, OpenCode, Pi) calls it, and heuristic_mine labels a task fail whenever any turn carries a negative signal. It matched phrases with a plain substring test (ph in text.lower()), so phrases fired inside unrelated words.

On current main:

User text Signals today After this PR
Can you play the piano, guitar, and drums in this demo? neg:no, none
Write a function that undoes the last migration neg:undo none
That's incorrect neg:incorrect, pos:correct neg:incorrect
Still not fixed neg:still not, neg:not fixed, pos:fixed neg:still not, neg:not fixed
Add a section on Venice, Italy pos:nice none
Rename the prefixed columns pos:fixed none
It didn’t work (curly apostrophe) none neg:didn't
no thanks, that's not great pos:thanks, pos:great none

The first row matters most. The opening request isn't feedback at all, but because "piano," contains "no,", the session's task is labelled fail and goes into replay and the held-out gate as a failure.

How

  1. Whole-word matching. Each phrase is compiled once (functools.lru_cache) as (?<!\w)<phrase>(?!\w). Lookarounds are used instead of \b because some phrases end in punctuation (no,). The phrase lists and the SKILLOPT_SLEEP_NEG_FEEDBACK / _POS_FEEDBACK env-var extensions are unchanged, and user phrases get the same treatment.
  2. Positives inside a negative don't count. Negative matches are blanked out before positive phrases are searched, so fixed inside not fixed no longer gives a positive signal as well.
  3. Negated positives don't count. A positive phrase directly after not, no, never, hardly or an n't word, with at most one word in between, is skipped (not great, no thanks, isn't correct, not really perfect). A positive after an unrelated clause still counts (Not what I pictured, but thanks → pos:thanks).
  4. Curly apostrophes. ’ is normalised to ' before matching, so didn’t and doesn’t work from macOS or mobile keyboards are detected.

The return type and the neg:<phrase> / pos:<phrase> format are unchanged, so callers and the LLM miner prompt are unaffected.

Tests

  • New tests/test_sleep_feedback_phrases.py (stdlib unittest, no network). It covers substring false positives for both lists, incorrect vs correct, positives inside negatives, negated positives, curly apostrophes, existing phrases that must still match, and one end-to-end check that heuristic_mine labels the "piano," request unknown instead of fail.
  • Full suite on Windows 11 / Python 3.13: 36 failures, the same 36 with and without this change (in test_sleep_config_encoding, test_sleep_staging_fanout, test_sleep_engine::test_cycle_stages_only_documents_that_changed, test_harvest_project_scope, test_reproducibility, test_openai_compatible_config, test_benchmark_task_output_paths). They look Windows-specific and are unrelated to this change. All the existing feedback-signal tests (test_sleep_engine, test_sleep_harvest_non_user_records, test_copilot_harvest, test_harvest_copilot_cli, test_harvest_opencode, test_harvest_pi) pass.

Not in this PR

Two related things are left for discussion, since they change behaviour more than a matching fix should:

  • The opening request is still scanned for feedback, even though it can't be a reaction to earlier output. Skipping the first user turn would touch every harvester.
  • heuristic_mine's docstring says "negative feedback present and no later positive → fail", but the code ignores order: any negative gives fail, even when a later turn says "perfect, thanks". Fixing that needs ordered signals, so it changes how feedback_signals is built.

Glad to follow up on either if you'd like them.

@Vidwaansinghania

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

1 participant