Skip to content

Make session creation to be idempotent - #1677

Merged
malatewang merged 4 commits into
mainfrom
session_management
Sep 18, 2026
Merged

malatewang merged 4 commits into
mainfrom
session_management

Conversation

@malatewang

Copy link
Copy Markdown
Contributor

Purpose of the change

Make episodic memory session creation to be idempotent

Description

In current logic, when creating a session, if the session key already exists, the creation will fail. This logic will not work with scale out because multiple workers may create the same session simultaneously. With this PR, if the new session has the same configuration with the existing one, the creation will succeed.

Fixes/Closes

Fixes #(issue number)

Type of change

[Please delete options that are not relevant.]

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

[Please delete options that are not relevant.]

  • Unit Test
  • Integration Test
  • End-to-end Test
  • Test Script (please provide)
  • Manual verification (list step-by-step instructions)

Test Results: [Attach logs, screenshots, or relevant output]

Checklist

[Please delete options that are not relevant.]

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

Screenshots/Gifs

[If applicable, add screenshots or GIFs that show the changes in action. This is especially helpful for API responses. Otherwise, delete this section or type "N/A".]

Further comments

[Add any other relevant information here, such as potential side effects, future considerations, or any specific questions for the reviewer. Otherwise, type "None".]

@edwinyyyu edwinyyyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Disagree with tenant lifecycle here, but it's not any worse than what's already in the codebase.

@malatewang
malatewang merged commit 843f00c into main Sep 18, 2026
51 checks passed
@malatewang
malatewang deleted the session_management branch September 18, 2026 17:40

@edwinyyyu edwinyyyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Found while rebasing the vector store PRs onto this: the port drops one condition its origin #1539 (3b0d9ec61 on speedkick) has, and it changes behavior for a session that is being deleted.

session = sessions.scalars().first()
if session is not None:
if (
session.configuration == configuration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#1539's create_new_session_if_not_exist accepts an existing row only when session.status != SessionDataManager.SessionStatus.Deleted as well as the three data matches; this port has the three matches without the status condition. So on main a session whose row is marked deleted (delete in progress, or a delete whose purge has not run) is accepted by a matching create, and create_episodic_memory then builds an instance for it, which open_episodic_memory would refuse with SessionDeletedError.

Verified on 843f00cd9 with the manager test's setup: create a session, close_session, update_session_status(key, "delete"), then create_episodic_memory with the same data — no error, where #1539 raises SessionAlreadyExistsError and this branch's open_episodic_memory raises SessionDeletedError. #1624's port of the deleted-session test drops its re-create assertion because of this, and says so in its body.

This was referenced Sep 18, 2026
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