score timezone-aware memory timestamps instead of raising TypeError

Abierto
#9,690 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Wooohaaa ya está trabajando en esto.

Desde el 24/11/2026.

  • #9687 de @DZH166 — cerrado sin fusionar
  • #9715 de @Wooohaaa — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

The failing subtraction is datetime.utcnow() - record.created_at in compute_composite_score() in lib/crewai/src/crewai/memory/types.py, reached from the recall paths in unified_memory.py and recall_flow.py. Reproduce by building a MemoryRecord with an aware UTC created_at and calling the score. Done means aware and naive inputs for the same instant give the same composite score. Open PR #9715 already targets this, so check it before starting.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Problem

compute_composite_score() in lib/crewai/src/crewai/memory/types.py computes the
recency term as

age_seconds = (datetime.utcnow() - record.created_at).total_seconds()

datetime.utcnow() is offset-naive, and MemoryRecord.created_at is only
naive by default (default_factory=datetime.utcnow). Nothing in the model
enforces that: a caller may pass datetime.now(timezone.utc), and the storage
backends hand back aware datetimes as well, because they persist
record.created_at.isoformat() (which appends the offset when the value was
aware) and parse it back with datetime.fromisoformat(...):

  • lib/crewai/src/crewai/memory/storage/lancedb_storage.py:290-296 (_parse_dt, "Z" → "+00:00")
  • lib/crewai/src/crewai/memory/storage/qdrant_edge_storage.py:223-228 (_parse_dt)

Subtracting the two raises:

TypeError: can't subtract offset-naive and offset-aware datetimes

This helper is on every recall path — lib/crewai/src/crewai/memory/unified_memory.py:764
and lib/crewai/src/crewai/memory/recall_flow.py:140,169,371. In
recall_flow._do_search the call sits outside the try that wraps the storage
search, so the TypeError is not even logged and skipped: it aborts the whole
recall. Any user who creates a MemoryRecord with an aware UTC timestamp (the
form the datetime docs recommend) gets a working remember() and a
recall() that explodes.

Observed with the checkout at 6a5b80c (before-1.log):

created_at naive UTC       -> composite=0.738110
created_at aware UTC       -> TypeError: can't subtract offset-naive and offset-aware datetimes

EXPECTED: composite == 0.738110 (aware input scores like the same UTC instant)
ACTUAL:   TypeError: can't subtract offset-naive and offset-aware datetimes

The same instant stored naively scores fine, so the failure is purely the
naive/aware mix and not the timestamp value.

I opened #9687 with a one-line fix and a regression test for this before reading the contribution flow; linking it here in case a maintainer wants to pick it up from the issue.

Lenguaje dominante
Python
Estrellas
61.2k
Forks
9.2k
Merge medio
1 d 14 h
PR fusionados (30 d)
180

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de crewAIInc/crewAI

Todos los issues de crewAIInc/crewAI

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.