Skip to content

fix(sleep): read the first JSON value from a chatty CLI reply - #456

Open
Lenin Mookiah (leninworld) wants to merge 1 commit into
microsoft:mainfrom
leninworld:fix-sleep-extract-json-chatty-455
Open

Lenin Mookiah (leninworld) wants to merge 1 commit into
microsoft:mainfrom
leninworld:fix-sleep-extract-json-chatty-455

Conversation

@leninworld

Copy link
Copy Markdown

Summary

_extract_json in skillopt_sleep/backend.py says it pulls the first JSON object or array out of a chatty CLI reply, but it matched a greedy \{.*\} / \[.*\] span from the first opening delimiter to the last closing one. Any other brace or bracket around the JSON (a judge restating {score, reason}, a trailing See [1]) made that span invalid, so the reply parsed as None. The judge then scored judge-parse-failed (0), and reflect, the LLM miner, rollout reflection and the slow update got no edits or tasks.

Changes

  • _extract_json tries each { (or [) left to right with json.JSONDecoder().raw_decode and returns the first value that decodes, or None. Whenever the old greedy span decoded, that value starts at the first opener, so replies that parsed before give the same result. It catches ValueError and RecursionError, so a reply that returned None before can't raise now.
  • CHANGELOG.md: entry under Fixed.

Tests

New tests/test_sleep_extract_json.py:

  • an object after prose that contains braces
  • an array followed by prose that contains brackets

Both fail on main (they get None) and pass with the fix. Full suite: 2418 passed, 23 skipped, 4 xfailed, plus 2 failures in tests/test_sleep_adopt_skill_subset.py (the tampered-manifest tests). Those 2 fail the same way on main on this machine (macOS, Python 3.12) and are unrelated. ruff check passes on the new test file. It reports nothing in the changed function; the 7 findings elsewhere in backend.py are already on main.

Fixes #455

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 _extract_json returns None when a CLI reply has other braces or brackets around the JSON

1 participant