Skip to content

feat: InMemoryTaskStore creates a copy of Task by default to make it consistent with database task stores #887

Merged
bartek-w merged 1 commit into1.0-devfrom
bartekw-task-store
Mar 24, 2026
Merged

feat: InMemoryTaskStore creates a copy of Task by default to make it consistent with database task stores #887
bartek-w merged 1 commit into1.0-devfrom
bartekw-task-store

Conversation

@bartek-w
Copy link
Copy Markdown
Collaborator

Sharing the Task object instance in InMemoryTaskStore leads to unexpected behaviour (from differences of in-place update Task in AgentExecutor to non-trivial concurrency reporting issues on task state reporting).

Fixes #869

@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 addresses a critical issue in the InMemoryTaskStore where sharing Task object instances could lead to unexpected behavior and concurrency problems. By introducing a CopyingTaskStoreAdapter and integrating it into the InMemoryTaskStore by default, the system now consistently handles Task objects as deep copies, preventing unintended in-place modifications and aligning its behavior with persistent database task stores.

Highlights

  • New Copying Task Store Adapter: Introduced CopyingTaskStoreAdapter to enforce deep copying of Task objects when interacting with any TaskStore, preventing shared mutable state issues.
  • Refactored InMemoryTaskStore: The InMemoryTaskStore has been refactored to internally use _InMemoryTaskStoreImpl and now wraps it with CopyingTaskStoreAdapter by default, ensuring consistent behavior with database-backed task stores.
  • Enhanced Test Coverage: Added new integration and unit tests specifically designed to verify the task copying behavior and prevent unintended shared mutable state issues.
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.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/tasks/inmemory_task_store.py 96.77% 97.14% 🟢 +0.37%
src/a2a/server/tasks/copying_task_store.py (new) 100.00%
Total 91.39% 91.43% 🟢 +0.04%

Generated by coverage-comment.yml

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 a significant improvement to the InMemoryTaskStore by making it behave consistently with database-backed task stores. By default, it now returns copies of Task objects instead of direct references, which prevents subtle bugs related to shared mutable state. This is achieved cleanly by introducing a CopyingTaskStoreAdapter and refactoring InMemoryTaskStore to use it. The changes are well-structured and accompanied by a comprehensive set of unit and integration tests that validate the new behavior. My review includes a couple of minor suggestions to improve code clarity and remove unused code. Overall, this is an excellent change.

@bartek-w bartek-w force-pushed the bartekw-task-store branch 2 times, most recently from a57e9c4 to e70fd58 Compare March 23, 2026 08:09
@bartek-w bartek-w requested a review from ishymko March 23, 2026 08:12
@bartek-w bartek-w marked this pull request as ready for review March 23, 2026 08:12
@bartek-w bartek-w requested a review from a team as a code owner March 23, 2026 08:12
@bartek-w bartek-w force-pushed the bartekw-task-store branch from e70fd58 to 0d1cb60 Compare March 24, 2026 10:57
@bartek-w bartek-w force-pushed the bartekw-task-store branch from 0d1cb60 to 4ae40ae Compare March 24, 2026 11:12
@bartek-w bartek-w merged commit 8c65e84 into 1.0-dev Mar 24, 2026
12 checks passed
@bartek-w bartek-w deleted the bartekw-task-store branch March 24, 2026 11:15
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