@davoodmehraban89 / Aram / commits / 6397835
Fork 0

fix(gate3): close SQLite connections after reads and initialization

Davood Mehraban committed Nov 1, 2026 at 21:50 UTC 63978350a7cb47c6a7d0bcadafa84916d459d012
2 files changed +6 -3
backend/src/aram_backend/mapping_store.py
+4 -3
@@ -3,6 +3,7 @@ from __future__ import annotations
3
4 import json
5 import sqlite3
6 +from contextlib import closing
7 from dataclasses import asdict
8 from pathlib import Path
9
@@ -16,7 +17,7 @@ class MappingStore:
17 self.path = str(path)
18 if self.path == ":memory:":
19 raise MappingWorkflowError("durable store requires a filesystem path")
19 - with self._connect() as db:
20 + with closing(self._connect()) as db:
21 db.execute("PRAGMA journal_mode=WAL")
22 db.executescript("""
23 CREATE TABLE IF NOT EXISTS mapping_state (
@@ -40,7 +41,7 @@ class MappingStore:
41
42 def load(self, company: str, year: int) -> tuple[MappingWorkspace, int]:
43 workspace = MappingWorkspace(company, year)
43 - with self._connect() as db:
44 + with closing(self._connect()) as db:
45 row = db.execute(
46 "SELECT revision, payload FROM mapping_state WHERE company=? AND year=?",
47 (workspace.company_code, year),
@@ -144,7 +145,7 @@ class MappingStore:
145 db.close()
146
147 def audit_log(self, company: str, year: int) -> tuple[MappingAuditEvent, ...]:
147 - with self._connect() as db:
148 + with closing(self._connect()) as db:
149 rows = db.execute(
150 "SELECT payload FROM mapping_audit WHERE company=? AND year=? ORDER BY sequence",
151 (company, year),
docs/GATE3_REVIEW_82.md
+2
@@ -60,3 +60,5 @@ review and updated final-head CI are required before formal acceptance.
60 - No merge, release or production financial data modification is authorized.
61 - Final CI and full local test evidence must be checked against the new head before any acceptance decision.
62 - Decision: CHANGES REQUESTED; PR remains Draft pending independent review and closure of material controls.
63 +
64 +- Additional architecture finding: sqlite3.Connection context managers do not close connections. Fixed init/load/audit_log paths using contextlib.closing to prevent leaked file descriptors and Windows DB locks.