Skip to content

fix: preserve cancellation after interrupted execution - #588

Open
Linux2010 wants to merge 3 commits into
a2aproject:mainfrom
Linux2010:codex/fix-cancel-interrupted-execution
Open

Linux2010 wants to merge 3 commits into
a2aproject:mainfrom
Linux2010:codex/fix-cancel-interrupted-execution

Conversation

@Linux2010

Copy link
Copy Markdown

Problem

When cancellation overlaps an execution that finishes in INPUT_REQUIRED, the execution's event consumer can stop before it processes the cancellation events. This can happen either after the pipe closes or after a cancellation event is enqueued successfully but no consumer remains. CancelTask then reports that the task cannot be canceled even though the task is still interruptible.

This is the non-terminal case left open by the earlier closed-pipe fix in #521 (related to #518).

Change

  • Track whether each cancellation event is read by the running execution, without blocking the cancellation writer on consumer progress.
  • Once that execution finishes in a non-terminal state, process only the unread cancellation events against a fresh task snapshot. Do not invoke the agent's cancellation callback again.
  • Preserve the existing handling for executions that reach a terminal state, and document the handoff in the concurrency model.

Validation

  • go test ./...
  • go test -race ./internal/eventpipe ./internal/taskexec ./a2asrv ./integrations/executor/a2aacp
  • Repeated race tests cover the closed-pipe and unread-enqueued-event windows, a full pipe with no consumer, avoiding a cancel/execution deadlock, and not processing an event twice.
  • Handler tests cover streaming ending at INPUT_REQUIRED, followed by successful CancelTask and a CANCELED GetTask; mixed consumed/unread artifacts and push delivery; and an execution that reaches COMPLETED before cancellation. They also check callback and cleanup counts.

The original stream ends when execution reaches INPUT_REQUIRED; the later cancellation result is returned by CancelTask and visible through GetTask.

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