Skip to content

Python: Bug fix for Redis TypeError#2411

Merged
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom
moonbox3:fix-1991
Nov 24, 2025
Merged

Python: Bug fix for Redis TypeError#2411
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom
moonbox3:fix-1991

Conversation

@moonbox3
Copy link
Contributor

Motivation and Context

When using RedisChatMessageStore for message storage and calling thread.serialize(), the following error occurs:

File "/Users/worker/workspace/project/agent-framework-demo/chatagent_redisstore_demo.py", line 93, in chat_demo
    serialized_thread = await thread_1.serialize()
File ".../agent_framework/_threads.py", line 430, in serialize
    state = AgentThreadState(
        service_thread_id=self._service_thread_id, chat_message_store_state=chat_message_store_state
    )
File ".../agent_framework/_threads.py", line 175, in __init__
    self.chat_message_store_state = ChatMessageStoreState.from_dict(chat_message_store_state)
File ".../agent_framework/_serialization.py", line 552, in from_dict
    return cls(**kwargs)
File ".../agent_framework/_threads.py", line 144, in __init__
    raise TypeError("Messages should be a list")

The bug is in ChatMessageStoreState.__init__() in _threads where in the constructor, the line if not isinstance(messages, list): always runs, even if messages is None. When RedisChatMessageStore.serialize() returns a dict without a messages field (containing only thread_id, redis_url, etc.), the messages parameter defaults to None, triggering the TypeError.

The fix is to add an early return after handling the empty/None case - no further processing is necessary because the incoming messages are None.

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3 moonbox3 self-assigned this Nov 24, 2025
@moonbox3 moonbox3 marked this pull request as ready for review November 24, 2025 04:02
Copilot AI review requested due to automatic review settings November 24, 2025 04:02
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _threads.py1362184%145, 177–178, 180, 257–260, 343, 355, 467–471, 474–475, 494, 496, 499, 505
TOTAL15462235284% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2225 130 💤 0 ❌ 0 🔥 56.934s ⏱️

Copy link
Contributor

Copilot AI left a comment

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 a bug in ChatMessageStoreState.__init__() where a TypeError was raised when messages parameter was None or empty. This occurred when using RedisChatMessageStore with AgentThread.serialize() because Redis stores don't include a messages field in their serialized state.

  • Fixed the TypeError by adding an early return after handling None/empty messages
  • Added comprehensive test coverage for the None and empty messages scenarios
  • Added integration test to verify the fix works with RedisChatMessageStore and AgentThread

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
python/packages/core/agent_framework/_threads.py Added early return in ChatMessageStoreState.__init__() after handling None/empty messages to prevent TypeError
python/packages/core/tests/core/test_threads.py Added unit tests for None messages, no messages argument, and AgentThreadState with store state without messages field
python/packages/redis/tests/test_redis_chat_message_store.py Added integration test to verify RedisChatMessageStore can be serialized within an AgentThread

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Nov 24, 2025
Merged via the queue into microsoft:main with commit f9a94ce Nov 24, 2025
30 checks passed
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: When using RedisChatMessageStore for message storage, the following error occurs: TypeError: Messages should be a list.

5 participants