Skip to content

refactor: separate staleness control from workflow execution#444

Merged
rchardx merged 11 commits intomainfrom
fw/rollout-controller
Oct 20, 2025
Merged

refactor: separate staleness control from workflow execution#444
rchardx merged 11 commits intomainfrom
fw/rollout-controller

Conversation

@garrett4wade
Copy link
Collaborator

@garrett4wade garrett4wade commented Oct 13, 2025

Major Change

  1. Distilling the capacity and staleness control logic during rollout into areal/core/staleness_manager.py, which will be adopted by WorkflowExecutor. The implemented StalenessManager is a fully independent component that can be used in both the SPMD mode and in the single-controller mode. The main aim of this PR is to let the future implementation of single-controller mode easier.
  2. File structure change: StalenessManager is placed at areal/core/staleness_manager.py. Preparing to move WorkflowExecutor from areal/api/workflow_api.py to areal/core/workflow_executor, which will be done in the next PR.

Additional Comments

The preivous unit-tests regarding staleness control all pass. This PR should not affect any practical usage.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @garrett4wade, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the staleness and capacity control mechanisms within the system. By isolating this logic into a dedicated StalenessController component, the codebase becomes more modular and prepares the groundwork for easier implementation of future features, such as a single-controller mode. The WorkflowExecutor now leverages this new controller for managing rollouts, ensuring that the system adheres to concurrency and staleness constraints without functional regressions, as confirmed by existing and new unit tests.

Highlights

  • Staleness Control Refactoring: The core logic for managing rollout capacity and staleness has been extracted from WorkflowExecutor into a new, independent StalenessController class.
  • New Component: StalenessController: A new file, areal/core/staleness_controller.py, introduces the StalenessController class, designed to be fully independent and usable in various operational modes (SPMD, single-controller).
  • WorkflowExecutor Integration: The WorkflowExecutor in areal/api/workflow_api.py has been refactored to delegate all staleness and capacity management to an instance of the new StalenessController.
  • Initialization Logic Relocation: The initialization of WorkflowExecutor instances within RemoteSGLangEngine and RemotevLLMEngine has been moved from their __init__ methods to their respective initialize methods.
  • Comprehensive Unit Tests: A new, extensive suite of unit tests for the StalenessController has been added in areal/tests/test_staleness_controller.py, covering various scenarios including thread safety and edge cases.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 effectively refactors the staleness and capacity control logic into a new, dedicated StalenessController class. This is a great improvement for modularity and prepares the codebase for future enhancements like a single-controller mode. The introduction of areal/core/staleness_controller.py with its own comprehensive unit tests in areal/tests/test_staleness_controller.py significantly improves the robustness and maintainability of this critical logic. The changes in WorkflowExecutor to delegate responsibility to the new controller are clean and simplify its implementation. My review includes a few minor suggestions to update docstrings to align with the new design, ensuring the code remains easy to understand.

@garrett4wade
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 is a well-executed refactoring that successfully separates staleness control logic into a new, dedicated StalenessManager class. This significantly improves modularity, clarity, and maintainability. The introduction of a comprehensive test suite for the new component is excellent and ensures its correctness and thread safety. The changes make the WorkflowExecutor cleaner and set a good foundation for future work. I've identified a potential bug in exception handling and a minor performance improvement, which are detailed in the comments.

@garrett4wade garrett4wade requested a review from fishcrap October 17, 2025 08:21
Copy link
Collaborator

@nuzant nuzant left a comment

Choose a reason for hiding this comment

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

LGTM

@garrett4wade
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 is an excellent refactoring effort that successfully separates the staleness control logic from the WorkflowExecutor into a new, dedicated StalenessManager class. This change significantly improves the code's modularity, clarity, and testability. The WorkflowExecutor is now much simpler, with the removal of manual lock management and state tracking for rollouts.

The new StalenessManager is well-designed, thread-safe, and its logic is clear. I particularly appreciate the comprehensive suite of unit tests that have been added for it, which covers various scenarios including concurrency and edge cases, providing strong confidence in its correctness.

I have one minor suggestion to improve the documentation clarity in the new StalenessManager. Overall, this is a high-quality contribution that improves the maintainability of the codebase.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Collaborator

@rchardx rchardx left a comment

Choose a reason for hiding this comment

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

LGTM!

@rchardx rchardx merged commit 2ab0169 into main Oct 20, 2025
1 of 4 checks passed
@rchardx rchardx deleted the fw/rollout-controller branch October 20, 2025 03:23
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.

3 participants