Skip to content

fix(microskills): skip non-dict JSON lines in load_calls - #199

Merged
Aaron Li (aaron-jx-li) merged 2 commits into
microsoft:mainfrom
TejasLamba2006:fix/load-calls-isinstance-check
Nov 16, 2026
Merged

Aaron Li (aaron-jx-li) merged 2 commits into
microsoft:mainfrom
TejasLamba2006:fix/load-calls-isinstance-check

Conversation

@TejasLamba2006

Copy link
Copy Markdown
Contributor

Summary

load_calls in distiller.py parses transcript JSONL files but doesn't guard against non-dict JSON lines. A line like null, [1,2], or "string" passes json.loads but fails on d.get("message") with AttributeError.

This is the same pattern fixed in #180 (cursor readers) and #182 (agent-output readers), applied to the transcript reader used by the proposer.

Changes

Added isinstance(d, dict) check after json.loads, before accessing dict methods.

Test plan

# Before fix: AttributeError: 'NoneType' object has no attribute 'get'
# After fix: returns [] and skips bad lines
load_calls("file_with_null_line.jsonl")

Separate from #198 which guards parse_payload (proposer reply) - this guards load_calls (transcript parsing).

Same pattern as microsoft#180/microsoft#182: json.loads can return null/list/string,
and d.get("message") fails with AttributeError on non-dicts.

This is a separate fix from microsoft#198 (parse_payload guards) - load_calls
parses the transcript, parse_payload parses the proposer reply.

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 load_calls at the PR head. The new isinstance(d, dict) check is in the right place: a null, list or string line is now skipped before d.get("message"), which is the same pattern #180 and #182 use.

The same loop still trusts the types one level down, so a hand-edited or truncated transcript can still raise here:

  • b.get("id") not in uses (distiller.py:93): an id that is a list or an object raises TypeError: unhashable type. res[b.get("tool_use_id")] = txt (:102) has the same problem.
  • uses[t][0].lower() (:103): b.get("name", "") returns None when the key is present with null, and that raises AttributeError: 'NoneType' object has no attribute 'lower'.
  • "\n".join(x.get("text", "") ...): a text that is not a string raises TypeError in join.

Something like bid = b.get("id"); if not isinstance(bid, str): continue, str(b.get("name") or "") and str(x.get("text") or "") would cover all three. The PR also has no test, and one with a null line, which is the case it fixes, would help.

Reviewed with help from Claude Code.

A tool_use or tool_result id that is not a string crashed the
unhashable lookup, a null or non-string tool name crashed lower(),
and a non-string text block crashed the join. Skip blocks with a
non-string id, default a non-string name to empty, drop a non-dict
input to empty args, and join only string text.
@TejasLamba2006

Copy link
Copy Markdown
Contributor Author

Thanks Muhammad Abdullah Butt (@1AbdullahButt), pushed c086241: load_calls now guards non-string id/tool_use_id, null/non-string name and text blocks, and non-dict input, with tests in tests/test_load_calls_malformed.py.

@aaron-jx-li
Aaron Li (aaron-jx-li) merged commit 6366ac4 into microsoft:main Nov 16, 2026
9 checks passed
Aaron Li (aaron-jx-li) pushed a commit that referenced this pull request Nov 16, 2026
…repos

store.read_lines can return non-dict JSON values (null, arrays, strings)
if a ledger file was corrupted or written incorrectly. Code calling .get()
on these records crashes with AttributeError.

Added isinstance(r, dict) checks before accessing record fields in:
- accounting.summarize (filters at entry)
- repos._infer_repo_from_state (inline check)
- repos._merge_state (filters ledger lists, inline check for events)

Same pattern as the distiller fix in #199.
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.

3 participants