Skip to content

trace: skip JSON lines that are not objects when reading a transcript - #150

Merged
SakshamUboweja merged 1 commit into
microsoft:mainfrom
kvishalv:fix-non-object-transcript-records
Nov 6, 2026
Merged

SakshamUboweja merged 1 commit into
microsoft:mainfrom
kvishalv:fix-non-object-transcript-records

Conversation

@kvishalv

Copy link
Copy Markdown
Contributor

A transcript reader parses each line with json.loads and calls .get on the result. A line that is valid JSON but not an object (null, 42, "text", []) has no .get, so the reader raises AttributeError, and one such line discards the whole transcript. For example, load_trajectory on a log with a null line between two tool calls raises instead of returning the two calls.

The readers in opencode.py and the other Claude readers already check isinstance(ev, dict). This PR adds the same check to the 13 places that miss it: claude_calls, claude_session_usage, the 5 Codex readers, copilot_event_calls, copilot_session_cwd, both tool-catalog parsers, the loop guard's completed_calls and the Codex capability audit inspect_usage. A non-object line is skipped, and the valid lines around it read as before. The check covers the top-level record only, not nested fields.

This is #40 and #41 by 1aifanatic, which were closed with the other ungrouped submissions. The fix is the same idea as #41. I left out microskills/distiller.py (load_calls), which has the same gap, because #134 and #141 change that file. I can add it after they land.

The tests are in the existing tests/test_trace.py. Each of the 5 tests puts 4 non-object lines before and after valid records and checks that the result equals the result for the valid records alone. One array line holds every marker string that a reader checks before it parses, so each reader reaches json.loads with a non-object line.

How it was produced: Claude Code, an AI coding agent, found the bug by reading the readers after #132 and wrote the fix and the tests. I directed the work and ran the checks below.

What was verified, on macOS with Python 3.12.0, on main at 519c65f:

Risk: a non-object line was never a record, so skipping it cannot change a result that was correct before. It only stops an exception.

A transcript reader calls .get on whatever json.loads returns. A line that
is valid JSON but not an object (null, 42, "text", []) has no .get, so the
reader raised AttributeError and one such line discarded the whole log.
Check isinstance(ev, dict) after parsing and skip the line, as opencode.py
and the other Claude readers already do. This covers claude_calls,
claude_session_usage, the Codex rollout and exec readers, the Copilot
readers, both tool-catalog parsers, the loop guard's completed_calls and
the Codex capability audit.

Follows microsoft#40 and microsoft#41 by 1aifanatic.
@SakshamUboweja
SakshamUboweja merged commit baba1b6 into microsoft:main Nov 6, 2026
10 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

Development

Successfully merging this pull request may close these issues.

2 participants