Skip to content

fix(server): store MySQL task timestamps with microsecond precision - #1506

Open
SoroushRF wants to merge 2 commits into
a2aproject:mainfrom
SoroushRF:fix/mysql-task-timestamp-precision
Open

SoroushRF wants to merge 2 commits into
a2aproject:mainfrom
SoroushRF:fix/mysql-task-timestamp-precision

Conversation

@SoroushRF

@SoroushRF SoroushRF commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

On MySQL, tasks.last_updated is created as DATETIME with no fractional seconds, while the SDK stamps task status with microseconds. ListTasks filters, sorts and pages on that column, so tasks updated within the same second come back out of order, and status_timestamp_after can drop a task at its own timestamp or include one from before the cutoff.

Map last_updated to DATETIME(6) on MySQL and MariaDB and add Alembic revision d7ef24c86b19 for existing tables. The index, the cursor format and the list query are unchanged. PostgreSQL and SQLite already keep microseconds; the revision does nothing there.

Fixes #1505

Migration

  • On MySQL 8/InnoDB, changing DATETIME to DATETIME(6) rebuilds the table (ALGORITHM=COPY) and blocks writes during the copy. The migrations README now says so. InnoDB online DDL
  • Existing rows keep their whole-second values until saved again, so upgrading does not invalidate page tokens already issued. Backfilling from the status JSON could move old rows across an issued cursor, and custom converters choose their own last_updated.
  • Downgrade returns the column to whole-second precision (dropping fractional seconds; on MySQL, values can round into the next second). The revision honours --tasks-table.
  • The default a2a-db command runs upgrade head, applying any pending revisions including b5e3d1c8a2f7 (which creates task_versions and task_events if missing; the default DatabaseTaskStore leaves them unused, while VersionedDatabaseTaskStore uses them). The migrations README now documents this.
  • Draft feat(server): recover tasks abandoned by a crashed replica #1395 also adds a revision on top of b5e3d1c8a2f7. Whichever lands second needs its down_revision updated.

Verification

  • test_list_tasks_within_one_second fails on the unpatched base with MySQL 8.0.36 (['latest', 'z-early', 'a-middle']) and passes on SQLite 3.45.1 and PostgreSQL 16.14. With the fix it passes on all three.
  • New migration tests: offline SQL for mysql and mariadb in both directions on a custom table name, no ALTER TABLE for PostgreSQL and SQLite, and a SQLite upgrade and downgrade cycle.
  • Live MySQL 8.0.36 check: a table created by the old model was upgraded through a2a-db --tasks-table. The composite index survived, an old page token resumed, new writes listed in the right order with the right cutoff counts, and downgrade restored whole seconds.
  • Live MariaDB 10.11.14 check (mariadb+aiomysql, SQLAlchemy 2.0.48, aiomysql 0.3.2): same custom-table a2a-db --tasks-table upgrade/downgrade cycle passed, and all 45 test_database_task_store.py MySQL-parametrized tests passed against the live server. On a disposable copy, MariaDB 10.11.14 rejected ALGORITHM=INPLACE and suggested COPY.
  • Ruff and ty passed. With PostgreSQL and MySQL enabled, pytest had 2,882 passes (1 skipped, 4 xfailed, 1 xpassed) and 93.89% coverage; the 5 cross-version cases failed/errored there due to an inherited PYTHONPATH in the local environment and all 5 passed when rerun with PYTHONPATH unset (2,887 total passes).

Checklist

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

AI assistance: Codex, Claude and Gemini reproduced the bug, prepared the change and ran the checks under my direction.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SoroushRF
SoroushRF requested a review from a team as a code owner November 20, 2026 12:08
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/tasks/database_task_store.py 96.77% 98.39% 🟢 +1.61%
src/a2a/migrations/versions/d7ef24c86b19_mysql_task_timestamp_precision.py (new) — 85.71% —
Total 94.11% 94.12% 🟢 +0.01%

Generated by coverage-comment.yml

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]: MySQL ListTasks misorders and misfilters tasks updated within the same second

1 participant