Repository navigation
Python: Reset Magentic participant sessions on replan - #9131
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
Conversation
MagenticAgentExecutor.handle_magentic_reset assigned the new session to _agent_thread, an attribute nothing reads since the AgentExecutor session attribute was renamed to _session, so participants kept their whole conversation across every reset. Assign _session instead and also clear _pending_request_order with the other pending request state.
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 1bed6c084b12
Model: gpt-5.6-sol
Overview
The change restores the documented fresh-session invariant by resetting the _session field actually used by both streaming and non-streaming agent runs. It also clears all three correlated pending-request structures, and the end-to-end regression test demonstrates that pre-reset history no longer reaches a participant after replanning. No concrete Critical, High, or Medium regression remains after reconciling the reset lifecycle, checkpoint behavior, provider contracts, and existing safeguards.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Motivation & Context
When a Magentic workflow stalls and replans, participant agents are supposed to start fresh. Instead they keep their whole earlier conversation.
MagenticAgentExecutor.handle_magentic_resetassigns the new session toself._agent_thread, butAgentExecutorhas run the agent withself._sessionsince #3850, so the new session is never used and the old history is sent again after every reset.Description & Review Guide
What are the major changes?
In
handle_magentic_reset:_pending_request_orderis cleared along with the other pending-request state the handler already resets, so it can't keep IDs of requests that no longer exist.The new test
test_magentic_reset_gives_participants_a_fresh_sessiondrives a realAgentthrough a scripted stall, reset and replan, and checks what the agent sends to the model after the reset. Without the change it fails:What is the impact of these changes?
After a reset, each participant gets a new session, as the class and handler docstrings describe. For the repro in the linked issue, the second call is now
['after reset']instead of['before reset', 'reply-1', 'after reset']. Nothing changes for workflows that never reset.What do you want reviewers to focus on?
Whether clearing
_pending_request_orderbelongs here. I added it because the handler already clears_pending_agent_requestsand_pending_responses_to_agent, and the order list only tracks IDs from those. I can drop it to keep the change to the session line only.Related Issue
Fixes #9129
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.