fix: satisfy the no-locked-pure-readers gate and close the DB before rmtree

_record_db_file_identity's PRAGMA fallback is a pure read — route it
through _read_ctx() instead of the writer lock (Pattern C gate).
test_codex_turn_persists_each_message_exactly_once leaked a live
SessionDB into shutil.rmtree, racing the WAL sidecars ('Directory not
empty' on CI); close the handle first and rmtree with ignore_errors.
This commit is contained in:
Teknium
2026-08-31 13:44:56 -07:00
parent a9b6b979e9
commit 8dbf07e950
2 changed files with 6 additions and 3 deletions
+2 -2
View File
@@ -5978,8 +5978,8 @@ class SessionDB(SessionSearchMixin, SessionSchemaMixin, SessionPortabilityMixin)
self._db_file_application_id = disk_id
elif self._conn is not None and not self._db_file_application_id:
try:
with self._lock:
pragma_row = self._conn.execute("PRAGMA application_id").fetchone()
with self._read_ctx() as conn:
pragma_row = conn.execute("PRAGMA application_id").fetchone()
if pragma_row and pragma_row[0]:
self._db_file_application_id = int(pragma_row[0])
except sqlite3.Error:
+4 -1
View File
@@ -111,6 +111,7 @@ def test_codex_turn_persists_each_message_exactly_once():
real AIAgent._flush_messages_to_session_db to prove no #860/#42039
duplicate-write regression on the codex path."""
tmp = tempfile.mkdtemp(prefix="codex_persist_")
db = None
try:
db = SessionDB(Path(tmp) / "state.db")
sid = "sess-codex-once"
@@ -163,7 +164,9 @@ def test_codex_turn_persists_each_message_exactly_once():
finally:
import shutil
shutil.rmtree(tmp)
if db is not None:
db.close()
shutil.rmtree(tmp, ignore_errors=True)
class TestGatewayPersistedResolution: