Skip to content

fix(core): enforce maxSubtasks limit in createPlan and reviseCurrentPlan #656

Merged
AlbumenJ merged 4 commits intoagentscope-ai:mainfrom
JGoP-L:fix/maxSubtasks-parameter-now-works-correctly
Jan 26, 2026
Merged

fix(core): enforce maxSubtasks limit in createPlan and reviseCurrentPlan #656
AlbumenJ merged 4 commits intoagentscope-ai:mainfrom
JGoP-L:fix/maxSubtasks-parameter-now-works-correctly

Conversation

@JGoP-L
Copy link
Contributor

@JGoP-L JGoP-L commented Jan 25, 2026

AgentScope-Java Version

1.0.8-SNAPSHOT

Description

Fixes #631

The maxSubtasks parameter of PlanNotebook was not being enforced.
Users could set maxSubtasks(5) but still create plans with more than 5 subtasks or add unlimited subtasks via reviseCurrentPlan.

Changes:

  • Added validation in createPlan method to reject plan creation when subtask count exceeds maxSubtasks
  • Added validation in reviseCurrentPlan method (action="add") to
    reject adding subtasks when the current plan has reached the limit

Testing:

  • Created a plan with 6 subtasks when maxSubtasks=5 → correctly rejected
  • Created a plan with 5 subtasks when maxSubtasks=5 → correctly allowed
  • Added a subtask when plan already has 5 subtasks and maxSubtasks=5 → correctly rejected
  • Added a subtask when plan has 4 subtasks and maxSubtasks=5 → correctly allowed
  • Historical plan recovery and session load are not affected (by design)

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@JGoP-L JGoP-L requested review from a team and Copilot January 25, 2026 15:25
@gemini-code-assist
Copy link

Summary of Changes

Hello @JGoP-L, 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 addresses a critical bug where the maxSubtasks parameter in PlanNotebook was not being properly enforced. The changes introduce robust validation checks within both the createPlan and reviseCurrentPlan methods. This ensures that users cannot create plans with more subtasks than allowed or add additional subtasks beyond the specified maximum, thereby upholding the integrity of the plan structure and adhering to configured limits.

Highlights

  • Enforce maxSubtasks in createPlan: Added validation in the createPlan method to reject plan creation if the number of subtasks exceeds the configured maxSubtasks limit.
  • Enforce maxSubtasks in reviseCurrentPlan: Implemented validation in the reviseCurrentPlan method (specifically for the 'add' action) to prevent adding new subtasks if the current plan has already reached the maxSubtasks limit.
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

@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 correctly implements the maxSubtasks limit enforcement in createPlan and reviseCurrentPlan. The validation logic is sound and placed appropriately to prevent the creation of plans or addition of subtasks beyond the configured limit. My review includes a couple of suggestions to improve the readability of the error messages. Additionally, while manual testing was performed, I highly recommend adding automated unit tests to cover these new validation scenarios to safeguard against future regressions.

Comment on lines +311 to +312
"Cannot create plan: the number of subtasks (%d) exceeds the maximum"
+ " limit of %d. Please reduce the number of subtasks.",

Choose a reason for hiding this comment

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

medium

For improved readability and maintainability, it's better to define this long string on a single line rather than concatenating it across multiple lines.

Suggested change
"Cannot create plan: the number of subtasks (%d) exceeds the maximum"
+ " limit of %d. Please reduce the number of subtasks.",
"Cannot create plan: the number of subtasks (%d) exceeds the maximum limit of %d. Please reduce the number of subtasks.",

Comment on lines +517 to +519
"Cannot add more subtasks: the current plan has reached the"
+ " maximum limit of %d subtasks. Please delete some"
+ " existing subtasks first.",

Choose a reason for hiding this comment

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

medium

For better readability, this multi-line string concatenation can be simplified into a single line.

Suggested change
"Cannot add more subtasks: the current plan has reached the"
+ " maximum limit of %d subtasks. Please delete some"
+ " existing subtasks first.",
"Cannot add more subtasks: the current plan has reached the maximum limit of %d subtasks. Please delete some existing subtasks first.",

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the bug where the PlanNotebook.maxSubtasks configuration was not actually enforced, allowing plans to exceed the configured subtask limit. It adds validation to both plan creation and incremental plan revision so the maximum subtask count is consistently respected.

Changes:

  • In createPlan, validate the number of requested subtasks against maxSubtasks and return a descriptive error message when the limit is exceeded, without creating or replacing the current plan.
  • In reviseCurrentPlan (for action="add"), prevent adding new subtasks when the current plan has already reached maxSubtasks, returning a clear limit-reached message instead.
  • Keep existing behavior unchanged when maxSubtasks is null, maintaining the “unlimited subtasks” configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +308 to +314
if (maxSubtasks != null && subtaskList.size() > maxSubtasks) {
return Mono.just(
String.format(
"Cannot create plan: the number of subtasks (%d) exceeds the maximum"
+ " limit of %d. Please reduce the number of subtasks.",
subtaskList.size(), maxSubtasks));
}
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

The new maxSubtasks validation path in createPlan (when subtaskList.size() > maxSubtasks) is not covered by tests, even though PlanNotebookToolTest already exercises createPlanWithSubTasks and related tool flows. Please add tests that configure a PlanNotebook with a finite maxSubtasks value and verify that creating a plan with more subtasks than allowed returns the expected error message and does not set currentPlan or trigger plan change side effects.

Copilot uses AI. Check for mistakes.
Comment on lines +514 to +520
if (maxSubtasks != null && subtasks.size() >= maxSubtasks) {
return Mono.just(
String.format(
"Cannot add more subtasks: the current plan has reached the"
+ " maximum limit of %d subtasks. Please delete some"
+ " existing subtasks first.",
maxSubtasks));
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

The new maxSubtasks guard in reviseCurrentPlan for action "add" (rejecting additions when subtasks.size() >= maxSubtasks) is not currently exercised by automated tests, while other PlanNotebook tool behaviors are covered in PlanNotebookToolTest. To prevent regressions for this bugfix, consider adding tests that: (1) create a plan at the subtask limit and verify that an "add" action returns the new limit-reached message and leaves the subtask list unchanged, and (2) confirm that adding a subtask is still allowed just below the limit.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ain/java/io/agentscope/core/plan/PlanNotebook.java 85.71% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AlbumenJ
Copy link
Collaborator

@LearningGp PTAL

@AlbumenJ AlbumenJ merged commit 42b3b0b into agentscope-ai:main Jan 26, 2026
5 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.

[Bug]: the maxSubtasks param of PlanNoteBook doesn't work

2 participants