fix: apply historyLength trimming on tasks/resubscribe snapshot - #628
Open
ez-lbz wants to merge 4 commits into
Open
fix: apply historyLength trimming on tasks/resubscribe snapshot#628ez-lbz wants to merge 4 commits into
ez-lbz wants to merge 4 commits into
Conversation
ez-lbz
force-pushed
the
fix/resubscribe-history-trim
branch
from
August 10, 2026 16:43
040d533 to
6daa921
Compare
🧪 Code Coverage
Generated by coverage-comment.yml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
1. Apply
historyLengthtrimming ontasks/resubscribesnapshotProblem:
resubscribeyielded the full stored task without applying_applyHistoryLengthSemantics, unlikegetTaskandlistTasks. A client that reconnects withhistoryLengthexpecting a trimmed snapshot receives the entire task history, defeating thehistoryLengthinformation-disclosure protection (CWE-200). The canonicalSubscribeToTaskRequestwire type has nohistoryLengthfield, and thesrc/types/pb/a2a.ts/src/grpc/pb/a2a.tsfiles are generated from the upstream A2A proto (viabuf generate), so the field is carried at the handler/transport layer instead of editing the generated files.Fix (src/server/request_handler/default_request_handler.ts):
resubscribenow acceptsSubscribeToTaskRequest & { historyLength?: number }and applies_applyHistoryLengthSemanticsto the initial Task snapshot before yielding it.historyLength(non-negative integer) and throwsRequestMalformedErrorforNaN/negative values — aNaNwould previously bypass the<= 0check andslice(-NaN)→slice(0)would return the full history.Fix (src/server/request_handler/a2a_request_handler.ts):
A2ARequestHandler.resubscribesignature widened toSubscribeToTaskRequest & { historyLength?: number }(optional field, backward-compatible for all existing call sites).Fix (src/server/transports/rest/rest_transport_handler.ts):
resubscribe(taskId, context, tenant?, historyLength?)parses the optional query value with the existingparseHistoryLengthand forwards it to the handler.Fix (src/server/express/rest_handler.ts):
GET/POST /tasks/:taskId:subscribepassesreq.query.historyLengththrough to the transport.Fix (src/server/transports/jsonrpc/jsonrpc_transport_handler.ts):
SubscribeToTaskextractsparams.historyLengthfrom the raw JSON-RPC params (dropped bySubscribeToTaskRequest.fromJSON) and attaches it to the request passed toresubscribe.Note: the gRPC transport cannot carry
historyLength— the gRPCSubscribeToTaskRequestproto message has nohistory_lengthfield (field 3 is unset insrc/grpc/pb/a2a.ts), so the trimming is applied only for REST/JSON-RPC, matching the field's absence on the wire.Testing
npx vitest run test/server/request_handler/resubscribe.spec.ts test/server/rest_transport_handler.spec.ts test/server/jsonrpc_transport_handler.spec.ts— all pass.historyLength=0omits history entirely, non-integer rejection, negative rejection (resubscribe.spec.ts); REST passthrough and REST validation of the parsed value (rest_transport_handler.spec.ts).npx tsc --noEmitpasses.Behavior change:
tasks/resubscribenow honors an optionalhistoryLengthquery param (REST) /params.historyLength(JSON-RPC); invalid values are rejected with-32602/400. WhenhistoryLengthis absent, behavior is unchanged.