fix: prevent infinite loop with self-referencing handoffs in Autopilot mode (#325128)#325145
Open
AmariahAK wants to merge 2 commits into
Open
fix: prevent infinite loop with self-referencing handoffs in Autopilot mode (#325128)#325145AmariahAK wants to merge 2 commits into
AmariahAK wants to merge 2 commits into
Conversation
…t mode In Autopilot mode, a custom agent with handoffs that have send:true pointing to the same agent creates an infinite loop. Each response auto-triggers a handoff back to itself, which produces the same response again. The fix adds a guard in renderChatSuggestNextWidget() to skip the auto-send handoff when the handoff targets the same mode that produced the response. Handoff buttons are still rendered for manual use. Fixes microsoft#325128 Co-authored-by: atlarix-agent <agent@atlarix.dev>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents an infinite Autopilot loop in the chat widget when an agent response includes a self-referencing send: true handoff, by adding a guard before auto-triggering a handoff. This lives in the workbench chat UI layer (ChatWidget) where the auto-send behavior is implemented.
Changes:
- Add a condition to skip auto-triggering
send: truehandoffs that target the same agent/mode that produced the response.
Comment on lines
1349
to
1353
| if (permissionLevel === ChatPermissionLevel.Autopilot) { | ||
| const autoSendHandoff = handoffs.find(h => h.send); | ||
| if (autoSendHandoff) { | ||
| if (autoSendHandoff && autoSendHandoff.agent !== responseMode.name.get()) { | ||
| this.handleNextPromptSelection(autoSendHandoff); | ||
| return; |
Move the self-referencing guard from the if-block into the find() predicate so that subsequent send:true handoffs targeting a different agent still auto-trigger when the first one is self-referencing. Also compare against both responseMode.name and responseMode.id since handoff agents can be specified by either. Co-authored-by: atlarix-agent <agent@atlarix.dev>
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.
Description
Before auto-triggering a
send: truehandoff, the code now compares the handoff's target agent against the name of the mode that produced the response. If they match (self-referencing), the auto-trigger is skipped. Handoff buttons are still rendered for manual use — only the automatic send is blocked for self-referencing handoffs.Why this method over others
IHandOff.agent,IChatMode.name) already in scope. No new imports, no behavior change for legitimate cross-agent handoffs.How to test
Create a
.agent.mdfile with a self-referencing handoff:Enable Autopilot mode and select the "test agent" mode
Send "Hi"
Verify handoff buttons are visible and clickable for manual use
Verify a Plan → Agent handoff with
send: truestill auto-triggers (different agents should work normally)