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.
This commit is contained in:
teknium1
2026-09-12 08:14:56 -07:00
committed by Teknium
parent 9c614484b3
commit 330004e597

View File

@@ -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