← Back to Pull requests

feat(a2asrv): long-poll GetTask with currentGeneration #662

Merged
polchernikova-w merged 3 files (150 lines) on Dec 04, 2026 14:40 UTC
View on GitHub
polchernikova-w polchernikova-w commented on Dec 02, 2026 13:08 UTC
Author

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's generation is less than or equal to it, the server holds the request until the generation advances. Otherwise it returns right away.
  • Changes

  • GetTask waits through Resubscribe (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.

  • New option a2asrv.WithLongPollTimeout(d), default 30s, 0 or less turns it off. The request context also bounds the hold.
  • Requests without currentGeneration behave as before.

    Diff: 150 lines (+144 / -6) across 3 files Reviewer: yarolegovich Review duration: 2971m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.36) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 150 lines diff across 3 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.83 · 5 substantive comment(s)
    0.83
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.300
    Real PR Conversation Timeline
    9 items
    Shay-Deng Shay-Deng commented on Dec 02, 2026 15:25 UTC
    Reviewer

    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.

    yarolegovich yarolegovich commented on code on Dec 02, 2026 16:21 UTC
    Code Review
    a2asrv/handler.go:1
    @@ -302,9 +315,48 @@ func (h *defaultRequestHandler) GetTask(ctx context.Context, req *a2a.GetTaskReq
     		return nil, fmt.Errorf("failed to get task: %w", err)
     	}
     
    -	task := trimTaskHistory(storedTask.Task, req.HistoryLength)
    +	if cur := req.CurrentGeneration; h.longPollTimeout > 0 && cur != nil && storedTask.Task.Generation <= *cur && !storedTask.Task.Status.State.Terminal() {
    +		h.waitForGeneration(ctx, taskID, *cur)
    +		if storedTask, err = h.taskStore.Get(ctx, taskID); err != nil {
    +			return nil, fmt.Errorf("failed to load task after long-poll: %w", err)
    +		}
    +	}
    +
    +	return trimTaskHistory(storedTask.Task, req.HistoryLength), nil
    +}
    +
    +func (h *defaultRequestHandler) waitForGeneration(ctx context.Context, taskID a2a.TaskID, after a2a.TaskGeneration) {
    +	ctx, cancel := context.WithTimeout(ctx, h.longPollTimeout)
    +	defer cancel()
    +
    +	sub, err := h.execManager.Resubscribe(ctx, taskID)
    +	if err != nil {
    +		log.Debug(ctx, "long-poll resubscribe failed", "error", err)
    +		return
    +	}
    +	for ev, err := range sub.Events(ctx) {
    +		if err != nil {
    +			log.Debug(ctx, "long-poll subscription ended", "error", err)

    nit: cancelled, ended reads as if normally

    yarolegovich yarolegovich commented on code on Dec 02, 2026 16:23 UTC
    Code Review
    a2asrv/handler.go:1
    @@ -302,9 +315,48 @@ func (h *defaultRequestHandler) GetTask(ctx context.Context, req *a2a.GetTaskReq
     		return nil, fmt.Errorf("failed to get task: %w", err)
     	}
     
    -	task := trimTaskHistory(storedTask.Task, req.HistoryLength)
    +	if cur := req.CurrentGeneration; h.longPollTimeout > 0 && cur != nil && storedTask.Task.Generation <= *cur && !storedTask.Task.Status.State.Terminal() {
    +		h.waitForGeneration(ctx, taskID, *cur)
    +		if storedTask, err = h.taskStore.Get(ctx, taskID); err != nil {
    +			return nil, fmt.Errorf("failed to load task after long-poll: %w", err)
    +		}
    +	}
    +
    +	return trimTaskHistory(storedTask.Task, req.HistoryLength), nil
    +}
    +
    +func (h *defaultRequestHandler) waitForGeneration(ctx context.Context, taskID a2a.TaskID, after a2a.TaskGeneration) {
    +	ctx, cancel := context.WithTimeout(ctx, h.longPollTimeout)
    +	defer cancel()
    +
    +	sub, err := h.execManager.Resubscribe(ctx, taskID)
    +	if err != nil {
    +		log.Debug(ctx, "long-poll resubscribe failed", "error", err)
    +		return
    +	}
    +	for ev, err := range sub.Events(ctx) {
    +		if err != nil {
    +			log.Debug(ctx, "long-poll subscription ended", "error", err)
    +			return
    +		}
    +		if eventGeneration(ev) > after {
    +			return
    +		}
    +	}
    +}
     
    -	return task, nil
    +func eventGeneration(event a2a.Event) a2a.TaskGeneration {

    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)

    yarolegovich yarolegovich commented on code on Dec 02, 2026 16:24 UTC
    Code Review
    a2asrv/handler.go:1
    @@ -302,9 +315,48 @@ func (h *defaultRequestHandler) GetTask(ctx context.Context, req *a2a.GetTaskReq
     		return nil, fmt.Errorf("failed to get task: %w", err)
     	}
     
    -	task := trimTaskHistory(storedTask.Task, req.HistoryLength)
    +	if cur := req.CurrentGeneration; h.longPollTimeout > 0 && cur != nil && storedTask.Task.Generation <= *cur && !storedTask.Task.Status.State.Terminal() {
    +		h.waitForGeneration(ctx, taskID, *cur)
    +		if storedTask, err = h.taskStore.Get(ctx, taskID); err != nil {

    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

    yarolegovich yarolegovich approved these changes on Dec 02, 2026 16:31 UTC
    Approved Reviewer

    Approved these changes.

    polchernikova-w polchernikova-w commented on Dec 03, 2026 14:25 UTC
    Author

    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.

    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.

    polchernikova-w polchernikova-w commented on code on Dec 03, 2026 14:26 UTC
    Code Review
    a2asrv/handler.go:1
    @@ -302,9 +315,48 @@ func (h *defaultRequestHandler) GetTask(ctx context.Context, req *a2a.GetTaskReq
     		return nil, fmt.Errorf("failed to get task: %w", err)
     	}
     
    -	task := trimTaskHistory(storedTask.Task, req.HistoryLength)
    +	if cur := req.CurrentGeneration; h.longPollTimeout > 0 && cur != nil && storedTask.Task.Generation <= *cur && !storedTask.Task.Status.State.Terminal() {
    +		h.waitForGeneration(ctx, taskID, *cur)
    +		if storedTask, err = h.taskStore.Get(ctx, taskID); err != nil {
    +			return nil, fmt.Errorf("failed to load task after long-poll: %w", err)
    +		}
    +	}
    +
    +	return trimTaskHistory(storedTask.Task, req.HistoryLength), nil
    +}
    +
    +func (h *defaultRequestHandler) waitForGeneration(ctx context.Context, taskID a2a.TaskID, after a2a.TaskGeneration) {
    +	ctx, cancel := context.WithTimeout(ctx, h.longPollTimeout)
    +	defer cancel()
    +
    +	sub, err := h.execManager.Resubscribe(ctx, taskID)
    +	if err != nil {
    +		log.Debug(ctx, "long-poll resubscribe failed", "error", err)
    +		return
    +	}
    +	for ev, err := range sub.Events(ctx) {
    +		if err != nil {
    +			log.Debug(ctx, "long-poll subscription ended", "error", err)
    +			return
    +		}
    +		if eventGeneration(ev) > after {
    +			return
    +		}
    +	}
    +}
     
    -	return task, nil
    +func eventGeneration(event a2a.Event) a2a.TaskGeneration {

    eventGeneration is the only reader today, so I'd keep it private for now and revisit if more callers appear.

    Shay-Deng Shay-Deng commented on Dec 03, 2026 15:24 UTC
    Contributor

    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.

    Reviewers
    Assignees
    polchernikova-w polchernikova-w
    Labels
    risk: low confidence: 87.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.9% (MEDIUM) · Higher = larger blast radius
    35.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.2% · Lower = rushed or shallow review
    87.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.6% · Safe to merge
    4.6%