fix(core): enforce maxSubtasks limit in createPlan and reviseCurrentPlan #656
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| "Cannot create plan: the number of subtasks (%d) exceeds the maximum" | ||
| + " limit of %d. Please reduce the number of subtasks.", |
There was a problem hiding this comment.
For improved readability and maintainability, it's better to define this long string on a single line rather than concatenating it across multiple lines.
| "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.", |
| "Cannot add more subtasks: the current plan has reached the" | ||
| + " maximum limit of %d subtasks. Please delete some" | ||
| + " existing subtasks first.", |
There was a problem hiding this comment.
For better readability, this multi-line string concatenation can be simplified into a single line.
| "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.", |
There was a problem hiding this comment.
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 againstmaxSubtasksand return a descriptive error message when the limit is exceeded, without creating or replacing the current plan. - In
reviseCurrentPlan(foraction="add"), prevent adding new subtasks when the current plan has already reachedmaxSubtasks, returning a clear limit-reached message instead. - Keep existing behavior unchanged when
maxSubtasksisnull, maintaining the “unlimited subtasks” configuration.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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)); | ||
| } |
There was a problem hiding this comment.
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.
| 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)); |
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@LearningGp PTAL |
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:
reject adding subtasks when the current plan has reached the limit
Testing:
Checklist