feat(a2asrv): long-poll GetTask with currentGeneration #662
Thanks for this. I read it against dev-1.1 (304b9969) and ran it locally: go vet ./... and go test ./... pass on b25e362. The wake-up path looks right to me. Both subscription types open with a store snapshot, so an update that lands between the first Get and Resubscribe still ends the wait. The queue message is written after the store update, so the reload sees the new generation.
One question about the requested version. The long-poll runs whenever CurrentGeneration is set, whatever A2A-Version the caller sent. §3.6.2 says agents MUST process requests "using the semantics of the requested A2A-Version", and currentGeneration exists only from 1.1. So for a 1.0 caller, or one with no header (§3.6.2 reads that as 0.3), I would expect an immediate answer. The response side already follows the caller's version: adaptToClientVersion strips generation, so such a caller is held on a value it can't see.
A local test next to TestRequestHandler_GetTask_LongPoll (WithLongPollTimeout(2*time.Second), a working task, CurrentGeneration = 100):
client version "1.0": GetTask took 2.001s, returned generation 0
client version "": GetTask took 2.001s, returned generation 0
A version check before the wait, like the one in withCallerProtocolVersion (compat.Compare(callCtx.ClientProtocolVersion(), a2a.Version11) >= 0), would cover it. lastSeenGeneration in #663 and view in #661 raise the same question, so a shared request-side step next to adaptToClientVersion might fit better, if you prefer that. Happy to share the test file.
nit: cancelled, ended reads as if normally
nit: not sure if will be useful to clients, but we can maybe add this to Event interface. the only awkward case is a2a.Message (0 or negative)
nit: if err := ctx.Err(); err != nil { return nil, err } before calling taskStore to avoid this extra "failed to load task after long-poll" in error
Approved these changes.
Thanks for this. I read it againstdev-1.1(304b9969) and ran it locally:go vet ./...andgo test ./...pass on b25e362. The wake-up path looks right to me. Both subscription types open with a store snapshot, so an update that lands between the firstGetandResubscribestill ends the wait. The queue message is written after the store update, so the reload sees the new generation.
> One question about the requested version. The long-poll runs wheneverCurrentGenerationis set, whateverA2A-Versionthe caller sent. §3.6.2 says agents MUST process requests "using the semantics of the requestedA2A-Version", andcurrentGenerationexists only from 1.1. So for a 1.0 caller, or one with no header (§3.6.2 reads that as 0.3), I would expect an immediate answer. The response side already follows the caller's version:adaptToClientVersionstripsgeneration, so such a caller is held on a value it can't see.
> A local test next toTestRequestHandler_GetTask_LongPoll(WithLongPollTimeout(2*time.Second), a working task,CurrentGeneration= 100):
>> client version "1.0": GetTask took 2.001s, returned generation 0 > client version "": GetTask took 2.001s, returned generation 0 >
> A version check before the wait, like the one inwithCallerProtocolVersion(compat.Compare(callCtx.ClientProtocolVersion(), a2a.Version11) >= 0), would cover it.lastSeenGenerationin #663 andviewin #661 raise the same question, so a shared request-side step next toadaptToClientVersionmight fit better, if you prefer that. Happy to share the test file.
Thanks for catching this, and for the repro.
The impact of this is low, though. A client that negotiated a version below 1.1 never gets a generation back, so it has no real value to send in currentGeneration.
Fixed anyway, it's cheap and small. Both #661 (view) and #663 (lastSeenGeneration) will use the same helper after this lands.
On the shared request-side step: I kept the check in the handler, not next to adaptToClientVersion. A step in InterceptedHandler would change the request that interceptors and plugins see, and it wouldn't apply when defaultRequestHandler is called directly.
eventGeneration is the only reader today, so I'd keep it private for now and revisit if more callers appear.
Thanks, that makes sense, and agreed the impact is low. I reran my test on 8e9481a: 1.0 and header-less calls now return at once, and go test ./... passes. Keeping the check in the handler for the reason you gave sounds right to me.
yarolegovich
polchernikova-w
Part of the A2A v1.1 work. Targets
release/v1.1.v1.1 spec changes implemented
GetTaskRequest.current_generation(§3.2.7): when the task'sgenerationis less than or equal to it, the server holds the request until the generation advances. Otherwise it returns right away.Changes
GetTaskwaits throughResubscribe(local and cluster mode), then reads the task from the store again. Terminal tasks, and in local mode tasks with no active execution, return right away.a2asrv.WithLongPollTimeout(d), default 30s, 0 or less turns it off. The request context also bounds the hold.Requests without
currentGenerationbehave as before.