Skip to content

fix: reject empty task IDs with RequestMalformedError in getTask/cancelTask - #629

Merged
JakubWorek merged 4 commits into
a2aproject:mainfrom
ez-lbz:fix/empty-taskid-validation
Aug 27, 2026
Merged

JakubWorek merged 4 commits into
a2aproject:mainfrom
ez-lbz:fix/empty-taskid-validation

Conversation

@ez-lbz

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

Copy link
Copy Markdown
Contributor

What changed

1. Reject empty/whitespace task IDs with RequestMalformedError in getTask/cancelTask

Problem: getTask and cancelTask passed params.id straight to taskStore.load. An empty or whitespace-only task ID therefore surfaced as TaskNotFoundError (-32001 / HTTP 404) instead of the protocol-correct RequestMalformedError (-32602 / HTTP 400). Python and Go return InvalidParams for this input; JS diverged.

Fix (src/server/request_handler/default_request_handler.ts):

  • getTask now rejects empty/whitespace-only params.id with RequestMalformedError('Task ID is required') before touching the store.
  • cancelTask applies the same validation.

Testing

  • npm test — 68 test files, 1510 tests passed.
  • npx tsc --noEmit -p tsconfig.test.json — passes.
  • New regression tests: getTask with id: '' and id: ' ' reject with RequestMalformedError; cancelTask with id: '' and id: ' \t ' reject with RequestMalformedError.

Behavior change: empty/whitespace task IDs on tasks/get and tasks/cancel now return -32602/400 instead of -32001/404. All other inputs behave as before.

@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.72% 91.83% 🟢 +0.11%
Total 91.54% 91.55% 🟢 +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/empty-taskid-validation branch from f36e552 to 742ee8a 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 empty-task-ID validation change (plus the prettier/tracking-id cleanup). All 1494 tests pass locally.

ez-lbz added 3 commits August 27, 2026 15:52
…empty task ID guard

Per review feedback, extend the empty/whitespace task ID validation
beyond getTask/cancelTask to resubscribe and the four
*TaskPushNotificationConfig methods (create/get/list/delete). The
checks are deduplicated into a shared _requireValidTaskId helper so
every task-ID entry point surfaces RequestMalformedError (-32602 /
HTTP 400) instead of TaskNotFoundError for malformed requests.
@ez-lbz
ez-lbz force-pushed the fix/empty-taskid-validation branch from 742ee8a to 5ce18ed Compare August 27, 2026 08:13
@ez-lbz

ez-lbz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion @JakubWorek — done. resubscribe and all four *TaskPushNotificationConfig methods (create/get/list/delete) are now covered. The whitespace/empty guard is deduplicated into a shared _requireValidTaskId helper used by every task-ID entry point of DefaultRequestHandler, so they all surface RequestMalformedError instead of TaskNotFoundError.

While extending coverage I also fixed a pre-existing test ("Push Notification methods should throw error if task does not exist") that was still passing legacy name:-path-style params, i.e. no real taskId field at all. It now uses the current request shapes against a genuinely non-existent task id and keeps asserting TaskNotFoundError.

All checks are green on the updated head.

@JakubWorek
JakubWorek merged commit 71aae97 into a2aproject:main Aug 27, 2026
16 checks passed
bartek-gralewicz pushed a commit that referenced this pull request Aug 28, 2026
# Description

- [x] Follow the CONTRIBUTING Guide
- [x] Conventional Commits title
- [x] Tests and linter pass
- [x] Docs updated if necessary

Fixes #683

## Summary

`_createRequestContext` used `if (incomingMessage.taskId)`, which is
true for `" "`, then loaded that id and threw TaskNotFoundError (-32001
/ 404).

getTask, cancelTask, push-config methods, and resubscribe already use
`_requireValidTaskId` after #629 and return RequestMalformedError
(-32602 / 400) for whitespace. Empty `""` stays "create new task".

If taskId is non-empty, sendMessage now runs `_requireValidTaskId`
before load.

## Testing

```
npx --no-install vitest run test/server/default_request_handler.spec.ts
```

95 passed.

Signed-off-by: Anas Khan <[email protected]>
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