Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions agentrace/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def find_sessions(root: Path | None = None) -> list[Path]:


def _ts(value: str | None) -> datetime | None:
if not isinstance(value, str):
return None
if not value:
return None
try:
Expand Down
30 changes: 30 additions & 0 deletions tests/test_agentrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,36 @@ def test_non_agent_tools_are_ignored(tmp_path):
assert parse_session(p).runs == []


def test_non_string_timestamp_does_not_crash(tmp_path):
"""A numeric timestamp (malformed transcript) should not crash _ts."""
p = tmp_path / "s.jsonl"
p.write_text(
json.dumps({
"type": "assistant",
"timestamp": 1718000000,
"message": {
"content": [
{"type": "tool_use", "id": "t1", "name": "Agent", "input": {"prompt": "go"}}
]
},
})
+ "\n"
+ json.dumps({
"type": "user",
"timestamp": 1718000600,
"message": {
"content": [
{"type": "tool_result", "tool_use_id": "t1", "content": "done"}
]
},
})
)
s = parse_session(p)
assert len(s.runs) == 1
assert s.runs[0].started_at is None
assert s.runs[0].ended_at is None


def test_tool_use_without_id_is_skipped(tmp_path):
"""A tool_use block missing an id should be skipped rather than crashing with KeyError."""
p = tmp_path / "s.jsonl"
Expand Down
Loading