Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/praisonai-agents/praisonaiagents/session/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def list_sessions(self, limit: int = 50) -> List[Dict[str, Any]]:
pass

# Sort by updated_at descending
sessions.sort(key=lambda x: x.get("updated_at", ""), reverse=True)
sessions.sort(key=lambda x: x.get("updated_at") or "", reverse=True)
return sessions[:limit]

# ── Agent-Level Queries (Gap S4) ──────────────────────────────────
Expand Down
36 changes: 36 additions & 0 deletions src/praisonai-agents/tests/unit/session/test_session_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,42 @@ def test_invalidate_cache(self, temp_store):
temp_store.invalidate_cache("session-1")
history = temp_store.get_chat_history("session-1")
assert len(history) == 2

def test_list_sessions_with_none_updated_at(self, temp_store):
"""Test list_sessions handles None updated_at values without crashing.

Regression test for issue #1445 where sessions with updated_at=None
caused TypeError in sorting.
"""
# Create a session with a regular message
temp_store.add_user_message("session-1", "Hello")

# Create another session and manually set updated_at to None
temp_store.add_user_message("session-2", "Hi")
filepath = os.path.join(temp_store.session_dir, "session-2.json")

# Read the session file and set updated_at to None
with open(filepath, "r") as f:
data = json.load(f)
data["updated_at"] = None # Explicit None value
with open(filepath, "w") as f:
json.dump(data, f)

# Clear cache to ensure file is re-read
temp_store.invalidate_cache("session-2")

# This should not crash with TypeError
sessions = temp_store.list_sessions(limit=50)

# Should return both sessions
assert len(sessions) == 2
session_ids = [s["session_id"] for s in sessions]
assert "session-1" in session_ids
assert "session-2" in session_ids

# Session with None updated_at should appear last (empty string sorts before timestamps)
assert sessions[-1]["session_id"] == "session-2"
assert sessions[-1]["updated_at"] is None


class TestAgentSessionIntegration:
Expand Down
Loading