Skip to content

fix(microskills): guard parse_payload against wrongly-typed proposer fields - #198

Merged
Aaron Li (aaron-jx-li) merged 4 commits into
microsoft:mainfrom
TejasLamba2006:fix/parse-payload-type-guards
Nov 16, 2026
Merged

Aaron Li (aaron-jx-li) merged 4 commits into
microsoft:mainfrom
TejasLamba2006:fix/parse-payload-type-guards

Conversation

@TejasLamba2006

Copy link
Copy Markdown
Contributor

Summary

When the proposer returns wrongly-typed fields, parse_payload crashes instead of filtering them out, causing the session to stay pending and retry the proposer on every session start.

Changes

  • obj.get("extractors", []) returns None (not []) when the key exists with value null. Changed to obj.get("extractors") or []
  • Filter extractors with non-string pattern field
  • Filter facts with non-dict detector field
  • Guard _rx() against non-string input

Test plan

Inline verification:

parse_payload('{"extractors": null, "facts": []}')  # was TypeError, now ([], [])
parse_payload('{"extractors": [{"name": "x", "pattern": [1,2]}], "facts": []}')  # filters out
parse_payload('{"extractors": [], "facts": [{"id": "f1", "detector": "string"}]}')  # filters out
_rx(['a', 'b'])  # was TypeError, now None

Fixes #173

…fields

- Handle extractors/facts as null (not just missing key)
- Filter extractors with non-string pattern
- Filter facts with non-dict detector
- Guard _rx against non-string pattern input

Fixes microsoft#173

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read parse_payload and everything that consumes its output at the PR head (_admit_extractor, _admit, _ground, DetectorV3Scope). The three cases in #173 are covered: "extractors": null now yields [], a non-string pattern is filtered out, and _rx returns None for a non-string instead of raising.

The same reply can still abort the fold, because a field that is not hashable crashes later in admission:

  1. name or id that is a list or an object. _admit_extractor does spec["name"] in self.extractors (distiller.py:640), and _admit does fid not in self.facts (:689). With {"name": ["a"], "pattern": "x"} or {"id": ["f"], "detector": {}}, both raise TypeError: unhashable type: 'list'.
  2. detector.scope / detector.fired that is a list. DetectorV3Scope._lookup does name in self.features (:334) before it gets to the now-guarded _rx(name), so _ground raises the same TypeError.
  3. cite that is a number. for iid in (spec.get("cite") or []) (:657) raises 'int' object is not iterable.

I checked the membership and iteration errors with a standalone snippet (['a'] in {}, for i in (3 or []): pass), not by running the distiller.

Requiring isinstance(e.get("name"), str) and isinstance(f.get("id"), str) in parse_payload closes 1. For 2 and 3, the simplest fix is to drop a fact whose detector has a non-string scope/fired/confirm/contradict, or whose cite is not a list. A test with each malformed reply, like the repro in the issue, would also keep this from coming back.

Reviewed with help from Claude Code.

…d cite fields

A malformed proposer reply with a list or dict name or id crashed the
extractor and fact admission on an unhashable key, and non-string
detector fields crashed the feature lookup. Drop such entries in
parse_payload, and treat a non-list cite as no citations.
@TejasLamba2006

Copy link
Copy Markdown
Contributor Author

Thanks Muhammad Abdullah Butt (@1AbdullahButt), pushed 30e07e0: parse_payload now requires string name/id, string-or-null detector fields (scope, fired, confirm, contradict), and null-or-list cite, and _ground skips non-list cite or non-string cite entries. Added unit tests in tests/test_distiller_payload_types.py.

`obj.get(...) or []` still iterated a truthy value that is not a list, so
{"extractors": true} or {"facts": 7} raised TypeError out of parse_payload
and aborted the fold (microsoft#173). The isinstance checks had also replaced the
truthiness checks, so an empty pattern or detector got through, and an
empty detector, which never grounds, took one of the MAX_CANDS slots.

The id cases now carry a real detector, so they reproduce the
unhashable-id crash in _admit on main instead of being dropped for their
empty detector. A new test checks that empty detectors no longer crowd
out a valid fact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Aaron Li (aaron-jx-li) pushed a commit that referenced this pull request Nov 16, 2026
Same pattern as #180/#182: json.loads can return null/list/string,
and d.get("message") fails with AttributeError on non-dicts.

This is a separate fix from #198 (parse_payload guards) - load_calls
parses the transcript, parse_payload parses the proposer reply.
@aaron-jx-li
Aaron Li (aaron-jx-li) merged commit edde289 into microsoft:main Nov 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants