Repository navigation
Description
What happened?
On main at 2cc1dd5020874376ed293ef87089e5df9d205571, ListTasks backed by DatabaseTaskStore returns an internal error for a page token whose JSON structure is valid but whose timestamp is outside Protobuf's supported range.
DatabaseTaskStore._after_cursor() catches OverflowError from _ns_to_datetime(), but Protobuf 7.36.2 raises ValueError from Timestamp.FromNanoseconds() for these values. That exception reaches the REST error handler as an unknown exception instead of the existing InvalidParamsError('Invalid page token') path.
Reproduction
Python 3.12.16 on Windows, Protobuf 7.36.2, SQLite/aiosqlite; no model, credentials, external database, or provider requests.
import asyncio
import base64
import json
from sqlalchemy.ext.asyncio import create_async_engine
from a2a.server.context import ServerCallContext
from a2a.server.tasks.database_task_store import DatabaseTaskStore
from a2a.types.a2a_pb2 import ListTasksRequest
async def main():
engine = create_async_engine('sqlite+aiosqlite:///:memory:')
try:
store = DatabaseTaskStore(engine)
token = base64.urlsafe_b64encode(json.dumps({
'ts': 253402300800000000000, 'id': 'last-task'
}).encode()).decode().rstrip('=')
await store.list(ListTasksRequest(page_token=token), ServerCallContext())
finally:
await engine.dispose()
asyncio.run(main())Actual: ValueError: Timestamp is not valid: Seconds 253402300800 must be in range [-62135596800, 253402300799].
I also exercised the real create_rest_routes → DefaultRequestHandlerV2 → DatabaseTaskStore path with Starlette, httpx.ASGITransport, and in-memory SQLite:
Cursor ts (nanoseconds) |
HTTP status |
|---|---|
null |
200 |
0 |
200 |
-62135596800000000001 |
500 |
253402300800000000000 |
500 |
10**100 |
500 |
The error body is {"error":{"code":500,"status":"INTERNAL","message":"unknown exception"}}.
Expected: reject the invalid page token with InvalidParamsError, producing HTTP 400 / INVALID_ARGUMENT, consistent with the other invalid-token cases and #814.
Proposed fix
Catch ValueError alongside OverflowError around the timestamp conversion. Add regression cases for both range boundaries and very large positive/negative integers. Four new SQLite cases fail on the unmodified source. This is separate from #1280/#1282 (pagination after task updates/deletions) and #1219/#1220 (database timestamp ordering).
AI disclosure: Codex performed the source inspection, local reproduction, and report drafting under the account holder's instruction. No independent human reproduction is claimed.
Activity
fix(server): reject out-of-range ListTasks cursor timestamps (a2aproj…