Skip to content

fix(server): avoid out-of-range datetime task ordering - #1220

Open
Jokasa7 wants to merge 1 commit into
a2aproject:mainfrom
Jokasa7:JoyCx/a2a-python-1219-null-sort
Open

fix(server): avoid out-of-range datetime task ordering#1220
Jokasa7 wants to merge 1 commit into
a2aproject:mainfrom
Jokasa7:JoyCx/a2a-python-1219-null-sort

Conversation

@Jokasa7

@Jokasa7 Jokasa7 commented Aug 29, 2026

Copy link
Copy Markdown

Description

DatabaseTaskStore.list() currently makes NULL timestamps sort last by
coalescing them to datetime.min (year 0001). MySQL documents year 1000 as the
lower bound of its supported DATETIME range. Current MySQL versions may still
accept year 0001, so this is a portability and specification-conformance risk
rather than a consistently reproducible runtime failure.

This change replaces the datetime sentinel with an explicit ordering key:

  1. a CASE expression ranks non-NULL timestamps before NULL timestamps;
  2. non-NULL timestamps remain in descending order; and
  3. task IDs remain the descending tie-breaker, including for NULL timestamps.

This preserves the existing list and cursor-pagination order without binding an
out-of-range datetime. It also avoids NULLS LAST, which MySQL does not support
and which was previously removed in #651.

The regression test observes SQLAlchemy's compiled execution parameters and
fails if list() binds a datetime before year 1000. With the test applied to the
base implementation, the SQLite case failed by capturing the year-0001
sentinel. With this change, the same test passes on SQLite, PostgreSQL 15, and
MySQL 8.0, alongside the existing ordering and pagination matrix.

Validation

  • ./scripts/lint.sh — Ruff check/format passed; ty check passed
  • ./scripts/run_db_tests.sh -k test_list_tasks — 36 passed across SQLite,
    PostgreSQL 15, and MySQL 8.0
  • uv run pytest tests/integration/cross_version/client_server/test_client_server.py -q
    — 4 passed
  • uv run pytest — 1971 passed, 92 skipped, 3 xfailed, 1 xpassed
  • uv run pytest --cov=src --cov-report=term-missing — same test result,
    93% total coverage
  • git diff --check — passed

Checklist

  • Followed the CONTRIBUTING guide and repository AI workflow documents.
  • Used a Conventional Commit title.
  • Ran the required linter, formatter, type checker, full tests, and coverage.
  • Added a regression test for the changed runtime behavior.
  • No user-facing documentation change is required; ordering semantics are
    unchanged.

Fixes #1219 🦕

AI assistance was used for issue and code-path research and for drafting. I
reviewed the final diff and ran every validation command listed above.

@Jokasa7
Jokasa7 requested a review from a team as a code owner August 29, 2026 09:35
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

No coverage changes.

Generated by coverage-comment.yml

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.

[Task]: datetime.min fallback in DatabaseTaskStore.list() is outside MySQL's documented DATETIME range

1 participant