Skip to content

Conversation

@abhipatel12
Copy link
Collaborator

Summary

Extracts the scheduler state (active calls, queue, completed batch) from CoreToolScheduler into a dedicated SchedulerStateManager. This modularizes state management and simplifies the scheduler's logic, serving as a foundation for the Phase 2 asynchronous orchestrator.

Details

  • State Extraction: Created SchedulerStateManager to encapsulate all tool call data structures and status transitions, removing the complex setStatusInternal and setArgsInternal methods from the scheduler.
  • Fix for Live Output: Implemented robust property merging in the executing state to prevent data loss for live output streaming and PID updates (discovered during internal review).
  • Standardized Finalization: Introduced an explicit finalizeCall step to archive terminal calls into the completed batch after post-processing (like logging).
  • Improved Testability: Added comprehensive unit tests for SchedulerStateManager and updated existing scheduler tests to be resilient to more granular state updates.

Related Issues

Works towards resolving issue #14306.

How to Validate

  1. Build: Run npm run build to ensure type safety.
  2. Unit Tests: Run npx vitest packages/core/src/scheduler/state-manager.test.ts.
  3. Integration Tests: Run npx vitest packages/core/src/core/coreToolScheduler.test.ts.
  4. UI Hook Tests: Run npx vitest packages/cli/src/ui/hooks/useToolScheduler.test.ts.
  5. E2E Tests: Run npx vitest packages/a2a-server/src/http/app.test.ts.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx

…ansitions

- Extracted scheduler state (active calls, queue, completed batch) into a dedicated SchedulerStateManager class.
- Simplified CoreToolScheduler by delegating state manipulations and status transitions to the manager.
- Standardized terminal call finalization and archiving logic.
- Updated CoreToolScheduler and useReactToolScheduler tests to be more resilient to granular state updates.
- Refactored a2a-server E2E tests to use robust event matching instead of fragile array indices.
- Added comprehensive unit tests for SchedulerStateManager.
@abhipatel12 abhipatel12 requested a review from a team as a code owner January 8, 2026 05:20
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @abhipatel12, 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 CoreToolScheduler by extracting its state management responsibilities into a new, dedicated SchedulerStateManager class. This change modularizes the scheduler's internal logic, making it cleaner, more maintainable, and easier to reason about. By centralizing how tool call states are tracked and transitioned, the PR lays a crucial foundation for future asynchronous orchestration improvements, while also addressing specific issues like live output data integrity and enhancing overall testability.

Highlights

  • State Management Extraction: The core logic for managing tool call states (active, queued, completed) has been moved from CoreToolScheduler into a new dedicated class, SchedulerStateManager.
  • Modularized State Transitions: Complex setStatusInternal and setArgsInternal methods in CoreToolScheduler have been replaced by calls to the SchedulerStateManager, centralizing and simplifying state updates.
  • Live Output Data Preservation: A fix was implemented to ensure robust property merging during the executing state, preventing data loss for live output streaming and process ID updates.
  • Standardized Call Finalization: An explicit finalizeCall step was introduced in the SchedulerStateManager to consistently archive terminal tool calls into the completed batch after any necessary post-processing.
  • Enhanced Testability: Comprehensive unit tests have been added for the new SchedulerStateManager, and existing scheduler tests were updated to be more resilient to the new granular state update mechanisms.
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 introduces a significant and valuable refactoring by extracting the scheduler's state management logic from CoreToolScheduler into a new, dedicated SchedulerStateManager class. This change greatly improves modularity, separation of concerns, and testability. The new SchedulerStateManager is well-designed and is accompanied by a comprehensive test suite. The updates to existing tests make them more robust and resilient to the more granular, asynchronous state updates from the new architecture. Overall, this is an excellent improvement.

I've identified two high-severity issues where errors during tool modification are silently ignored, which could lead to unexpected behavior. These comments have been retained as they do not contradict any existing rules.

Comment on lines +562 to +568
if (!(invocationOrError instanceof Error)) {
this.state.updateArgs(
callId,
result.updatedParams,
invocationOrError,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There's a potential issue here where an error from buildInvocation is silently ignored. If result.updatedParams are invalid, buildInvocation will return an Error. The current logic will not update the invocation but will proceed to update the status to awaiting_approval with a new diff. This can lead to a confusing state where the user sees a diff for a change that is invalid, and if they approve, the tool might execute with the old, stale parameters. The tool call should be transitioned to an 'error' state instead.

        if (invocationOrError instanceof Error) {
          this.state.updateStatus(
            callId,
            'error',
            createErrorResponse(
              waitingToolCall.request,
              invocationOrError,
              ToolErrorType.INVALID_TOOL_PARAMS,
            ),
          );
          await this.checkAndNotifyCompletion(signal);
          return;
        }
        this.state.updateArgs(
          callId,
          result.updatedParams,
          invocationOrError,
        );

Comment on lines +594 to +600
if (!(invocationOrError instanceof Error)) {
this.state.updateArgs(
callId,
result.updatedParams,
invocationOrError,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to a previous comment, an error from buildInvocation is silently ignored here. If the newContent from the payload results in invalid parameters, buildInvocation returns an Error, but the tool call is not transitioned to an error state. This could lead to the tool executing with stale parameters if the user re-confirms. The tool call should be moved to an 'error' state to reflect the invalid modification.

          if (invocationOrError instanceof Error) {
            this.state.updateStatus(
              callId,
              'error',
              createErrorResponse(
                (toolCall as WaitingToolCall).request,
                invocationOrError,
                ToolErrorType.INVALID_TOOL_PARAMS,
              ),
            );
            await this.checkAndNotifyCompletion(signal);
            return;
          }
          this.state.updateArgs(
            callId,
            result.updatedParams,
            invocationOrError,
          );

@gemini-cli gemini-cli bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Jan 8, 2026
Base automatically changed from abhi/extract-tool-mod to main January 8, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant