fix(session): honor toolChoice on max-mode's final step - #1871
Open
onlyfeng wants to merge 1 commit into
Open
Conversation
On the last step of a run, the main loop sets toolChoice: "none" so the model is forced to wrap up with text instead of proposing more tool calls. When max-mode is active, though, the step was unconditionally dispatched to MaxMode.runMaxStep instead of handle.process. runMaxStep's MaxStepInput.toolChoice field is intentionally unused (its own comment says so) since propose-only candidates and the judge don't care about it, and the winning candidate's tool calls are executed through handle.replay. As a result, a max-mode session could keep proposing and executing tool calls past its configured step budget. Gate the branch so the last step always falls back to handle.process, which does honor toolChoice, regardless of whether max-mode is otherwise enabled. Added a regression test that pins the "max" agent to a single step and enables max-mode with 2 candidates, then asserts only a single LLM call happens on that step (as handle.process would make) rather than the 3 calls (2 candidates + judge) max-mode would make if it incorrectly ran on the last step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toolChoice: "none"so the model is forced to wrap up with text instead of proposing more tool calls. When max-mode is active, the step was unconditionally dispatched toMaxMode.runMaxStepinstead ofhandle.process.runMaxStep'stoolChoicefield is intentionally unused, so a max-mode session could keep proposing and executing tool calls past its configured step budget.handle.process, which does honortoolChoice, regardless of whether max-mode is otherwise enabled.Test plan
bun typecheckpasses