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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user