Skip to content

fix(assistant): ensure checkpoints parent directory exists before sqlite3 connection - #41

Open
shrinivas-sn wants to merge 1 commit into
Harshbansal8705:mainfrom
shrinivas-sn:fix/checkpoints-dir-creation-40
Open

shrinivas-sn wants to merge 1 commit into
Harshbansal8705:mainfrom
shrinivas-sn:fix/checkpoints-dir-creation-40

Conversation

@shrinivas-sn

Copy link
Copy Markdown

Description

On a clean clone of the repository, the checkpoints/ directory does not exist on disk and is explicitly ignored by .gitignore. When src/core/assistant.py is imported (e.g. during application startup in main.py), SQLite attempts to open config.CHECKPOINTS_DB. Because SQLite cannot create files in non-existent parent directories, this causes an immediate sqlite3.OperationalError: unable to open database file.

This PR adds a directory creation guard (os.makedirs(checkpoint_dir, exist_ok=True)) before calling sqlite3.connect(), matching the pattern used for logs in src/utils/logger.py. It also introduces a dedicated unit test suite in tests/test_assistant_initialization.py to prevent regressions.

Fixes #40

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔨 Refactor (non-breaking change that improves code quality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation update

Changes Made

  • In src/core/assistant.py: imported os and added directory existence guard os.makedirs(checkpoint_dir, exist_ok=True) before sqlite3.connect(config.CHECKPOINTS_DB, check_same_thread=False).
  • In tests/test_assistant_initialization.py: added unit tests validating that missing directories raise SQLite errors without the guard, that the directory guard resolves the issue idempotently, and that config.CHECKPOINTS_DB parent directory can be safely initialized.
  • In tests/__init__.py: initialized tests package.

How Has This Been Tested?

  • Ran unit tests via python -m unittest discover tests (2 tests, 100% passing).
  • Verified linter and formatting checks via ruff check . (all checks passed) and ruff format --check . (27 files formatted).
  • Verified git diff --check has zero whitespace errors.
  • Tested the specific feature/fix manually on a fresh clone path with no existing checkpoints/ directory.
  • Verified no regressions in existing functionality.

Checklist

  • My code follows the project's code style
  • I have added/updated docstrings for new/modified functions
  • I have updated the README if needed
  • I have added my new configuration to src/config.py (if applicable)
  • New tools use the @tool decorator from src/core/tools.py

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.

[BUG] sqlite3.OperationalError on clean clone when checkpoints directory does not exist

1 participant