diff --git a/agent/trajectory.py b/agent/trajectory.py index aa4dacf54f..4c8616d90d 100644 --- a/agent/trajectory.py +++ b/agent/trajectory.py @@ -39,8 +39,8 @@ def save_trajectory(trajectory: List[Dict[str, Any]], model: str, completed: boo if filename is None: filename = "trajectory_samples.jsonl" if completed else "failed_trajectories.jsonl" entry = {"conversations": trajectory, "timestamp": datetime.now().isoformat(), "model": model, "completed": completed} - line = json.dumps(entry, ensure_ascii=False) + "\n" try: + line = json.dumps(entry, ensure_ascii=False) + "\n" # serialize before taking the lock with open(filename, "a", encoding="utf-8") as f: # Gateway sessions and batch workers append to the SAME default file; without an # exclusive lock around write+flush, entries larger than one write() interleave and the