Skip to content

fix: reject invalid ListTasks status filters with RequestMalformedError - #631

Merged
JakubWorek merged 6 commits into
a2aproject:mainfrom
ez-lbz:fix/invalid-status-rejected
Aug 27, 2026
Merged

JakubWorek merged 6 commits into
a2aproject:mainfrom
ez-lbz:fix/invalid-status-rejected

Conversation

@ez-lbz

@ez-lbz ez-lbz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What changed

1. Reject invalid status filters on ListTasks instead of silently converting them to UNRECOGNIZED

Problem: The generated taskStateFromJSON (from a2a.proto) maps any unknown status string or out-of-range number to UNRECOGNIZED (-1). The REST transport used it directly, so GET /tasks?status=INVALID_VALUE silently applied an UNRECOGNIZED filter that matches nothing and returned an empty list — the client believed the filter worked. Python's ParseDict rejects invalid values; JS diverged. (The pb file is generated via buf generate from the upstream A2A proto, so the fix lives in the transport parsing, not in the generated file.)

Fix (src/server/transports/rest/rest_transport_handler.ts):

  • listTasks now throws RequestMalformedError('Invalid status filter') when taskStateFromJSON yields UNRECOGNIZED, returning 400 INVALID_ARGUMENT instead of silently filtering.

Fix (src/server/transports/jsonrpc/jsonrpc_transport_handler.ts):

  • The ListTasks case validates the parsed ListTasksRequest.status and rejects UNRECOGNIZED with RequestMalformedError (-32602) before dispatching.

Testing

  • npm test — 68 test files, 1510 tests passed.
  • npx tsc --noEmit (no errors in src/) and npx tsc --noEmit -p tsconfig.test.json pass.
  • New regression tests: REST listTasks with status='bogus-status' and status='99' reject with Invalid status filter; a valid TASK_STATE_COMPLETED still passes through; JSON-RPC ListTasks with status='bogus-status' returns INVALID_PARAMS (-32602) and does not reach the handler.

Behavior change: an invalid status on ListTasks now returns 400 (REST) / -32602 (JSON-RPC) instead of 200 with an empty result set. Existing test GET /tasks > should treat unrecognized status values as UNRECOGNIZED (-1) was updated to assert the new 400 contract.

@ez-lbz
ez-lbz requested a review from a team as a code owner August 10, 2026 16:26
@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/server/request_handler/default_request_handler.ts 91.83% 91.86% 🟢 +0.03%
src/server/utils.ts 87.3% 89.18% 🟢 +1.88%
Total 91.55% 91.56% 🟢 +0.01%

Generated by coverage-comment.yml

@JakubWorek

Copy link
Copy Markdown
Member

Hi @ez-lbz, looks like this PR contains commit not related to the description, taken from #625. Could you update the branch to contain only relevant changes?

@ez-lbz
ez-lbz force-pushed the fix/invalid-status-rejected branch from ef43956 to 83d1341 Compare August 20, 2026 14:17
@ez-lbz

ez-lbz commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Hi @JakubWorek, thanks for the heads-up — the branch was based on a chain that included the #625 commits. I've rebased it onto the current main and removed the unrelated commits; it now contains only the invalid-status-filter rejection change (plus the prettier/tracking-id cleanup). All 1495 tests pass locally.

@JakubWorek JakubWorek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall changes are correct, however I'd move them to request handler. Currently grpc listTasks method is not covered by them and this violates Functional Equivalence Requirement.

ez-lbz added 5 commits August 27, 2026 15:59
Move the invalid status rejection from the JSON-RPC and REST transport
handlers into DefaultRequestHandler.listTasks so gRPC — which decodes
status as a raw enum number without going through taskStateFromJSON —
is covered too, satisfying the spec §5.1 Functional Equivalence
Requirement across all transports.

The handler rejects any state outside VALID_TASK_STATE_LIST (new shared
constant covering every named TaskState) with RequestMalformedError;
unrecognized wire values that protobufjs maps to the synthetic
UNRECOGNIZED (-1) sentinel now surface as malformed instead of silently
matching nothing. Transports return to plain parse-and-forward, and
their specs assert the pass-through plus the error mapping of a
handler-raised RequestMalformedError (-32602 / HTTP 400).
@ez-lbz
ez-lbz force-pushed the fix/invalid-status-rejected branch from ea14f5d to e48a968 Compare August 27, 2026 08:13
@ez-lbz

ez-lbz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this @JakubWorek — you're right, validating at the REST layer left grpc listTasks uncovered and broke the §5.1 functional-equivalence guarantee. I've moved the validation into DefaultRequestHandler.listTasks (next to the existing pageSize/statusTimestampAfter checks): any state outside the named TaskState values raises RequestMalformedError there, so JSON-RPC, REST, and gRPC now reject invalid filters identically — gRPC matters most since it decodes status as a raw enum number without going through taskStateFromJSON.

A side effect worth calling out: an unknown status previously deserialized to protobufjs' synthetic UNRECOGNIZED (-1) sentinel and silently matched nothing, on every transport. That silent-empty behavior is now a malformed request (-32602 / HTTP 400) everywhere.

The transport handlers are back to plain parse-and-forward; their specs now assert pass-through of the parsed value plus correct mapping of a handler-raised RequestMalformedError, and handler-level specs cover both unrecognized strings and out-of-range numbers. All checks green on the updated head.

@JakubWorek
JakubWorek merged commit a881fae into a2aproject:main Aug 27, 2026
16 checks passed
bartek-gralewicz added a commit that referenced this pull request Sep 18, 2026
🤖 I have created a release *beep* *boop*
---


## [1.2.0](v1.1.0...v1.2.0)
(2026-09-18)


### Features

* **server:** Introduce SettleByTaskId method
([#692](#692))
([e856bda](e856bda))


### Bug Fixes

* accept GetExtendedAgentCard JSON-RPC calls with omitted params
([#687](#687))
([047d970](047d970))
* avoid mutating caller message configuration
([#725](#725))
([e3a6428](e3a6428))
* **client:** cache the extended Agent Card only after signature
verification ([#711](#711))
([55b601c](55b601c))
* guard terminal state transitions and make cancelTask atomic
([#636](#636))
([7b87c94](7b87c94))
* preserve call context for JSON-RPC tenant requests
([#708](#708))
([ae20aca](ae20aca))
* preserve HeadersInit in authenticating fetch
([#721](#721))
([f8c33fa](f8c33fa))
* preserve historyLength=0 and reject invalid REST listTasks pageSize
([#685](#685))
([32c1865](32c1865))
* reject empty task IDs with RequestMalformedError in getTask/cancelTask
([#629](#629))
([71aae97](71aae97))
* reject invalid ListTasks status filters with RequestMalformedError
([#631](#631))
([a881fae](a881fae))
* reject missing required extensions before mutating task history
([#690](#690))
([3b4ef3f](3b4ef3f))
* reject whitespace-only taskId on sendMessage
([#689](#689))
([85227a0](85227a0))
* return 404/-32001 for missing push notification configs
([#630](#630))
([34f06e3](34f06e3))
* scope ExecutionEventBusManager by tenant and owner to match TaskStore
([#707](#707))
([69d8899](69d8899))
* stamp the resolved taskId onto sendMessage push configs
([#688](#688))
([cfb19a8](cfb19a8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Bartek Gralewicz <[email protected]>
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.

2 participants