Fix #4751: Implement optimistic concurrency control with event sequence#4752
Fix #4751: Implement optimistic concurrency control with event sequence#47529chait9 wants to merge 4 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, 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 introduces a robust optimistic concurrency control mechanism to the session management system. By adding an Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
|
Response from ADK Triaging Agent Hello @9chait9, thank you for creating this PR! It looks like the Contributor License Agreement (CLA) check has failed. Please make sure you have signed the CLA at https://cla.developers.google.com/. In addition, could you please add a This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request replaces the timestamp-based concurrency check with a more robust optimistic concurrency control mechanism using an event_sequence number. The implementation correctly adds the event_sequence to sessions and checks it during event appends. However, I've found a critical race condition in the implementation for databases that do not support row-level locking, such as SQLite. This can lead to lost updates in a multi-process environment, which undermines the goal of this change.
…race conditions in optimistic concurrency control.
…use for optimistic concurrency control
|
Thanks for quickly jumping on this and driving the fix @9chait9! There are a few points for your consideration: 1. 2. JSON path WHERE won't work on non-PostgreSQL — 3. ORM dirty tracking bypasses the atomic UPDATE — After the raw UPDATE, mutating 4. SQLite 5. Minor — Issues 2 and 3 are both rooted in storing # v1.py — StorageSession
event_sequence: Mapped[int] = mapped_column(default=0)
__mapper_args__ = {"version_id_col": event_sequence}This works on all backends, cooperates with ORM dirty tracking, and requires no custom UPDATE logic. Would also be great to add a test asserting the #4751 contract: two concurrent appends from the same base version → one succeeds, one fails. |
Fixes #4751.
Details
This PR implements optimistic concurrency control using an event sequence number. This ensures that concurrent updates to the same resource are handled gracefully, preventing data loss by rejecting stale updates.
Test Plan