From 330004e59797c8ebe6c752007b046673d19ec25b Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sat, 12 Sep 2026 08:14:56 -0700 Subject: [PATCH] fix(agent): keep trajectory serialization inside the best-effort handler A non-JSON value used to log 'Failed to save trajectory' and return; moving json.dumps above the try made it raise to the caller. --- agent/trajectory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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