Skip to content

fix(a2a): make list_tasks sorting and filtering safe across naive and aware datetimes - #8739

Open
heyseere wants to merge 1 commit into
crewAIInc:mainfrom
heyseere:fix/a2a-list-tasks-timezone
Open

heyseere wants to merge 1 commit into
crewAIInc:mainfrom
heyseere:fix/a2a-list-tasks-timezone

Conversation

@heyseere

@heyseere heyseere commented Oct 28, 2026 •

Copy link
Copy Markdown

Related issue

Fixes #8735

Summary

list_tasks raised TypeError: can't compare offset-naive and offset-aware datetimes when the task list mixed tasks carrying aware ISO timestamps with tasks without a timestamp (the sort key returned naive datetime.min), and when callers passed a naive status_timestamp_after. This PR normalizes status timestamps to aware UTC in a single helper used by both the sort key and the timestamp filter, and normalizes a naive cutoff at entry. Missing timestamps still sort as the oldest instant and are still exempt from the time filter — semantics unchanged, crash removed.

Verification

  • Tests added or updated for the changed behavior
  • Relevant tests and quality checks pass locally

lib/crewai/tests/a2a (104 passed): new tests cover mixed aware/missing-timestamp sorting, a naive cutoff, and an aware cutoff. The mixed-sort and naive-cutoff tests fail with TypeError on the old code. ruff check clean on changed files.

Disclosure: this PR was produced with AI assistance (ZCode agent) and human-reviewed — please apply the llm-generated label.

Additional context

None

From ZCode


Note

Low Risk
Targeted datetime normalization in an A2A listing utility with preserved behavior and new regression tests; no auth or data-path changes.

Overview
Fixes TypeError when list_tasks sorted or filtered tasks whose status timestamps mixed timezone-aware ISO strings with missing timestamps, or when callers passed a naive status_timestamp_after.

Introduces _parse_status_timestamp so every comparison uses UTC-aware datetimes: missing timestamps map to the oldest instant, naive parsed values are treated as UTC, and the cutoff datetime is normalized at entry. Sorting and the “updated after” filter both go through this helper; ordering and filter semantics for missing timestamps are unchanged.

Adds unit tests for mixed aware/missing-timestamp sort order, naive cutoffs, and aware time filtering.

Reviewed by Cursor Bugbot for commit f547cd2. Bugbot is set up for automated code reviews on this repo. Configure here.

@strix-security

strix-security Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 23 commits after the last Strix review (c7c8fc8). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: Adds a `_parse_status_timestamp` helper in the A2A task utilities that normalizes task status timestamps to aware UTC datetimes, and uses it for both the `list_tasks` timestamp filter and sort key, plus normalizing a naive `status_timestamp_after` cutoff. This removes the `TypeError` raised when tasks mixed aware timestamps with missing ones, and adds tests for the mixed, naive-cutoff, and aware-cutoff cases.

Review summary

This PR fixes a crash in the A2A list_tasks helper: a new _parse_status_timestamp normalizes every stored status timestamp to an aware UTC datetime (missing values becoming the oldest instant, naive values assumed UTC), and a naive status_timestamp_after cutoff is converted at entry, so sorting and filtering no longer raise TypeError on mixed naive/aware values. Security review found no vulnerability: the patch parses exactly the same strings with the same datetime.fromisoformat call as the pre-image (only adding non-raising tzinfo handling), removes exception surface rather than adding it, keeps context_id/status scoping untouched, and does not widen who can reach or see a task — the filter is a caller-side narrowing predicate, not an authorization decision, and ordering semantics are unchanged. The new tests only exercise the corrected comparison behavior.

Review 1 on this PR · c7c8fc8 · requested Oct 28 16:07 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings

@heyseere
heyseere force-pushed the fix/a2a-list-tasks-timezone branch 2 times, most recently from 2f3babb to faf2a21 Compare October 29, 2026 15:42
@heyseere

Copy link
Copy Markdown
Author

Friendly ping for a review when you have a moment. All bot checks are green and the PR is mergeable; happy to adjust anything.

@heyseere
heyseere force-pushed the fix/a2a-list-tasks-timezone branch from faf2a21 to f547cd2 Compare November 1, 2026 09:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant