Skip to content

Python: skip Foundry session persist after a failed conversation turn - #7637

Open
Shikhar Goel (sgoel2be24-cyber) wants to merge 4 commits into
microsoft:mainfrom
sgoel2be24-cyber:fix/foundry-skip-failed-conversation-persist
Open

Python: skip Foundry session persist after a failed conversation turn#7637
Shikhar Goel (sgoel2be24-cyber) wants to merge 4 commits into
microsoft:mainfrom
sgoel2be24-cyber:fix/foundry-skip-failed-conversation-persist

Conversation

@sgoel2be24-cyber

Copy link
Copy Markdown

Motivation & Context

When a hosted Foundry agent is used with conversation_id, a failed request still saved the mutated Agent Framework session. The next request on the same conversation then replayed the bad input and failed too. Azure OpenAI does not keep failed input on the conversation.

Fixes #7630

Description & Review Guide

  • What are the major changes? In _handle_inner_agent, skip session_storage.set when the request failed and context.conversation_id is set. Non-conversation runs still persist on failure (existing test_failed_run_still_saves_mutated_session).
  • What is the impact of these changes? A conversation remains usable after a failed turn.
  • What do you want reviewers to focus on? That we only skip persist for conversation mode, not for previous_response_id / anonymous sessions.

Related Issue

Fixes #7630

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

Assistance: drafted with an AI coding agent and reviewed before opening.

Made with Cursor

… turn

Saving the mutated session on failure poisons later requests that reuse
the same conversation_id. Non-conversation runs still persist on failure.
Copilot AI balanced review requested due to automatic review settings August 13, 2026 03:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 13, 2026
@sgoel2be24-cyber

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@cecheta

Copy link
Copy Markdown
Member

Unfortunately this doesn't fix the issue, as the problem is that the messages get saved to the chat history, not the session.

Skip persisting input items when a stored response is failed so the next
request on the same conversation does not replay the bad turn.
@sgoel2be24-cyber

Copy link
Copy Markdown
Author

You're right — the first commit skipped the wrong store.

The agentserver response provider was persisting input items for failed turns, so the next request on the same conversation replayed them via chat history (get_history()), not the MAF session.

24ebe8b wraps the response store so failed turns persist without input items (including the in_progress → failed update path). A follow-up request on the same conversation no longer sees the bad function_call_output. Tests cover both the store wrapper and the HTTP conversation repro from the issue.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Foundry Hosting - User messages added to conversation chat history for failed requests

3 participants