Skip to content

Comments

fix: AutoGen 'No next batch available' when next batch is ready#659

Merged
ChuxiJ merged 1 commit intomainfrom
fix/autogen-next-batch-stale-total-batches
Feb 21, 2026
Merged

fix: AutoGen 'No next batch available' when next batch is ready#659
ChuxiJ merged 1 commit intomainfrom
fix/autogen-next-batch-stale-total-batches

Conversation

@ChuxiJ
Copy link
Contributor

@ChuxiJ ChuxiJ commented Feb 21, 2026

navigate_to_next_batch relied on a stale total_batches Gradio state to decide whether a next batch exists. The background generator updates total_batches after navigate_to_next_batch runs in the .then() chain, so the guard check blocked valid navigation.

Changes:

  • batch_navigation.py: derive total_batches from batch_queue length (mirrors navigate_to_previous_batch which already did this).
  • batch_management.py: fix early-return path in generate_next_batch_background to update total_batches when the next batch was already completed.
  • batch_navigation_test.py: add 3 focused unit tests.

Summary by CodeRabbit

  • Bug Fixes

    • Improved batch tracking to ensure completed batches are reflected accurately without delay
    • Enhanced batch navigation to safely handle asynchronous queue updates and prevent reliance on outdated batch counts
  • Tests

    • Added comprehensive unit tests for batch navigation, covering edge cases with stale batch counts and missing batches

navigate_to_next_batch relied on a stale total_batches Gradio state
to decide whether a next batch exists. The background generator
updates total_batches *after* navigate_to_next_batch runs in the
.then() chain, so the guard check blocked valid navigation.

Changes:
- batch_navigation.py: derive total_batches from batch_queue length
  (mirrors navigate_to_previous_batch which already did this).
- batch_management.py: fix early-return path in
  generate_next_batch_background to update total_batches when the
  next batch was already completed.
- batch_navigation_test.py: add 3 focused unit tests.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

📝 Walkthrough

Walkthrough

The changes introduce defensive updates to batch management and navigation functions to handle stale total_batches values. When new completed batches are observed in the queue, total_batches is updated accordingly. New tests validate the stale total_batches scenario and existing guard logic.

Changes

Cohort / File(s) Summary
Batch State Management
acestep/ui/gradio/events/results/batch_management.py, acestep/ui/gradio/events/results/batch_navigation.py
Adds defensive logic to update total_batches when completed batches are discovered in the queue. batch_management.py ensures total_batches reflects newly observed completed batches; batch_navigation.py computes total_batches as the maximum of the provided value and current queue length to prevent reliance on stale values.
Test Coverage
acestep/ui/gradio/events/results/batch_navigation_test.py
New unit test module for batch navigation logic, covering stale total_batches scenarios, last-batch detection, and missing batch handling. Tests validate defensive guard logic using mocked Gradio helpers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hops with glee through batches bright,
No stale counts shall block our sight!
Queue's true length now takes the floor,
Navigation runs forevermore! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main issue (stale total_batches causing false 'No next batch available' error) and the fix (handling ready next batches), accurately reflecting the primary changes across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/autogen-next-batch-stale-total-batches

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
acestep/ui/gradio/events/results/batch_navigation_test.py (1)

28-36: Consider renaming kw to _kw or **_ to signal intentional discard.

The **kw in the lambda is necessary to accept keyword arguments (e.g., n=new_idx + 1) passed to t(), but since it's unused in the return value, prefixing with _ makes the intent clearer and silences the linter.

♻️ Suggested fix
-@patch("acestep.ui.gradio.events.results.batch_navigation.t", side_effect=lambda key, **kw: key)
+@patch("acestep.ui.gradio.events.results.batch_navigation.t", side_effect=lambda key, **_kw: key)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@acestep/ui/gradio/events/results/batch_navigation_test.py` around lines 28 -
36, Rename the unused lambda keyword-args parameter in the patch on t() to
indicate intentional discard: change the side_effect lambda in the `@patch` on
"acestep.ui.gradio.events.results.batch_navigation.t" from "lambda key, **kw:
key" to use a prefixed/underscore parameter like "lambda key, **_kw: key" (or
"**_:") so the intent is clear to readers and linters; keep the rest of
NavigateToNextBatchTests and its helper _run_first_yield unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@acestep/ui/gradio/events/results/batch_navigation_test.py`:
- Around line 28-36: Rename the unused lambda keyword-args parameter in the
patch on t() to indicate intentional discard: change the side_effect lambda in
the `@patch` on "acestep.ui.gradio.events.results.batch_navigation.t" from "lambda
key, **kw: key" to use a prefixed/underscore parameter like "lambda key, **_kw:
key" (or "**_:") so the intent is clear to readers and linters; keep the rest of
NavigateToNextBatchTests and its helper _run_first_yield unchanged.

@ChuxiJ ChuxiJ merged commit 8cc86cb into main Feb 21, 2026
3 checks passed
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.

1 participant