Skip to content

fix(sleep): skip transcript lines that are not readable JSON objects - #388

Merged
Yifan Yang (Yif-Yang) merged 2 commits into
microsoft:mainfrom
1AbdullahButt:fix/harvest-jsonl-bad-lines
Nov 10, 2026
Merged

Yifan Yang (Yif-Yang) merged 2 commits into
microsoft:mainfrom
1AbdullahButt:fix/harvest-jsonl-bad-lines

Conversation

@1AbdullahButt

Copy link
Copy Markdown
Contributor

Fixes #386

_iter_jsonl (used by the Claude Code, Codex and Cursor harvesters) skipped lines that failed json.loads. Two other kinds of bad line still got past it and aborted the whole harvest:

  • Cut mid-character. The file was decoded in text mode, outside the per-line try. A transcript that ends partway through a multi-byte character (for example, a session still being written) raised UnicodeDecodeError out of the generator, and nothing above it catches that.
  • Valid JSON, but not an object. null, [], "text" and 42 were yielded, and digest_transcript / digest_codex_archived_session then raised AttributeError on rec.get(...).

The fix reads the file as bytes, decodes each line on its own, and yields only dicts. That is what the Copilot reader (_read_jsonl_snapshot) already does. A bad line is now skipped like any other malformed line, and the rest of the session is still harvested.

Tests

  • New tests/test_harvest_malformed_lines.py covers a cut line and non-object lines for the Claude Code harvester, and both together for the Codex harvester. All 3 tests fail on main (UnicodeDecodeError / AttributeError) and pass with this change.
  • python -m pytest -q: All 3 new tests fail on main and pass here. Full suite on Linux (python:3.11-slim): 2077 passed; the same 11 tests fail on unmodified main in that container (Devin installer, run-sleep fallback, reproducibility CLI: environment-dependent, unrelated). On Windows the harvest and sleep-engine tests pass apart from failures that also occur on main.
  • No docs changed.

This change was written with Claude Code.

🤖 Generated with Claude Code

_iter_jsonl skipped lines that failed json.loads, but two kinds of bad
line still escaped it and aborted the whole harvest:

- The file was decoded in text mode outside the per-line try, so a
  transcript that ends partway through a multi-byte character (a session
  still being written) raised UnicodeDecodeError out of the generator.
- A line that is valid JSON but not an object (null, [], "text", 42) was
  yielded, and digest_transcript / digest_codex_archived_session then
  raised AttributeError on rec.get().

Read the file as bytes, decode each line on its own, and yield only
dicts, as the Copilot reader (_read_jsonl_snapshot) already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep both CHANGELOG entries; no other change.
@Yif-Yang
Yifan Yang (Yif-Yang) merged commit ac44b4d into microsoft:main Nov 10, 2026
@Yif-Yang

Copy link
Copy Markdown
Contributor

Merged, thank you. A transcript line that is cut mid-character, or that is valid JSON but not an object, is now skipped instead of aborting the whole harvest. On main, the new tests fail (3 failures) and pass here. Closes #386. Your branch and an earlier PR in this batch each added an entry at the same spot in CHANGELOG.md, so I pushed one maintainer merge commit to your branch that keeps both entries and changes nothing else, then merged.

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.

harvest: a transcript line cut mid-character, or a JSON line that is not an object, aborts the whole harvest

2 participants