← Back to Pull requests

fix(remoteagent): cancel A2A task after early context cancellation #1324

Open
unknown opened this pull request with 325 lines diff across 4 files
View on GitHub
unknown unknown commented on Aug 13, 2026 07:26 UTC
Author

Linked issue

Closes #1076.

Canceling an invocation before the first A2A task event arrives can leave the remote task running because the client does not yet know its ID. This change briefly keeps the stream open to obtain a cleanup target and cancel the task, without emitting further session events or running response callbacks during that wait.

Behavior change

The wait is limited to five seconds and respects the caller's deadline. If the deadline expires before task information arrives, cleanup cannot discover the task. Terminal tasks and final message responses are left alone; an artifact's task ID can be used when no task state is available.

The default CancelTask call uses the remaining cleanup budget if at least 100 ms remain; otherwise, it gets a detached five-second timeout. Cleanup can therefore extend beyond the caller's deadline. These timing values are still awaiting maintainer feedback.

Non-streaming responses now retain their cleanup target too: working tasks are canceled, while completed tasks and input-required tasks without an error are preserved.

Unlike adk-python, which closes the stream without this wait, Go keeps it open briefly to recover the task ID needed for cleanup. No public API or dependency changes are introduced.

Testing Plan

  • Full workspace build and race tests passed after merging main, along with lint (v2.3.1) and tidy checks in both modules. Tests cover early cancellation, deadlines, final responses, and non-streaming cleanup.

  • Removing authentication context propagation makes TestRemoteAgent_AuthCleanupReusesTheInvocationCredential fail; restoring it makes the test pass.

  • Local A2A servers confirmed that cancellation reaches the remote task. The two-server reproduction and log and near-deadline measurements are in the discussion. These manual runs predate the latest main merge.
  • Checklist

  • I have read CONTRIBUTING.md.

  • I have performed a self-review of my own code.

  • I have commented my code, particularly in hard-to-understand areas.

  • I have added tests that prove my fix is effective.

  • New and existing unit tests pass locally with my changes.

  • I have manually tested my changes end-to-end.

  • No dependent changes are required.
  • Diff: 325 lines (+243 / -82) across 4 files Reviewer: ktsoator Review duration: 82471m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.49) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 325 lines diff across 4 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.346
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1324"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 49% (MEDIUM) · Higher = larger blast radius
    49%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 27.1% · Safe to merge
    27.1%
    Repository