Repository navigation
Conversation
redhat-chai-bot
left a comment
There was a problem hiding this comment.
Review: fix(rest): handle resource paths and intercepted fields
Nice work on this PR — it addresses an important gap by validating and URL-encoding resource identifiers before they reach the wire, and aligns the v0.3 compat transport with the interceptor model. Test coverage is thorough.
Summary of changes
v1.0 RestTransport:
- All task/config IDs are now validated via
HttpEndpoint.checkPathSegment()early, before building the request proto. This rejects path-traversal inputs (empty,.., path separators). - All IDs inserted into URL paths are percent-encoded via
HttpEndpoint.pathSegment(). buildListTasksQueryStringandbuildListPushNotificationConfigsQueryStringnow derive query parameters entirely from the intercepted/effective proto, dropping the separateoriginalparameter. Default/empty values (emptycontextId,UNSPECIFIEDstatus, emptypageToken) are no longer sent over the wire.- Pagination logic is extracted into a reusable
addPagination()helper.
v0.3 compat RestTransport_v0_3:
- The generic
resourceUrl(name)is replaced by specifictaskUrl(name),taskUrlFromId(id),configUrl(name)methods that parse resource names into their structural components and rebuild URLs with proper encoding. - New resource-name construction helpers (
taskName,pushNotificationConfigName) and parsing (taskIdFromName,configNameSegments,resourceSegments). alignPushConfigurationName()ensures the wire body'sparentandconfig.namefields match the intercepted parent + configId, not whatever was in the original request.- Pagination parameters are dropped from v0.3 push config list requests (aligning with v0.3 spec behavior).
PayloadAndHeaders_v0_3.getHeaders()null checks removed — safe becausePayloadAndHeaders_v0_3already mapsnull→Collections.emptyMap()in its constructor.- Import cleanup and Javadoc improvements.
Tests:
RestInterceptorWireTest: verifies that explicit-defaultListTasksParamsno longer sends default values as query params.RestTransport_v0_3_Test: major expansion — parameterized@ValueSource/@MethodSourcetests, a new in-processHttpServercapture test (createPushConfigurationUsesInterceptedRawIdsInBodyAndEncodesUrl) verifying URL encoding for special characters likecafé%2Eandjalapeño%2f, and verification that wire body fields are aligned after interception.
Observations
-
Behavioral change in query string construction (v1.0): The old
buildListTasksQueryStringhad a secondary code path that sent explicitly-set default values (emptycontextId,UNSPECIFIEDstatus, emptypageToken) over the wire. The new version omits these since proto defaults are indistinguishable from "not set." This is cleaner, but it is a subtle behavioral change — worth confirming no server implementation relies on receiving these explicit defaults. -
%1sformat specifier: Pre-existing, not introduced here —String.format("/tasks/%1s", ...)effectively means "minimum width 1," which is a no-op for any non-empty string. Consider using plain%sfor clarity in a future cleanup.
Overall this looks solid. The security hardening (path traversal prevention, URL encoding) is important, the interceptor alignment is correct, and the test coverage validates the key edge cases well.
Chai persona: A2A Java SDK
AI-generated. Review for accuracy.
bccd54f to
68f0263
Compare
| @Override | ||
| public Task getTask(TaskQueryParams taskQueryParams, @Nullable ClientCallContext context) throws A2AClientException { | ||
| checkNotNullParam("taskQueryParams", taskQueryParams); | ||
| HttpEndpoint.checkPathSegment(taskQueryParams.id()); |
There was a problem hiding this comment.
AIUI, HttpEndpoint.checkPathSegment check that the param can not be empty, . or .... This must be true regardless of the transport for the various IDs that are checked.
Would it be possible to "move up" this check so that it is verified on any transport?
There was a problem hiding this comment.
I did not find a rule there prohibiting ", /, , ?, . or ..across transports. Moving the entire check into the shared records would therefore reject IDs that JSON-RPC or gRPC may currently accept. It would also affect server-side code that constructs those records.
There was a problem hiding this comment.
I don't understand. IDs (for tasks and requests) must be valid regardless of the transport types, right?
It's valid to create a task with one transport (eg gRPC) and then query it later from REST.
There was a problem hiding this comment.
So there is a gap in the specs then as this should be covered. I'll move that up
There was a problem hiding this comment.
@jmesnil this has quite an impact on the server side thought
There was a problem hiding this comment.
the 2nd commit fixes that but is it quite a big change
| */ | ||
| public TaskPushNotificationConfig { | ||
| Assert.checkNotNullParam("url", url); | ||
| if (taskId != null && !taskId.isEmpty()) { |
There was a problem hiding this comment.
I don't understand, why the call to ResourceIdValidation.check is gated. Isn't this method supposed to check the validity of the parameter?
| assertEquals( | ||
| "GET /defaulttenant/tasks?contextId=&status=TASK_STATE_UNSPECIFIED&pageToken=", | ||
| queue.poll(5, TimeUnit.SECONDS)); | ||
| assertEquals("GET /defaulttenant/tasks", queue.poll(5, TimeUnit.SECONDS)); |
There was a problem hiding this comment.
is the change in the assertion correct?
There was a problem hiding this comment.
contextId, status, and pageToken are protobuf scalar fields without presence tracking. After conversion, the transport cannot distinguish an explicitly supplied default value from a field an interceptor cleared. It now treats "" and TASK_STATE_UNSPECIFIED as unset and sends /tasks.
The adjacent test verifies that cleared fields are omitted too. See RestTransport.java (client/transport/rest/src/main/java/org/a2aproject/sdk/client/transport/rest/RestTransport.java:294).
The assertion and the query-serialization behavior changed in its parent commit, 68f0263 (fix(rest): handle resource paths and intercepted fields). So the behavior change is part of the branch, but it predates the current commit.
|
|
||
| import static org.a2aproject.sdk.util.Assert.checkNotNullParam; | ||
|
|
||
| import org.a2aproject.sdk.client.http.A2AHttpClientConfiguration; |
There was a problem hiding this comment.
this PR is already big enough and having sorted the import in it makes it even more difficult to properly review...
| @@ -46,13 +47,7 @@ public static String pathSegment(@Nullable String value) { | |||
| * @throws IllegalArgumentException if the identifier is empty or ambiguous | |||
| */ | |||
| public static void checkPathSegment(@Nullable String value) { | |||
There was a problem hiding this comment.
this method can be removed and Assert.checkResourceId(value) used directly.
| */ | ||
| public CancelTaskParams { | ||
| Assert.checkNotNullParam("id", id); | ||
| ResourceIdValidation.check(id); |
There was a problem hiding this comment.
we are losing the name of the parameter if its value is no longer valid. Is that ok?
| return new DeleteTaskPushNotificationConfigParams( | ||
| Assert.checkNotNullParam("taskId", taskId), | ||
| Assert.checkNotNullParam("id", id), | ||
| ResourceIdValidation.require(taskId), |
There was a problem hiding this comment.
why require here and check above?
There was a problem hiding this comment.
Because of the builder pattern the id is nullable here and not in the constructor
e3fec11 to
6a5558c
Compare
redhat-chai-bot
left a comment
There was a problem hiding this comment.
Re-review: fix(rest): handle resource paths and intercepted fields (rewritten)
This is a substantial and welcome rewrite — expanding from 4 files to 32, with validation moved from the REST transport layer up to the shared spec/param layer. The architecture is sound.
Architecture summary
The PR now establishes a clean three-layer validation design:
-
Assert.checkResourceId(name, value)(common module) — the low-level primitive that rejectsnull, empty,.,.., and IDs containing/,\,?, or#. ThrowsIllegalArgumentException. -
ResourceIdValidation.check(name, id)(v1.0 spec) /ResourceIdValidation_v0_3.check(name, id)(v0.3 spec) — package-private wrappers that catchIllegalArgumentExceptionand rethrow asInvalidParamsError/InvalidParamsError_v0_3. This translates low-level validation into the protocol-appropriate error type. -
Parameter records (
TaskIdParams,CancelTaskParams,TaskQueryParams,DeleteTaskPushNotificationConfigParams, etc.) — now callResourceIdValidation.check()in their constructors and builders. IDs are validated at construction time, before any transport touches them.
This is the right decision. As jmesnil pointed out, IDs must be valid regardless of transport — a task created via gRPC and queried via REST should work, so validating at the spec level catches problems early and uniformly.
Transport simplification: HttpEndpoint.checkPathSegment() is removed entirely. pathSegment(name, value) now delegates to Assert.checkResourceId() for validation, then percent-encodes. The validation is technically redundant at this point (already done at param construction) but serves as defense-in-depth.
What looks good
- Consistent pattern across all param records. Every record that takes a resource ID now validates it the same way. The
ResourceIdValidation/ResourceIdValidation_v0_3wrappers ensure the right error type at the right layer. - Comprehensive test coverage.
ResourceIdValidationTestandResourceIdValidation_v0_3_Testverify that all param record types reject the same set of invalid IDs (null, empty,.,.., IDs with/,\,?,#). - Server-side test updates. Tests in
JSONRPCUtilsTest,GrpcHandlerTest,RestHandlerTestetc. now use valid IDs (e.g."test-task"instead of"."or""), ensuring they don't accidentally trip the new validation. - Mapper cleanups.
TaskPushNotificationConfigMapper_v0_3.toV10PushConfig()extraction is cleaner.MessageSendConfigurationMapper_v0_3now passesnullfor taskId instead of"", which is correct — a null taskId is semantically "not set," while""would now fail validation. - v0.3
PushNotificationConfig_v0_3test. The test verifies that null/emptyidis accepted (auto-assignment) while invalid IDs are rejected. This is an important edge case.
Comments on jmesnil's open threads
Gated validation in TaskPushNotificationConfig: The gating (if (taskId != null && !taskId.isEmpty())) is correct here because taskId and id are @Nullable with semantic meaning: null/empty taskId means "not associated with a task yet" (e.g. MessageSendConfiguration path), and null/empty id means "server should auto-assign." The check ensures that if a value is provided, it's a valid resource ID. A brief doc comment explaining this would help future readers.
Parameter name change ("id" → "taskId"): The old Assert.checkNotNullParam("id", id) used the Java field name; the new ResourceIdValidation.check("taskId", id) uses the protocol-level name. This is a user-facing error message change but arguably an improvement — when the user sees "Invalid path identifier for 'taskId'" it maps directly to the protocol concept. Worth documenting that parameter names in error messages reflect the protocol role, not the Java field.
Minor observations
-
v1.0
ResourceIdValidation.check()returnsString; v0.3ResourceIdValidation_v0_3.check()returnsvoid. The v1.0 version returns the validated ID for fluent chaining in constructors, while v0.3 uses it as a side-effect check. This works but is a subtle asymmetry between the two versions. -
Import sorting in
RestTransport_v0_3.javadoes add noise to the diff, as jmesnil noted. Not a blocker but makes the diff harder to review in the short term. -
Retained validation in
HttpEndpoint.pathSegment(): Since all param records already validate IDs, theAssert.checkResourceId()call inpathSegment()is defense-in-depth. This is fine — belt-and-suspenders is appropriate for security-sensitive URL construction.
Overall this is a well-structured improvement that moves validation to the right architectural layer with solid test coverage. 👍
Chai persona: A2A Java SDK
AI-generated. Review for accuracy.
0bc9421 to
5e183ca
Compare
kabir
left a comment
There was a problem hiding this comment.
- [P1] Preserve access to existing task IDs. The shared constructors now reject IDs that Task and TaskStore still accept. A task with an ID such as job?east can already exist or still be returned by an agent, but the upgraded SDK rejects GetTask for it before lookup, including over JSON-RPC and gRPC. Keep the restriction at the REST boundary, or define how existing IDs remain addressable and enforce the new rule when IDs are assigned. TaskQueryParams.java:25 · InMemoryTaskStore.java:121
- [P2] Preserve the explicit TASK_STATE_UNSPECIFIED filter. The REST server and task store treat this value as a concrete state filter. The old client emitted it when explicitly requested. The new client omits it, so a query for tasks in that state can return tasks in every state. Preserve field presence through interception so an explicit filter and a cleared filter produce distinct URLs. RestTransport.java:299 · InMemoryTaskStore.java:152
- [P2] Resolve empty v0.3 config IDs to the default. The request record accepts "", and the server documents empty and omitted IDs as selecting the default configuration. The client falls back to the task ID only for null, so "" now throws IllegalArgumentException before the interceptor runs. Apply the same fallback to both values. RestTransport_v0_3.java:239 · RestHandler_v0_3.java:255
- [P2] Keep interceptor-supplied v0.3 pagination. The v0.3 protobuf REST binding exposes page_size and page_token. Dropping both from the URL means a client that uses an interceptor to request a later page will receive the first page again from a server that implements pagination. RestTransport_v0_3.java:273 · v0.3 protobuf request
Validate task and push configuration IDs in shared request records, and encode REST path segments using intercepted values. Invalid required IDs now raise InvalidParamsError; HttpEndpoint.pathSegment requires an identifier name. Build pagination from intercepted requests, preserve explicit unspecified status filters, and default missing v0.3 configuration IDs to the task ID. Omit empty list-task context and page tokens and v0.3 push-configuration pagination. Preserve v0.3 message push configuration conversion when the task has not yet been created. Signed-off-by: Emmanuel Hugonnet <[email protected]>
5e183ca to
70ae1d8
Compare
Validate and encode task and push notification configuration identifiers in REST URLs. Build request URLs and pagination from intercepted values, and align v0.3 push configuration names with the intercepted parent and configuration ID.
Cover interceptor changes and encoded identifiers in both REST transports. Omit pagination parameters from v0.3 push configuration list requests.