Skip to content

fix: make session mutations atomic - #4212

Merged
seratch merged 7 commits into
mainfrom
fix/session-mutation-atomicity
Aug 6, 2026
Merged

fix: make session mutations atomic#4212
seratch merged 7 commits into
mainfrom
fix/session-mutation-atomicity

Conversation

@seratch

@seratch seratch commented Aug 5, 2026

Copy link
Copy Markdown
Member

This pull request resolves the session mutation races reported in #4202 and the related cross-backend problems tracked in #4205. It supersedes and broadens the narrower SQLite-focused approach proposed in #4203.

Built-in session mutations previously had backend-specific gaps around concurrent appends, destructive reads, clear boundaries, cancellation, and post-commit cleanup. Those gaps could expose partial batches, return the same popped item more than once, retry an already committed mutation, or allow cancellation to interrupt resource settlement.

This change establishes consistent mutation semantics across SQLite, AsyncSQLite, AdvancedSQLite, SQLAlchemy, MongoDB, and Redis:

  • Persist each logical item batch atomically.
  • Claim destructive reads at most once.
  • Establish one authoritative clear boundary.
  • Wait for mutation and owned cleanup outcomes before propagating caller cancellation.
  • Preserve Python 3.10 cancellation details.
  • Use primary-authoritative MongoDB generation metadata and atomic tail claims.
  • Distinguish explicit Redis transaction conflicts from ambiguous acknowledgements.
  • Preserve Redis connection ownership across redis-py 7.x through 8.1 cleanup, reconnect, and reborrow paths.
  • Retain backward compatibility for public call shapes, configured storage names, legacy readable data, and injected-resource ownership.

Dapr is intentionally excluded because generic Dapr state stores cannot guarantee an atomic conditional creation of an absent aggregate key with the current representation. Supporting it safely requires a separate distributed-lock contract or persisted-representation redesign.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31bd54eb7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/memory/sqlite_session.py Outdated
@seratch
seratch force-pushed the fix/session-mutation-atomicity branch from 31bd54e to 9d49724 Compare August 5, 2026 13:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d49724abc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/extensions/memory/redis_session.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0afc42ea86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/extensions/memory/mongodb_session.py Outdated
Comment thread src/agents/extensions/memory/mongodb_session.py Outdated
Comment thread src/agents/extensions/memory/sqlalchemy_session.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 926b40d319

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/extensions/memory/redis_session.py Outdated
@seratch
seratch force-pushed the fix/session-mutation-atomicity branch from 926b40d to 38638c0 Compare August 6, 2026 00:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38638c021a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/extensions/memory/advanced_sqlite_session.py
@seratch
seratch force-pushed the fix/session-mutation-atomicity branch from 38638c0 to e3f7014 Compare August 6, 2026 02:54
@seratch
seratch merged commit 4a1773f into main Aug 6, 2026
10 checks passed
@seratch
seratch deleted the fix/session-mutation-atomicity branch August 6, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant