[Bug]: REST transport: getTask builds an invalid URL for single-digit historyLength
Maintainer thường phản hồi trong vòng 1 ngày
@014-code đang làm issue này rồi.
Từ ngày 2/10/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Bắt đầu tại client/transport/rest/src/main/java/io/a2aproject/a2a/client/transport/rest/RestTransport.java, ở getTask, và kiểm tra định dạng URL. Chạy RestTransportTest.testGetTask với historyLength có một chữ số, chẳng hạn như 5, sau đó bổ sung phạm vi kiểm thử hồi quy cho thấy URI được tạo là hợp lệ và truy vấn không có phần đệm; chuẩn hóa các chuỗi định dạng liên quan nếu chúng được đưa vào thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened?
Summary
RestTransport.getTask builds the request URL with a String.format pattern that uses width specifiers (%2d) where argument-index specifiers (%2$d) were intended. For a single-digit historyLength (0–9), %2d left-pads the value with a space, producing historyLength= 5. A raw space is illegal in a URI, so java.net.URI.create(...) throws IllegalArgumentException: Illegal character in query, and the getTask call fails before any request is sent.
Affected code
client/transport/rest/src/main/java/io/a2a/client/transport/rest/RestTransport.java, in getTask:
url.append(String.format("/tasks/%1s?historyLength=%2d", taskQueryParams.id(), taskQueryParams.historyLength()));
In Java format syntax, an argument index requires a trailing $ (%2$d). Without it, %2d means "decimal, minimum width 2", and %1s means "string, minimum width 1" — these are width fields, not argument references. The %1s on the id is harmless only by accident (a UUID is always wider than 1, so nothing is padded); the %2d on the integer pads any single-digit value.
Reproduction
String.format("/tasks/%1s?historyLength=%2d", "de38c76d-d54c-436c-8b9f-4c2703648d64", 5);
// => "/tasks/de38c76d-d54c-436c-8b9f-4c2703648d64?historyLength= 5"
// ^ stray space
URI.create("https://host/tasks/de38c76d-d54c-436c-8b9f-4c2703648d64?historyLength= 5");
// => java.lang.IllegalArgumentException: Illegal character in query at index N: ...historyLength= 5
Behavior by value:
| historyLength | formatted query | valid URI? |
|---|---|---|
| 1–9 | historyLength= N (leading space) |
❌ |
| 0 | n/a — getTask skips the query when historyLength <= 0 |
✅ |
| ≥ 10 | historyLength=NN |
✅ |
So any getTask call with historyLength in 1–9 fails. This is the common case (clients typically request a small history window), which makes the practical impact high.
Why existing tests don't catch it
RestTransportTest.testGetTask uses new TaskQueryParams("...", 10) — a two-digit value that satisfies the width-2 field, so no space is injected and the URL stays valid. Single-digit values are never exercised.
Suggested fix
Drop the width (preferred) or use real positional indices:
// simplest
url.append(String.format("/tasks/%s?historyLength=%d", taskQueryParams.id(), taskQueryParams.historyLength()));
// or, if explicit indices are desired
url.append(String.format("/tasks/%1$s?historyLength=%2$d", taskQueryParams.id(), taskQueryParams.historyLength()));
Also recommend adding a regression test that calls getTask with a single-digit historyLength (e.g. 5) and asserts the resulting URL/query is well-formed.
Related occurrences (same specifier mistake, latent)
The same %Ns width-vs-index pattern appears on other URL-building sites in RestTransport.java (e.g. /tasks/%1s:cancel, /tasks/%1s/pushNotificationConfigs/%2s, /tasks/%1s:subscribe). These don't currently misbehave because their arguments are strings whose length exceeds the width, so no padding occurs — but they're the same bug waiting on a short/empty value and would be worth normalizing to %s in the same change.
Environment
- Observed on the v1.x line (
org.a2aproject.sdk) and the v0.3 line (io.github.a2asdk:0.3.3.Final); both contain the identicalhistoryLength=%2dline, and it is still present on the latestmain. - Transport: HTTP+JSON (REST). JSON-RPC transport is unaffected (it doesn't build this query).
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
- Ngôn ngữ chính
- Java
- Star
- 505
- Fork
- 185
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của a2aproject/a2a-java
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
a2aproject/a2a-java#1012 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
a2aproject/a2a-java#464 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Create a sample that demonstrates how to use a shared contextId across multiple tasksCó thể làm lại được @tanish111 đã nhận 359 ngày trước và không có pull request nào đang mở. Đang mởsample
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
a2aproject/a2a-java#375 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
a2aproject/a2a-java#1222 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
No structured payload loggingĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
a2aproject/a2a-java#1221 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của a2aproject/a2a-java
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
MCModderAnchor/TACZ#758 ·
-
agent-java community triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
elastic/apm-agent-java#4594 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/plugin good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
kestra-io/plugin-soda#137 ·
-
area/plugin good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
kestra-io/plugin-aws#816 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area/plugin good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
kestra-io/plugin-kestra#200 ·
Maintainer thường phản hồi trong vòng 1 ngày