Skip to content

fix(sessions): release unused SQLAlchemy table-init locks - #4748

Open
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:fix/sqlalchemy-table-init-locks
Open

fix(sessions): release unused SQLAlchemy table-init locks#4748
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:fix/sqlalchemy-table-init-locks

Conversation

@rioyu123

Copy link
Copy Markdown

Summary

This pull request fixes unused SQLAlchemy table-initialization locks remaining in the process-wide registry.

SQLAlchemySession(create_tables=True) currently keeps one initialization lock for every distinct database/table configuration, even after all sessions using that configuration have been released.

The registry now holds weak values, while each live session keeps its existing strong lock reference. Sessions sharing a key still use the same lock; the registry guard, initialization ordering and cancellation handling are unchanged.

In a probe creating and discarding sessions for 100,000 distinct configurations, the old registry retained 100,000 entries after collection. The updated registry retained none. The measured allocation delta came from tracemalloc; it is not RSS or the byte size of the lock objects.

Test plan

  • Added regression coverage for collection of unused locks and sharing with surviving owners during concurrent first writes.
  • Confirmed the collection regression fails against the unchanged base and existing cross-loop and cancelled-waiter tests still pass.
  • Ran the complete format, lint, Mypy, Pyright and test verification on Python3.12, plus focused tests on Python3.10.

Checks

  • Added regression tests.
  • Ran .agents/skills/code-change-verification/scripts/run.sh.
  • Confirmed all verification steps pass.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T03:49:44.768056Z f4cc0db PR opened
🔒 Security Review Completed 2026-08-29T03:50:54.307779Z f4cc0db PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant