crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[Tech Debt] Replace deprecated datetime.utcnow() with naive-UTC datetime.now(timezone.utc) in memory subsystem

Open Akaliup opened this issue 1 month ago • 1 comments

Summary

datetime.utcnow() is deprecated since Python 3.12 (docs) and emits DeprecationWarning on 3.12+. The memory subsystem still calls it in 13 places (5 files).

The internal contract of the memory layer is naive UTC (see #7529 and #8565, where timezone-aware datetimes crash compute_composite_score and LanceDB delete()). So the correct replacement here is not the aware datetime.now(timezone.utc), but the behavior-preserving naive form:

datetime.now(timezone.utc).replace(tzinfo=None)

This keeps every stored/compared value naive-UTC with identical wall-clock semantics, while removing the deprecation warnings.

Affected call sites

File Line Calls
lib/crewai/src/crewai/memory/encoding_flow.py 397 1
lib/crewai/src/crewai/memory/types.py 364 1
lib/crewai/src/crewai/memory/unified_memory.py 893 1
lib/crewai/src/crewai/memory/storage/lancedb_storage.py 193, 194, 292, 378 4
lib/crewai/tests/memory/test_unified_memory.py 700, 712, 747, 769, 779, 797 6

Suggested fix

Replace each datetime.utcnow() with datetime.now(timezone.utc).replace(tzinfo=None) and extend the from datetime import datetime imports with timezone. No behavior change: values stay naive UTC.

I have the change ready and verified locally and will open a PR referencing this issue.

Disclosure

This issue and the upcoming PR are AI-agent-assisted (generated with an AI coding agent). Please apply the llm-generated label per CONTRIBUTING - I cannot set labels without triage permission.

Akaliup avatar Oct 31 '26 03:10 Akaliup

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 30 '26 12:11 github-actions[bot]