Skip to content

fix: close KnowledgeGraph SQLite connections in test fixtures#450

Merged
bensig merged 1 commit intoMemPalace:developfrom
sjhddh:fix/close-kg-sqlite-in-tests
Apr 12, 2026
Merged

fix: close KnowledgeGraph SQLite connections in test fixtures#450
bensig merged 1 commit intoMemPalace:developfrom
sjhddh:fix/close-kg-sqlite-in-tests

Conversation

@sjhddh
Copy link
Copy Markdown
Contributor

@sjhddh sjhddh commented Apr 9, 2026

Summary

  • The kg fixture in tests/conftest.py creates a KnowledgeGraph (which opens SQLite connections) but never calls .close(), leaking connections during the test session.
  • Changed return to yield + graph.close() for proper teardown cleanup.

Test plan

  • Verify existing tests pass with the fixture change
  • Confirm no SQLite "database is locked" warnings in test output

🤖 Generated with Claude Code

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — this is a classic fixture leak. The returnyield + 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 bensig changed the base branch from main to develop April 11, 2026 22:22
Copy link
Copy Markdown
Collaborator

@bensig bensig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review + security audit clean.

@bensig bensig merged commit 15d9ee1 into MemPalace:develop Apr 12, 2026
jphein added a commit to jphein/mempalace that referenced this pull request Apr 12, 2026
…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]>
ichoosetoaccept pushed a commit to detailobsessed/mempalace that referenced this pull request Apr 13, 2026
…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.
ichoosetoaccept pushed a commit to detailobsessed/mempalace that referenced this pull request Apr 13, 2026
…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.
ichoosetoaccept pushed a commit to detailobsessed/mempalace that referenced this pull request Apr 13, 2026
…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.
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.

3 participants