Skip to content

[Misc] Strengthen batch execution with recovery-aware runtimes and atomic state updates - #2360

Merged
zhangjyr merged 13 commits into
vllm-project:mainfrom
zhangjyr:issues/batch_state_fixing
Jun 30, 2026
Merged

zhangjyr merged 13 commits into
vllm-project:mainfrom
zhangjyr:issues/batch_state_fixing

Conversation

@zhangjyr

@zhangjyr zhangjyr commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request Description

This PR reviews the abnormal test script (python/aibrix/tests/batch/test_e2e_abnormal_job_behavior.py) to systematically validate the batch system's robustness against accidental failure events.

What Changed

Batch manager and lifecycle handling

  • Refactors BatchManager to treat in-progress jobs as JobMetaInfo instead of raw BatchJob.
  • Adds clearer lifecycle/status methods such as:
    • mark_job_validated()
    • update_job_status()
    • update_job_local_status()
    • mark_job_finalizing()
    • conclude_job()
  • Improves handling for:
    • duplicate committed jobs
    • cancel/delete races
    • failure finalization
    • expiry of both pending and in-progress jobs
    • deferred deletion after terminal state

Driver / progress interface redesign

  • Moves RunningJobs out of batch.state into batch.job_driver .
  • Narrows the driver-facing protocol to explicit status/lifecycle operations.
  • Refactors BaseJobDriver to own:
    • job validation
    • execution-state resets
    • cancellation handling
    • failure normalization
    • recovery/finalization flow
    • worker-local progress persistence

Concurrent worker execution and status aggregation

  • Introduces worker-local status_copies plus aggregation into the persisted job status.
  • Adds durable execution metadata via JobRuntimeRef and BatchJobStatus.execution .
  • Aggregates:
    • request counts
    • token usage
    • worker-local state
  • Caps merged request counters using the largest seen request range to avoid overcounting during recovery/concurrent runs.

Runtime durability and reconnection

  • Extends runtime session handling to support:
    • persisted runtime refs
    • reconnect-before-reprovision
    • cleanup of recovered FINALIZING jobs
    • direct runtime termination on delete/cancel
  • Removes reliance on entity-manager delete hook hijacking for runtime cancellation.
  • Updates provisioning runtimes to publish reconnect metadata.

Kubernetes runtime changes

  • Kubernetes deployment runtime now supports reconnecting to previously provisioned resources.
  • KubernetesJob runtime now exposes runtime owner/reconnect metadata and simpler terminate handling.

Validation flow changes

  • Moves batch input validation out of the metadata API layer and into shared storage/driver code.
  • Adds shared validator in aibrix/batch/storage/input_validation.py .
  • create_batch() no longer precomputes request_count ; request totals are now validated and persisted during admission/driver validation, which removes the request counting overhead from API layer.

Scheduler behavior

  • Expiry now considers both:
    • pending jobs
    • in-progress jobs
  • Scheduler derives expiry directly from schedulable pools rather than a separate due-time structure.

Config updates

  • Moves AIBRIX_BATCH_JOB_POOL_SIZE handling into envs.py .
  • Adds fault-injection batch opts for testing:
    • fail_init_runtime
    • fail_preparation
  • Reduces default INFERENCE_TASK_TIMEOUT from 3600 to 600.

Test coverage

  • Adds or significantly updates batch-focused tests, including:
    • python/aibrix/tests/batch/test_base_job_driver.py
    • python/aibrix/tests/batch/test_batch_manager.py
    • python/aibrix/tests/batch/test_runtime.py
    • python/aibrix/tests/batch/test_k8s_deployment_runtime.py
    • python/aibrix/tests/batch/test_e2e_abnormal_job_behavior.py
    • python/aibrix/tests/batch/test_e2e_openai_batch_api.py

Impact

  • Batch execution is now more restart-safe and concurrency-aware.
  • Runtime-backed jobs can persist enough metadata to resume or clean up correctly after process restarts.
  • Validation is more centralized and reusable.
  • Cancellation, expiry, and finalization behavior is more explicit and less dependent on implicit side effects.

Contribution Guidelines (Expand for Details)

We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:

Pull Request Title Format

Your PR title should start with one of these prefixes to indicate the nature of the change:

  • [Bug]: Corrections to existing functionality
  • [CI]: Changes to build process or CI pipeline
  • [Docs]: Updates or additions to documentation
  • [API]: Modifications to aibrix's API or interface
  • [CLI]: Changes or additions to the Command Line Interface
  • [Misc]: For changes not covered above (use sparingly)

Note: For changes spanning multiple categories, use multiple prefixes in order of importance.

Submission Checklist

  • PR title includes appropriate prefix(es)
  • Changes are clearly explained in the PR description
  • New and existing tests pass successfully
  • Code adheres to project style and best practices
  • Documentation updated to reflect changes (if applicable)
  • Thorough testing completed, no regressions introduced

By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the batch job processing system in Aibrix, introducing job-bound driver instances, worker-local status tracking, and a new input validation module. It also improves local storage reliability through atomic file writes and enhances end-to-end test coverage. The review identified several critical issues that need to be addressed: an AttributeError in batch_manager.py due to assigning to read-only properties, a potential re-execution of completed requests in base.py, a NameError in batch_job.py from a missing copy import, file descriptor leaks in local.py during temporary file creation, and the loss of legacy options in k8s_transformer.py due to overwriting instead of merging.

Comment thread python/aibrix/aibrix/storage/local.py Resolved
@zhangjyr
zhangjyr force-pushed the issues/batch_state_fixing branch 2 times, most recently from c45e4c0 to ba0c326 Compare June 16, 2026 13:48
@zhangjyr
zhangjyr force-pushed the issues/batch_state_fixing branch 2 times, most recently from 565caa2 to 071d1b2 Compare June 25, 2026 18:35
@zhangjyr zhangjyr changed the title [Misc] Validated batch state transition. [Misc] Strengthen batch execution with recovery-aware runtimes and atomic state updates Jun 25, 2026
Jingyuan Zhang added 8 commits June 26, 2026 03:35
Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>
@zhangjyr
zhangjyr force-pushed the issues/batch_state_fixing branch from 8b812a1 to b97b3e4 Compare June 26, 2026 10:36
Jingyuan Zhang added 5 commits June 26, 2026 15:12
Add test case for cancellation during service discovery.

Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>
Signed-off-by: Jingyuan Zhang <[email protected]>

@DwyaneShi DwyaneShi left a comment

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.

The overall direction and the enhancements in this PR look reasonable to me. Given the scope of the changes, I didn't review all the details. I think it's fine to merge this as a first step and continue improving it.

@zhangjyr
zhangjyr merged commit 1120c10 into vllm-project:main Jun 30, 2026
13 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.

2 participants