Skip to content

Python: Clear stale service session on full-history replay - #7354

Draft
hsusul wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix-python-full-history-session-id
Draft

Python: Clear stale service session on full-history replay#7354
hsusul wants to merge 1 commit into
microsoft:mainfrom
hsusul:fix-python-full-history-session-id

Conversation

@hsusul

@hsusul hsusul commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

AgentExecutorRequest can replay an explicit prior conversation, including model-issued function calls, while the target executor still carries a service_session_id from an earlier run. That combines caller-supplied history with an unrelated service-side continuation handle.

The executor-layer regression was already recorded as a strict xfail when #5690 fixed the OpenAI wire-format half of #3295. Running that test with --runxfail on current main fails because the agent receives resp_PREVIOUS_RUN instead of None.

Description & Review Guide

  • What are the major changes?
    • Clear service_session_id before handling an AgentExecutorRequest that replays model-issued function_call content.
    • Promote the existing strict xfail to a normal regression test.
    • Add a boundary test proving that a function-result-only request preserves the service session so it can continue the stored tool call.
  • What is the impact of these changes?
    • Full-history replay no longer combines explicit function-call history with a stale service continuation.
    • Incremental function results and the existing from_response path continue to preserve service_session_id.
    • There is no public API or persistence-format change.
  • What do you want reviewers to focus on?
    • Whether model-issued function_call content is the right narrow signal that distinguishes explicit replay from a function-result continuation.

Validation:

  • .venv/bin/uv run pytest packages/core/tests/workflow/test_full_conversation.py -q — 10 passed.
  • .venv/bin/uv run poe check -P core — formatting, lint, source Pyright, and all five test type checkers passed; 3,690 tests passed, 18 skipped, and 1 unrelated test xfailed.

No live provider credentials were used. The regression captures the session value at the provider boundary, and #5690 retains the separate OpenAI wire-format protection.

Related Issue

Follow-up to #3295 and #5690. The issue is already closed; this completes the executor-layer strict-xfail follow-up documented by the merged fix, so no closing keyword is used.

No open PR found for this executor behavior. #7345 covers approval replay and touches neither affected file.

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. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings July 28, 2026 06:11
@hsusul
hsusul temporarily deployed to github-app-auth July 28, 2026 06:11 — with GitHub Actions Inactive
@hsusul
hsusul temporarily deployed to github-app-auth July 28, 2026 06:11 — with GitHub Actions Inactive
@hsusul
hsusul temporarily deployed to github-app-auth July 28, 2026 06:11 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Jul 28, 2026
@hsusul
hsusul temporarily deployed to github-app-auth July 28, 2026 06:12 — with GitHub Actions Inactive

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.

Pull request overview

This PR fixes an executor-layer session-continuation bug in the Python workflow runtime: when an AgentExecutorRequest replays a prior conversation (including tool calls), the executor must not reuse an unrelated service_session_id from a previous run, which can incorrectly combine explicit history with a provider-side continuation handle.

Changes:

  • Clear service_session_id in AgentExecutor.run() when an incoming AgentExecutorRequest replays function-call history.
  • Promote the previously strict-xfailed regression test to a normal test.
  • Add a boundary test ensuring a function-result-only request preserves service_session_id for legitimate continuation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/core/agent_framework/_workflows/_agent_executor.py Clears stale service_session_id on replayed function-call history before running the agent.
python/packages/core/tests/workflow/test_full_conversation.py Converts the regression from xfail to pass and adds a boundary test for function-result continuation behavior.

Comment on lines +210 to +211
if any(content.type == "function_call" for message in request.messages for content in message.contents):
self._session.service_session_id = None
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.

2 participants