[BUG] a2a.utils.task.list_tasks raises TypeError when task timestamps mix aware and missing values
Label:
llm-generated— this report was produced with AI assistance (ZCode agent) and human-reviewed. Please apply thellm-generatedlabel.
Problem
crewai.a2a.utils.task.list_tasks (a public pure utility for server implementations) crashes when the task list mixes tasks with aware ISO timestamps (what the a2a SDK writes) and tasks without a timestamp (which crewai.a2a.utils.task itself creates for completed statuses):
- Sorting: the key returns naive
datetime.minfor missing timestamps vs aware parsed values →TypeError: can't compare offset-naive and offset-aware datetimesinfiltered.sort(...). - Filtering: a naive
status_timestamp_after(e.g.datetime.utcnow()) compared against aware task timestamps raises the same TypeError.
The function has no internal callers or tests, which is why this never surfaced.
Reproduction
from datetime import datetime, timezone
from a2a.types import Task as A2ATask, TaskState, TaskStatus
from crewai.a2a.utils.task import list_tasks
tasks = [
A2ATask(id="t1", context_id="c", status=TaskStatus(state=TaskState.completed,
timestamp=datetime.now(timezone.utc).isoformat())),
A2ATask(id="t2", context_id="c", status=TaskStatus(state=TaskState.completed)),
]
list_tasks(tasks=tasks, context_id="c") # TypeError from filtered.sort(...)
Expected behavior
Missing timestamps sort as the oldest instant; naive inputs are treated as UTC; no crash either way.
Bounded scope
Normalize status timestamps to aware UTC in one helper used by both the sort key and the timestamp filter, and normalize a naive status_timestamp_after at entry. A PR with regression tests is attached.
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.
Related fix is up for review in #8739 (list_tasks is now safe across naive/aware datetimes). Happy to iterate there.