Skip to content

feat: agent executor cleaner#276

Merged
yarolegovich merged 9 commits intomainfrom
yarolegovich/agent-executor-cleaner
Mar 23, 2026
Merged

feat: agent executor cleaner#276
yarolegovich merged 9 commits intomainfrom
yarolegovich/agent-executor-cleaner

Conversation

@yarolegovich
Copy link
Copy Markdown
Member

@yarolegovich yarolegovich commented Mar 11, 2026

Add an optional callback AgentExecutor can implement to make it possible to run some actions after an execution was finished with either success or an error.

This callback is useful in a distributed environment when we can't place the logic into Cancel because it might be running concurrently with an active execution.

Release-As: 2.0.1

@yarolegovich yarolegovich requested a review from ishymko March 11, 2026 12:38
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the AgentExecutor by introducing an optional AgentExecutionCleaner interface. This allows for a dedicated cleanup callback to be executed after an agent's task completes, whether successfully or due to an error. This new mechanism provides a robust way to manage post-execution resources, especially in distributed systems where traditional cancellation might not suffice for finalization steps.

Highlights

  • New AgentExecutionCleaner Interface: Introduced an optional AgentExecutionCleaner interface that AgentExecutor implementations can use to perform cleanup actions after an execution completes, regardless of success or error.
  • Post-Execution Cleanup Logic: Integrated the cleanup callback into the agent execution flow, ensuring it is invoked in the execution goroutine after the main execution finishes.
  • Comprehensive Testing: Added new unit tests and updated an end-to-end test to thoroughly verify the functionality and behavior of the AgentExecutionCleaner under various scenarios.
  • Documentation Updates: Updated README.md to reflect the v2 module path in GoDoc links.
Changelog
  • README.md
    • Updated GoDoc links to reference the v2 module path for the main package and sub-packages like a2asrv and a2aclient.
  • a2asrv/agentexec.go
    • Defined the AgentExecutionCleaner interface with a Cleanup method.
    • Added a Cleanup method to the executor struct, which conditionally calls the agent's AgentExecutionCleaner if implemented.
  • a2asrv/handler_test.go
    • Added TestAgentExecutionCleaner to test the cleanup functionality for successful, handled error, and unhandled error executions.
    • Introduced cleanerAgentExecutor helper struct for mocking AgentExecutionCleaner in tests.
  • e2e/cancellation_test.go
    • Modified TestConcurrentCancellation_ExecutionResolvesToCanceledTask to include assertions for the cleanup callback's result, verifying the final task state.
  • internal/taskexec/api.go
    • Extended the Executor interface with a Cleanup method.
  • internal/taskexec/local_manager.go
    • Invoked the executor.Cleanup method after the runProducerConsumer completes, passing the execution result and any error.
  • internal/taskexec/manager_test.go
    • Added a no-operation Cleanup method to testExecutor to conform to the updated Executor interface.
  • internal/taskexec/work_queue_handler.go
    • Modified the handle function to store and execute a cleanup callback after processing the event producer and processor.
  • internal/testutil/testexecutor/executor.go
    • Added a CleanupFn field to TestAgentExecutor to allow custom cleanup logic in tests.
    • Implemented the Cleanup method for TestAgentExecutor to call the CleanupFn.
Activity
  • The pull request was created by yarolegovich. No other activity (comments, reviews, or progress updates) is available in the provided context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an optional AgentExecutionCleaner interface, allowing an AgentExecutor to perform cleanup actions after an execution completes, which is valuable for managing resources in distributed environments. However, the current implementation lacks panic protection when invoking the Cleanup callback, which could lead to a Denial of Service if a cleanup implementation panics. It is recommended to add a recover block to handle such cases gracefully. Additionally, there is a minor suggestion to improve the clarity of a comment on the new interface.

@yarolegovich yarolegovich changed the title feat: agent executor cleaner [WIP] feat: agent executor cleaner Mar 11, 2026
@yarolegovich yarolegovich changed the title [WIP] feat: agent executor cleaner feat: agent executor cleaner Mar 20, 2026
@yarolegovich yarolegovich merged commit 9c95980 into main Mar 23, 2026
5 checks passed
@yarolegovich yarolegovich deleted the yarolegovich/agent-executor-cleaner branch March 23, 2026 14:32
yarolegovich pushed a commit that referenced this pull request Mar 24, 2026
🤖 I have created a release *beep* *boop*
---


## [2.0.1](v2.0.0...v2.0.1)
(2026-03-24)


### Features

* **a2acompat:** add HTTP+JSON REST support to a2av0 compat layer
([#280](#280))
([bac00e7](bac00e7))
* agent executor cleaner
([#276](#276))
([9c95980](9c95980))


### Bug Fixes

* ensure correct concurrent cancellation results
([#287](#287))
([d0f8981](d0f8981)),
closes [#245](#245)


### Documentation

* **a2aclient:** add Example_* test functions for pkg.go.dev
documentation ([#263](#263))
([f8dae97](f8dae97))
* update diagrams, docs and instructions
([#289](#289))
([ed33c7a](ed33c7a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants