Skip to content

fix(batch): wait for first non-None result - #1069

Closed
KXHXK wants to merge 1 commit into
langroid:mainfrom
KXHXK:fix/batch-wait-for-valid-result
Closed

KXHXK wants to merge 1 commit into
langroid:mainfrom
KXHXK:fix/batch-wait-for-valid-result

Conversation

@KXHXK

@KXHXK KXHXK commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep waiting when the first completed batch task maps to None
  • stop once a non-None result is available, preserving its original input position
  • cancel only the tasks that are still pending at that point
  • add a deterministic event-based regression test

Root cause

The stop_on_first_result branch called asyncio.wait(..., FIRST_COMPLETED) only once. Its finally block then cancelled every pending task even when all completed tasks had produced None, contrary to the documented behavior of continuing until a valid result is obtained.

The branch now waits repeatedly on the remaining task set. Existing exception handling and cleanup stay in the same paths.

Fixes #1068

Validation

  • pytest tests/main/test_batch.py -k "process_batch_async" -q (9 passed)
  • ruff check langroid/agent/batch.py tests/main/test_batch.py
  • git diff --check

@pchalasani

Copy link
Copy Markdown
Contributor

Thanks a lot for this, @KXHXK — clean diagnosis in #1068 and a correct fix. I've taken it forward in #1072, which keeps your commit and authorship and adds some hardening on top: a deterministic version of your regression test (the valid task is now released from inside output_map, so it can't race into the first asyncio.wait round), an all-None termination test, a test for the exception path under RETURN_NONE, precise stop_on_first_result docstrings on the public batch helpers, and a new docs/notes/batch-processing.md.

Closing this one in favor of #1072 — the fix and the credit are yours. Much appreciated!

@pchalasani pchalasani closed this Jul 25, 2026
pchalasani added a commit that referenced this pull request Jul 25, 2026
…esult (#1072)

* fix(batch): wait for first non-None result when stop_on_first_result

Original work from PR #1069 (fixes #1068).

* fix: address review findings

* docs+test: document stop_on_first_result semantics; cover exception path

* docs: clarify stop_on_first_result with RETURN_EXCEPTION

* docs: add batch processing note covering stop_on_first_result

* docs: correct run_batch_tasks exception-handling note

---------

Co-authored-by: KXH <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stop_on_first_result cancels pending tasks after a None result

2 participants