Skip to content

feat: retry cancelations#222

Merged
yarolegovich merged 3 commits intomainfrom
yarolegovich/cancelation-retries
Feb 20, 2026
Merged

feat: retry cancelations#222
yarolegovich merged 3 commits intomainfrom
yarolegovich/cancelation-retries

Conversation

@yarolegovich
Copy link
Copy Markdown
Member

we rely on optimistic concurrency control to propagate cancelation signal in distributed deployments.
if a task gets cancelled the next task update fails and stops execution.
in case of cancelations OCC also applies, but this also makes cancelations fragile, especially when execution generates events rapidly
the solution for now is to provide a built-in retry mechanism on task update level where in cases of concurrent modification task status update to failed is going to be retried up to a max number of attempts

@yarolegovich yarolegovich requested a review from ishymko February 19, 2026 09:11
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @yarolegovich, 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 significantly improves the robustness of task cancelation in distributed environments by introducing a retry mechanism for optimistic concurrency control failures. By explicitly handling concurrent modification errors during cancelation attempts, the system ensures that cancelation signals are reliably processed, even when tasks are undergoing rapid state changes. This enhancement makes the task management system more resilient and predictable, especially for critical operations.

Highlights

  • New Error Type for Concurrency: Introduced ErrConcurrentTaskModification to specifically identify optimistic concurrency control failures during task updates, providing a more granular error handling mechanism.
  • Retry Mechanism for Cancelations: Implemented a retry loop within the taskupdate.Manager for task cancelation events. If a concurrent modification error occurs during a cancelation attempt, the system will fetch the latest task state and retry the cancelation up to a predefined maximum number of attempts.
  • Enhanced Saver Interface: The Saver interface was extended with a Get method, allowing the taskupdate.Manager to retrieve the most current version of a task, which is essential for the new retry logic.
  • Comprehensive Test Coverage: Added new test cases to validate the retry mechanism for cancelations under various scenarios, including successful retries, non-concurrent errors, and handling tasks that are already canceled or in a terminal state.
Changelog
  • a2a/errors.go
    • Added ErrConcurrentTaskModification error constant.
  • internal/taskstore/store.go
    • Updated Save method to return a2a.ErrConcurrentTaskModification on concurrent modification instead of a generic error.
  • internal/taskstore/store_test.go
    • Updated test case to use errors.Is for checking a2a.ErrConcurrentTaskModification.
  • internal/taskupdate/manager.go
    • Added maxCancelationAttempts constant.
    • Updated Saver interface to include a Get method.
    • Implemented retry logic in updateStatus for a2a.TaskStateCanceled events when a2a.ErrConcurrentTaskModification is encountered.
    • Refactored saveTask into saveVerstionedTask to support the retry mechanism.
    • Imported errors and maps packages.
  • internal/taskupdate/manager_test.go
    • Imported strings and utils packages.
    • Removed the newStatusUpdate helper function.
    • Updated testSaver to include failOnce field and implement the Get method.
    • Modified existing tests to utilize the a2a.NewStatusUpdateEvent helper.
    • Added TestManager_CancelatioStatusUpdate_RetryOnConcurrentModification test suite to verify the new cancelation retry logic.
Activity
  • The pull request introduces a new feature to retry task cancelations.
  • The author, yarolegovich, has implemented changes to handle optimistic concurrency control failures during task cancelation.
  • The changes involve defining a new error type, modifying the task store to return this specific error, and implementing retry logic in the task update manager.
  • New test cases have been added to ensure the retry mechanism functions correctly under various conditions, including successful retries, handling non-concurrent errors, scenarios where tasks are already canceled, and tasks in terminal states.
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

The pull request introduces a robust retry mechanism for task status updates to the canceled state, addressing potential failures in optimistic concurrency control within distributed environments. The implementation correctly re-fetches the latest task state and merges the cancellation intent, ensuring idempotency and respecting terminal states. I have identified a few typos in function and test names, and a missing adherence to the repository's testing style guide regarding parallel execution. All comments align with the provided rules or are not covered by them, thus no modifications or drops were necessary.

@yarolegovich yarolegovich merged commit 3057474 into main Feb 20, 2026
4 checks passed
@yarolegovich yarolegovich deleted the yarolegovich/cancelation-retries branch February 20, 2026 14:22
yarolegovich pushed a commit that referenced this pull request Feb 23, 2026
🤖 I have created a release *beep* *boop*
---


## [0.3.7](v0.3.6...v0.3.7)
(2026-02-20)


### Features

* implement tasks/list RPC
([#210](#210))
([6e04698](6e04698))
* retry cancelations
([#222](#222))
([3057474](3057474))


### Bug Fixes

* handle internal error: tck failure
([#186](#186))
([b55fbfd](b55fbfd))
* **sse:** support data: prefix without space
([#188](#188))
([6657a6d](6657a6d)),
closes [#162](#162)

---
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.

3 participants