Skip to content

fix: Code fix to handle replan request#1062

Merged
Roopan-Microsoft merged 1 commit into
microsoft:devfrom
chaudhariniraj:dev
Jun 24, 2026
Merged

fix: Code fix to handle replan request#1062
Roopan-Microsoft merged 1 commit into
microsoft:devfrom
chaudhariniraj:dev

Conversation

@chaudhariniraj

Copy link
Copy Markdown

Purpose

Code fix to handle replan requests.

Issue

When a user creates a task for the Retail Success Team for the first time, the Magentic orchestrator may not gather sufficient information to confidently complete the task. As a result, it triggers a replanning event during workflow execution.

The replanning event generates a new MagenticPlanReviewRequest, which was being handled the same way as the initial plan review. Consequently, orchestration_manager.py invoked _handle_plan_reviews() again, causing the workflow to pause and wait for user approval a second time.

This resulted in the user being redirected back to the "Approve Plan" screen, giving the impression that the workflow had failed, even though the orchestration was still active.


Fix

Introduced a plan_already_approved flag to track whether the user has already approved the workflow plan.

plan_already_approved = False

Workflow

  1. When the user approves the initial plan, the flag is set to True.
  2. If a replanning event occurs after the initial approval, the workflow skips the _handle_plan_reviews() method, which would otherwise:
    • Send another PLAN_APPROVAL_REQUEST to the UI.
    • Pause the workflow.
    • Wait for user approval again.
  3. Instead, replanned workflows are automatically approved by generating approval responses programmatically:
plan_responses = {
    request_id: plan_review.approve()
    for request_id, plan_review in plan_requests.items()
}

Benefits

  • Prevents users from being sent back to the Approve Plan screen during internal replanning.
  • Allows Magentic to continue executing replanned workflows without interruption.
  • Preserves the framework's replanning capability while improving the user experience.
  • Ensures that only the initial workflow plan requires explicit user approval.

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

@Roopan-Microsoft Roopan-Microsoft merged commit d64afbe into microsoft:dev Jun 24, 2026
6 of 7 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.

2 participants