[Bug]: ListTasks prints unset fields on every task (history: [] with historyLength=0, empty mediaType/filename on parts)

Đang mở
#1,461 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@rohityan đang làm issue này rồi.

Từ ngày 12/11/2026.

  • #1477 của @saquibjawedbit — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

What happened?

ListTasks (JSON-RPC and REST) serializes its tasks differently from GetTask. serialize_list_tasks_response uses MessageToDict(..., always_print_fields_with_no_presence=True), which is there so nextPageToken, pageSize and totalSize are always present. But the flag applies to the whole tree, so every nested task, message and part also gets its unset fields printed as defaults:

https://github.com/a2aproject/a2a-python/blob/2ba8e7bd27fce7de92c33813a46dbea1e3f7e6ce/src/a2a/server/routes/common.py#L32-L44

Two visible effects on main (2ba8e7b):

  1. With historyLength: 0, each task still carries "history": []. §3.2.4 says that for 0 "the history field SHOULD be omitted" (https://a2a-protocol.org/latest/specification/#324-history-length-semantics), and GetTask does omit it. #1211 fixed the same thing for artifacts, by popping the key afterwards.
  2. Messages and parts in a listed task get fields the stored task never had: "filename": "" and "mediaType": "" on a text part, "contextId": "", "taskId": "", "extensions": [] and "referenceTaskIds": [] on a message. The same task fetched with GetTask has none of them, so one task has two JSON shapes depending on the method used to read it.

Repro (one stored task, real DefaultRequestHandler behind create_jsonrpc_routes):

import asyncio, json, httpx
from starlette.applications import Starlette
from a2a.server.context import ServerCallContext
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.routes import create_jsonrpc_routes
from a2a.server.tasks import InMemoryTaskStore
from a2a.types.a2a_pb2 import AgentCard, Message, Part, Role, Task, TaskState, TaskStatus

async def main():
    store = InMemoryTaskStore()
    msg = Message(message_id='m1', role=Role.ROLE_USER, parts=[Part(text='hi')])
    await store.save(Task(id='t1', context_id='c1', status=TaskStatus(state=TaskState.TASK_STATE_WORKING), history=[msg]), ServerCallContext())
    handler = DefaultRequestHandler(None, store, AgentCard(name='a', version='1'))
    app = Starlette(routes=create_jsonrpc_routes(handler, '/'))
    async with httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url='http://agent', headers={'A2A-Version': '1.0'}) as c:
        async def call(method, params):
            r = await c.post('/', json={'jsonrpc': '2.0', 'id': 1, 'method': method, 'params': params})
            return r.json()['result']
        print('GetTask   historyLength=0:', json.dumps(await call('GetTask', {'id': 't1', 'historyLength': 0})))
        print('ListTasks historyLength=0:', json.dumps((await call('ListTasks', {'historyLength': 0}))['tasks'][0]))
        print('GetTask   :', json.dumps((await call('GetTask', {'id': 't1'}))['history']))
        print('ListTasks :', json.dumps((await call('ListTasks', {}))['tasks'][0]['history']))

asyncio.run(main())

Output on main:

GetTask   historyLength=0: {"id": "t1", "contextId": "c1", "status": {"state": "TASK_STATE_WORKING"}}
ListTasks historyLength=0: {"id": "t1", "contextId": "c1", "status": {"state": "TASK_STATE_WORKING"}, "history": []}
GetTask   : [{"messageId": "m1", "role": "ROLE_USER", "parts": [{"text": "hi"}]}]
ListTasks : [{"messageId": "m1", "role": "ROLE_USER", "parts": [{"text": "hi", "filename": "", "mediaType": ""}], "contextId": "", "taskId": "", "extensions": [], "referenceTaskIds": []}]

REST GET /tasks?historyLength=0 shows the same output, since both bindings use serialize_list_tasks_response.

Expected: each task in ListTasks serializes like the same task from GetTask: no history key for historyLength: 0, and no empty-default fields on messages and parts. Only the top-level response fields (tasks, nextPageToken, pageSize, totalSize) and, with includeArtifacts: true, artifacts need to be printed when empty.

Actual: history: [] with historyLength: 0, and empty-string or empty-list values on every nested message and part.

Happy to send a fix if that helps.

Code of Conduct
  • I agree to follow this project's Code of Conduct
Ngôn ngữ chính
Python
Star
2.2k
Fork
540
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
56

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của a2aproject/a2a-python

Tất cả issue của a2aproject/a2a-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.