Skip to content

Python: omit failed Foundry turns from conversation chat history - #7637

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

Python: omit failed Foundry turns from conversation chat history#7637
Shikhar Goel (sgoel2be24-cyber) wants to merge 1 commit into
microsoft:mainfrom
sgoel2be24-cyber:fix/foundry-skip-failed-conversation-persist

Conversation

@sgoel2be24-cyber

@sgoel2be24-cyber Shikhar Goel (sgoel2be24-cyber) commented Aug 13, 2026

Copy link
Copy Markdown

Motivation & Context

When a hosted Foundry agent is used with conversation_id, a failed turn still stored its input items on the agentserver response/conversation store. The next request on that conversation replayed them via get_history(). Azure OpenAI does not keep failed input on the conversation.

Fixes #7630

Description & Review Guide

  • Let ResponsesAgentServerHost resolve and validate its configured/default response store before wrapping it, preserving hosted and local persistence defaults plus the resilient-background guard.
  • For synchronous non-background requests, determine the terminal result before the provider's initial create so failed input items never enter conversation history.
  • Keep existing response updates atomic at the provider level instead of using delete-then-create.
  • Reverted the earlier “skip MAF session persist on failure” change; that was the wrong store.
  • Tests in python/packages/foundry_hosting/tests/test_responses.py cover the HTTP conversation repro, provider behavior, default persistent storage, and the resilience guard.

Please focus on: failed synchronous turns stay out of get_history(), successful turns still persist, non-conversation runs are unchanged, and the base host's storage behavior is preserved.

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.

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.

@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.

@sgoel2be24-cyber Shikhar Goel (sgoel2be24-cyber) changed the title Python: skip Foundry session persist after a failed conversation turn Python: omit failed Foundry turns from conversation chat history Aug 14, 2026
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
Comment thread python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py Outdated
@sgoel2be24-cyber
Shikhar Goel (sgoel2be24-cyber) force-pushed the fix/foundry-skip-failed-conversation-persist branch from 9c43deb to 4b6b97e Compare August 22, 2026 11:59
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

4 participants