Skip to content

test(remotagent) deflake a2a cleanup propagation#1131

Open
wolo-lab wants to merge 3 commits into
mainfrom
wolo/fix-a2a-cleanup-propagation-flake
Open

test(remotagent) deflake a2a cleanup propagation#1131
wolo-lab wants to merge 3 commits into
mainfrom
wolo/fix-a2a-cleanup-propagation-flake

Conversation

@wolo-lab

@wolo-lab wolo-lab commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix the panic + flakiness in TestA2ACleanupPropagation (agent/remoteagent/v2/a2a_e2e_test.go)
  • Join the detached streaming/cancel goroutines so neither logs on t after the test completes.
  • Make cancellation-propagation deterministic by cancelling only once the remote subagent's output has round-tripped to the client (i.e. once the remote agent actually knows the subagent task ID).
    Test-only change; no production code is modified.

Background / root cause

The test exercised two failure modes:

  1. Panic — Log in goroutine after test has completed. The CancelTask
    goroutine was never joined (cancelResultChan was created but never read),
    so under load it could still be mid-RPC when the test returned, fail on the
    cancelled t.Context(), and call t.Errorf on a finished test.
  2. remote cleanup was not called. This was not merely a too-tight
    timeout. Via goroutine dumps + tracing I confirmed the test cancelled the
    parent task right after the first status event — i.e. before the remote
    agent had received any event from the subagent
    . In that window the remote
    agent doesn't yet know the subagent's (server-assigned) task ID, so
    cleanupRemoteTask returns early (lastEvent == nil) and cannot propagate
    the cancellation. Under GOMAXPROCS=1 / CPU contention this race was lost
    deterministically, so the subagent task kept running and its cleanup never
    fired.

What changed

  • sync.WaitGroup + t.Cleanup(wg.Wait) join both detached goroutines before the test tears down (fixes the panic in all exit paths).
  • Replaced the single fixed time.After(5s) shared across all cleanup-channel reads with a per-wait, contention-tolerant helper awaitN.
  • The test now waits until the subagent's own artifact reaches the client before issuing the cancel. That is the precondition for propagation to be possible, so the (unchanged) propagation assertions become deterministic. Only the moment of cancellation is corrected — the test still exercises the full path.

Note on scope (best-effort propagation)

adk-go's remote-task cancellation propagation (cleanupRemoteTask) is an
additive, best-effort feature; adk-python's remote A2A agent does not cancel
remote tasks at all. Cancelling in the window before the remote agent has
received its first subagent event genuinely cannot propagate (the remote task
ID is unknown to the caller). This PR fixes the flaky test to respect that
contract; making propagation robust in that early-cancel window would be a
separate, behaviour-changing effort (client-assigned task IDs and/or a2a-go
support) and is intentionally out of scope here.

@wolo-lab wolo-lab changed the title Wolo/fix a2a cleanup propagation flake fix(flakiness) deflake a2a cleanup propagation Jul 8, 2026
@wolo-lab wolo-lab force-pushed the wolo/fix-a2a-cleanup-propagation-flake branch 2 times, most recently from 2636074 to f99c4cb Compare July 8, 2026 12:42
Under CPU contention / low parallelism the test hit two problems:

- The detached CancelTask goroutine was never joined (cancelResultChan was
  created but never read), so a slow RPC could still be in flight at teardown,
  fail on the cancelled t.Context(), and call t.Errorf on a finished test,
  which panics. Both detached goroutines are now joined via a WaitGroup and
  t.Cleanup.

- The parent was cancelled right after the first status event, before the
  remote agent had received any subagent event. In that window the parent does
  not know the subagent's server-assigned task ID, so cancellation cannot
  propagate and subagent cleanup never fires. The test now waits until the
  subagent's own output round-trips to the client before cancelling. The single
  fixed 5s deadline shared across all cleanup waits is also replaced with a
  per-wait, contention-tolerant bound.

Test-only change.
@wolo-lab wolo-lab force-pushed the wolo/fix-a2a-cleanup-propagation-flake branch from f99c4cb to dccbf00 Compare July 8, 2026 12:52
@wolo-lab wolo-lab requested a review from yarolegovich July 8, 2026 14:40
@wolo-lab wolo-lab marked this pull request as ready for review July 8, 2026 14:40
@wolo-lab wolo-lab changed the title fix(flakiness) deflake a2a cleanup propagation test(remotagent) deflake a2a cleanup propagation Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant