- Notifications
You must be signed in to change notification settings - Fork2.6k
Feat: Add AdvancedSQLiteSession with conversation branching & usage tracking#1662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
@codex Can you review this PR? Share both good things and rooms for improvements. |
There was a problem hiding this comment.
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 suggestions.
Reply with@codex fix comments
to fix any unresolved comments.
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, or 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 fix this CI failure" or "@codex address that feedback".
Uh oh!
There was an error while loading.Please reload this page.
def _update_sync(): | ||
conn = self._get_connection() | ||
# Serialize token details as JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
[P2] Guard turn usage writes with session lock
The detailed turn-level usage tracking is helpful, however_update_turn_usage_internal
acquires the shared SQLite connection and performs writes without usingself._lock
. For in-memory sessions that share a single connection, two concurrent calls tostore_run_usage()
or an overlap withadd_items()
can execute on the same connection from different threads, producingsqlite3.ProgrammingError
/OperationalError
(“database is locked”). Base session methods wrap all access in the lock for this reason; usage writes should do the same or otherwise ensure only one thread uses the connection at a time.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is valid, but SQLiteSession needs to reflect this as well
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Kazuhiro Sera <seratch@openai.com>
I added the For |
I ran into a bug in my implementation of Key changes:
Now each branch is truly isolated - no more weird cross-branch contamination when doing operations. I understand this might require some extensive review, so take your time. |
@seratch awaiting your review |
@habema Thanks for being patient here. I didn't have enough time for intensively reviewing this one today, but I will do tomorrow! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Great work! Left a few minor comments
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for adding this!
4f54878
intoopenai:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Resolves#1385
This PR introduces
AdvancedSQLiteSession
as a drop-in replacement forSQLiteSession
with enhanced conversation management capabilities. Addresses#1385 and builds on the foundation from#1474.Key Features
New Table Schema
Usage Pattern
Currently requires manual usage storage:
Question: Should usage storage be automatic?
Currently users need to manually call
store_run_usage()
after each run to get the analytics features (turn-level token tracking, usage breakdowns, etc.). It works fine but could be better UX-wise.However, since this is an extension feature, it shouldn't require changes to the core SDK (
run.py
). Making it automatic could be quite a complex change - as it could need to patch the runner itself, and potentially break the clean separation between core and extensions.What's the preference here - keep the explicit manual approach or explore automatic storage despite the complexity?
Testing Notes
Tests skip in
old_versions_test
due to sqlalchemy dependency in the same directory (same issue as#1357). The advanced session itself doesn't need sqlalchemy, but the import path requires it.