Repository navigation
Python: Release the AgentChat activity signal when a message is rejected - #14640
Open
Michael Y (Michael-Duck) wants to merge 1 commit into
Open
Michael Y (Michael-Duck) wants to merge 1 commit into
Michael Y (Michael-Duck) wants to merge 1 commit into
Conversation
Signed-off-by: Michael-Duck <michael@realms.nexus>
Michael Y (Michael-Duck)
deployed
to
github-app-auth
October 22, 2026 14:54 — with
GitHub Actions
Active
Michael Y (Michael-Duck)
deployed
to
github-app-auth
October 22, 2026 14:54 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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), theAgentChatExceptionwas raised before thetry/finallyblock that releases the signal. The chat therefore stayed "active" forever: after the caller handled the validation error, every later call failed withUnable 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
tryblock that already releases the activity signal, so a rejected message always leaves the chat inactive and usable again. Acquiring the signal stays outside thetry, 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/unitsuite 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_rejectedtopython/tests/unit/agents/test_group_chat/test_agent_chat.py. It fails on the unpatched tree (assert not Trueforagent_chat.is_active) and passes with the fix.pytest python/tests/unit/agents/test_group_chat/-> 53 passedruff format --checkandruff checkon both changed files -> cleanThe 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, printsFalseforchat.is_activeand adds the corrected message.