fix: close KnowledgeGraph SQLite connections in test fixtures#450
fix: close KnowledgeGraph SQLite connections in test fixtures#450bensig merged 1 commit intoMemPalace:developfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <[email protected]>
web3guru888
left a comment
There was a problem hiding this comment.
Good catch — this is a classic fixture leak. The return → yield + graph.close() pattern is the correct pytest approach.
One thing to verify: does KnowledgeGraph have a .close() method? If it uses sqlite3.connect() internally, the close should call self.conn.close() on the underlying connection. Worth confirming this exists and doesn't raise if called on an already-closed graph (idempotent close).
Broader concern: If the test fixture is leaking connections, the production code likely has the same issue. Any long-running process (like the MCP server) that creates KnowledgeGraph instances without closing them would accumulate SQLite connections. In our integration, we use context managers (with-blocks) for KG operations — might be worth filing a follow-up for KnowledgeGraph to support __enter__/__exit__ as a context manager.
Small, clean fix. 👍
🔭 Reviewed as part of the MemPalace-AGI integration project — autonomous research with perfect memory. Community interaction updates are posted regularly on the dashboard.
bensig
left a comment
There was a problem hiding this comment.
Code review + security audit clean.
…n conflicts Merge upstream/develop: MemPalace#177, MemPalace#361, MemPalace#449, MemPalace#450 (benchmarks, tilde expand, duplicate cache vars, test fixture cleanup). Merge upstream/main: MemPalace#666 (z3tz3r0's block reason disambiguation). Conflict resolution: keep our scoped "For THIS save" phrasing instead of MemPalace#666's absolute "Do NOT write to auto-memory" — both memory systems are used in tandem. Also drop "AAAK-compressed" from diary instructions since diary_write is plain text, not AAAK dialect. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…iterdir OSError) - Expand ~ in split command dir/output-dir args (upstream MemPalace#361) - Use yield+close in KG test fixture to prevent SQLite leaks (MemPalace#450) - Use char/3.8 token estimate for consistency (MemPalace#609) - Handle OSError from iterdir on broken symlinks/reparse points (MemPalace#558) Closes DOT-488.
…iterdir OSError) - Expand ~ in split command dir/output-dir args (upstream MemPalace#361) - Use yield+close in KG test fixture to prevent SQLite leaks (MemPalace#450) - Use char/3.8 token estimate for consistency (MemPalace#609) - Handle OSError from iterdir on broken symlinks/reparse points (MemPalace#558) Closes DOT-488.
…iterdir OSError) - Expand ~ in split command dir/output-dir args (upstream MemPalace#361) - Use yield+close in KG test fixture to prevent SQLite leaks (MemPalace#450) - Use char/3.8 token estimate for consistency (MemPalace#609) - Handle OSError from iterdir on broken symlinks/reparse points (MemPalace#558) Closes DOT-488.
Summary
kgfixture intests/conftest.pycreates aKnowledgeGraph(which opens SQLite connections) but never calls.close(), leaking connections during the test session.returntoyield+graph.close()for proper teardown cleanup.Test plan
🤖 Generated with Claude Code