Skip to content
Open
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
11 changes: 8 additions & 3 deletions batch_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def _process_batch_worker(args: Tuple) -> Dict[str, Any]:
batch_tool_stats = {}
batch_reasoning_stats = {"total_assistant_turns": 0, "turns_with_reasoning": 0, "turns_without_reasoning": 0}
completed_in_batch = []
batch_results_to_write = []
discarded_no_reasoning = 0

# Process each prompt sequentially in this batch
Expand Down Expand Up @@ -469,9 +470,8 @@ def _process_batch_worker(args: Tuple) -> Dict[str, Any]:
"tool_error_counts": tool_error_counts # Simple: {tool: failure_count} - normalized
}

# Append to batch output file
with open(batch_output_file, 'a', encoding='utf-8') as f:
f.write(json.dumps(trajectory_entry, ensure_ascii=False) + "\n")
# Accumulate results in memory instead of writing to disk every time
batch_results_to_write.append(trajectory_entry)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trajectory_entry is only assigned in the successful-result guard above. A failed first prompt raises UnboundLocalError here; after a prior success, this appends that prior entry again. Keep this append inside the guard.


# Aggregate tool statistics
for tool_name, stats in result.get("tool_stats", {}).items():
Expand All @@ -498,6 +498,11 @@ def _process_batch_worker(args: Tuple) -> Dict[str, Any]:
else:
print(f" ❌ Prompt {prompt_index} failed (will retry on resume)")

# Write all accumulated results to disk in a single I/O operation
if batch_results_to_write:
with open(batch_output_file, 'a', encoding='utf-8') as f:
for entry in batch_results_to_write:
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
print(f"βœ… Batch {batch_num}: Completed ({len(prompts_to_process)} prompts processed)")

return {
Expand Down