Skip to content

Python: Release the AgentChat activity signal when a message is rejected - #14640

Open
Michael Y (Michael-Duck) wants to merge 1 commit into
microsoft:mainfrom
Michael-Duck:michael-duck/ai-14638-agent-chat-activity-signal
Open

Michael Y (Michael-Duck) wants to merge 1 commit into
microsoft:mainfrom
Michael-Duck:michael-duck/ai-14638-agent-chat-activity-signal

Conversation

@Michael-Duck

@Michael-Duck Michael Y (Michael-Duck) commented Oct 22, 2026 •

Copy link
Copy Markdown

Motivation and Context

AgentChat.add_chat_messages() acquires the activity signal before it validates the roles of the incoming messages. When that validation rejects a message (for example a system message, which cannot be part of the chat history), the AgentChatException was raised before the try/finally block that releases the signal. The chat therefore stayed "active" forever: after the caller handled the validation error, every later call failed with Unable to proceed while another agent is active. and the chat could neither be used nor reset.

A recoverable validation error became permanent, which is reported in issue #14638.

Description

The role validation now runs inside the try block that already releases the activity signal, so a rejected message always leaves the chat inactive and usable again. Acquiring the signal stays outside the try, so a rejected competing operation still cannot release the signal of another running operation.

Nothing else changes: the validation still runs before history.messages.extend(messages), so a mixed batch of user and system messages is rejected without a partial append to the history.

Fixes #14638

Contribution Checklist

The third box is left unticked only because the complete python/tests/unit suite cannot be collected in my environment: several unrelated modules fail to import under Python 3.14 (tests/unit/test_serialization.py, tests/unit/processes/dapr_runtime/, ...). The tests that cover the changed code pass in full - see below.

Tests

Added test_add_chat_messages_releases_activity_signal_when_a_message_is_rejected to python/tests/unit/agents/test_group_chat/test_agent_chat.py. It fails on the unpatched tree (assert not True for agent_chat.is_active) and passes with the fix.

  • pytest python/tests/unit/agents/test_group_chat/ -> 53 passed
  • ruff format --check and ruff check on both changed files -> clean

The reproduction script from the issue was also run before and after the change: before the fix the snippet ended with Exception: Unable to proceed while another agent is active.; after the fix it completes, prints False for chat.is_active and adds the corrected message.

Signed-off-by: Michael-Duck <michael@realms.nexus>
@Michael-Duck
Michael Y (Michael-Duck) requested a review from a team as a code owner October 22, 2026 14:54
Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:54
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 22, 2026

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.

🟢 Approval recommended

The targeted fix preserves validation-before-append behavior and activity ownership, with regression coverage and no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #14638 by ensuring AgentChat releases its activity signal after rejecting a system message, allowing subsequent operations to proceed.

Changes:

  • Moves role validation inside the cleanup scope while keeping activity acquisition outside it.
  • Adds a regression test confirming signal release, successful recovery, and exclusion of the rejected message from history.
File Description
python/​tests/​unit/​agents/​test_group_chat/​test_agent_chat.py Tests activity release and recovery after message rejection.
python/​semantic_kernel/​agents/​group_chat/​agent_chat.py Ensures validation failures release the activity signal.

Review effort: Balanced

This branch was successfully deployed

1 active deployment
github-app-auth — a7e93055 Deployed Oct 22, 2026 by Michael-Duck via team_check #658
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Rejected system messages leave AgentChat permanently active

2 participants