Skip to content

Keep SQLite sessions on the original database - #5012

Open
1fanwang wants to merge 1 commit into
openai:mainfrom
1fanwang:1fannnw/fix-sqlite-relative-db-path
Open

1fanwang wants to merge 1 commit into
openai:mainfrom
1fanwang:1fannnw/fix-sqlite-relative-db-path

Conversation

@1fanwang

Copy link
Copy Markdown

Summary

After changing directories, a SQLite session created with a relative filename can read or clear another database, or raise sqlite3.OperationalError: no such table: agent_messages.

Bind the filename at construction. In-memory sessions and literal ~ filenames keep their behavior.

Test plan

Ran this against both versions with real SQLite files.

Source Command Result
Base Inline program below Missing-table error
Fix Same program Original database retained
Reproducer and raw logs
PYTHONPATH=src python - <<'PY'
import asyncio
import os
import sqlite3
from contextlib import closing
from tempfile import TemporaryDirectory

from agents import SQLiteSession

original_cwd: str = os.getcwd()
try:
    with TemporaryDirectory() as root:
        try:
            os.chdir(root)
            os.mkdir("other")
            with closing(SQLiteSession(session_id="example", db_path="history.db")) as session:
                os.chdir("other")
                print("history:", asyncio.run(session.get_items()))
                print("second database created:", os.path.exists("history.db"))
        finally:
            os.chdir(original_cwd)
except sqlite3.OperationalError as error:
    print(f"sqlite3.OperationalError: {error}")
    raise SystemExit(1) from None
PY

Before:

sqlite3.OperationalError: no such table: agent_messages
exit=1

After:

history: []
second database created: False
exit=0

The full check has one unrelated docs-publisher failure on both versions: Git's safe.bareRepository=explicit rejects its bare-repo fixture. The SQLite and serial tests pass.

Issue number

No issue filed.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass (Docs fixture failure above.)
  • If using Codex, I've run /review before submitting this PR (Not applicable.)

Signed-off-by: 1fanwang <1fannnw@gmail.com>
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