crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] a2a.utils.task.list_tasks raises TypeError when task timestamps mix aware and missing values

Open heyseere opened this issue 1 month ago • 2 comments

Label: llm-generated — this report was produced with AI assistance (ZCode agent) and human-reviewed. Please apply the llm-generated label.

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.min for missing timestamps vs aware parsed values → TypeError: can't compare offset-naive and offset-aware datetimes in filtered.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.

heyseere avatar Oct 28 '26 16:10 heyseere

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 28 '26 12:11 github-actions[bot]

Related fix is up for review in #8739 (list_tasks is now safe across naive/aware datetimes). Happy to iterate there.

heyseere avatar Nov 30 '26 09:11 heyseere