Skip to content

perf: optimize disk I/O by batching writes in _process_batch_worker - #13701

Open
EMREYSLCY wants to merge 1 commit into
NousResearch:mainfrom
EMREYSLCY:perf/optimize-disk-io
Open

perf: optimize disk I/O by batching writes in _process_batch_worker#13701
EMREYSLCY wants to merge 1 commit into
NousResearch:mainfrom
EMREYSLCY:perf/optimize-disk-io

Conversation

@EMREYSLCY

Copy link
Copy Markdown

What does this PR do?

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for targeting repeated output-file opens in the batch worker.

Problems

  • batch_runner.py:474 on this PR appends trajectory_entry outside the if result["success"] and result["trajectory"] block that creates it at lines 441-471. A failed first prompt therefore raises UnboundLocalError; a failure after a success appends the prior entry again.
  • The PR changes no tests. The current worker test at tests/test_batch_runner_checkpoint.py:160-186 covers a successful no-reasoning discard, not a failed prompt in this path.

Suggested changes

  • Keep the append inside the successful-trajectory block.
  • Add a regression test with failed and successful worker results, asserting only successful entries are written.

Automated hermes-sweeper review.

Comment thread batch_runner.py
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
Contributor

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.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants