UAT: Database URL default inconsistency — Settings uses sqlite:///cleveragents.db, alembic/env.py uses .cleveragents/db.sqlite, spec requires ~/.cleveragents/cleveragents.db #2871

Closed
opened 2026-04-04 21:16:52 +00:00 by freemo · 4 comments
Owner

Metadata

  • Branch: fix/database-url-default-inconsistency
  • Commit Message: fix(config): align Settings and alembic/env.py database_url defaults to spec-required ~/.cleveragents/cleveragents.db
  • Milestone: v3.7.0
  • Parent Epic: #362

Bug Description

Three different database URL defaults exist across the codebase, none of which match the specification's required default location.

Expected Behavior (from spec)

The system uses a local SQLite database by default. Location: ~/.cleveragents/cleveragents.db.

Actual Behavior — Three Inconsistent Defaults

1. src/cleveragents/config/settings.py:

database_url: str = Field(
    default="sqlite:///cleveragents.db",  # relative path, wrong filename
    ...
)

2. alembic/env.py:

database_url = os.getenv(
    "CLEVERAGENTS_DATABASE_URL",
    f"sqlite:///{Path.cwd() / '.cleveragents' / 'db.sqlite'}",  # wrong filename: db.sqlite vs cleveragents.db
)

3. alembic.ini:

sqlalchemy.url = driver://user:pass@localhost/dbname  # placeholder, overridden by env.py

Verified by Running

from cleveragents.config.settings import Settings
s = Settings()
print(s.database_url)  # sqlite:///cleveragents.db (relative, wrong)
# alembic/env.py default: sqlite:///<cwd>/.cleveragents/db.sqlite (wrong filename)
# Spec requires: sqlite:////home/user/.cleveragents/cleveragents.db

Impact

  1. Running alembic upgrade head without CLEVERAGENTS_DATABASE_URL set creates the database at <cwd>/.cleveragents/db.sqlite instead of ~/.cleveragents/cleveragents.db.
  2. Running the application without CLEVERAGENTS_DATABASE_URL set creates the database at <cwd>/cleveragents.db instead of ~/.cleveragents/cleveragents.db.
  3. These two paths are different, so migrations and the application may use different databases — a critical data integrity risk.

Fix Required

Both Settings.database_url and alembic/env.py should default to sqlite:////home/<user>/.cleveragents/cleveragents.db (using Path.home() / ".cleveragents" / "cleveragents.db").

Code Locations

  • src/cleveragents/config/settings.pydatabase_url field default value
  • alembic/env.pydatabase_url fallback default

Subtasks

  • Fix Settings.database_url default in src/cleveragents/config/settings.py to use f"sqlite:///{Path.home() / '.cleveragents' / 'cleveragents.db'}"
  • Fix alembic/env.py fallback default to use Path.home() / ".cleveragents" / "cleveragents.db" (matching Settings)
  • Verify both Settings and alembic/env.py now resolve to the same absolute path
  • Add or update a Behave scenario covering the correct database_url default value
  • Verify CLEVERAGENTS_DATABASE_URL env var override still works correctly in both Settings and alembic/env.py
  • Confirm Settings.database_url and Settings.data_dir defaults are mutually consistent (database lives inside data_dir)
  • Run nox -e typecheck to confirm no type regressions

Definition of Done

  • Settings().database_url resolves to sqlite:////home/<user>/.cleveragents/cleveragents.db when CLEVERAGENTS_DATABASE_URL is not set
  • alembic/env.py fallback default resolves to the same path as Settings().database_url
  • CLEVERAGENTS_DATABASE_URL env var override works correctly in both locations
  • Behave scenario added or updated to cover the correct database_url default
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/database-url-default-inconsistency` - **Commit Message**: `fix(config): align Settings and alembic/env.py database_url defaults to spec-required ~/.cleveragents/cleveragents.db` - **Milestone**: v3.7.0 - **Parent Epic**: #362 ## Bug Description Three different database URL defaults exist across the codebase, none of which match the specification's required default location. ### Expected Behavior (from spec) > The system uses a local SQLite database by default. Location: `~/.cleveragents/cleveragents.db`. ### Actual Behavior — Three Inconsistent Defaults **1. `src/cleveragents/config/settings.py`:** ```python database_url: str = Field( default="sqlite:///cleveragents.db", # relative path, wrong filename ... ) ``` **2. `alembic/env.py`:** ```python database_url = os.getenv( "CLEVERAGENTS_DATABASE_URL", f"sqlite:///{Path.cwd() / '.cleveragents' / 'db.sqlite'}", # wrong filename: db.sqlite vs cleveragents.db ) ``` **3. `alembic.ini`:** ```ini sqlalchemy.url = driver://user:pass@localhost/dbname # placeholder, overridden by env.py ``` ### Verified by Running ```python from cleveragents.config.settings import Settings s = Settings() print(s.database_url) # sqlite:///cleveragents.db (relative, wrong) # alembic/env.py default: sqlite:///<cwd>/.cleveragents/db.sqlite (wrong filename) # Spec requires: sqlite:////home/user/.cleveragents/cleveragents.db ``` ### Impact 1. Running `alembic upgrade head` without `CLEVERAGENTS_DATABASE_URL` set creates the database at `<cwd>/.cleveragents/db.sqlite` instead of `~/.cleveragents/cleveragents.db`. 2. Running the application without `CLEVERAGENTS_DATABASE_URL` set creates the database at `<cwd>/cleveragents.db` instead of `~/.cleveragents/cleveragents.db`. 3. These two paths are different, so migrations and the application may use **different databases** — a critical data integrity risk. ### Fix Required Both `Settings.database_url` and `alembic/env.py` should default to `sqlite:////home/<user>/.cleveragents/cleveragents.db` (using `Path.home() / ".cleveragents" / "cleveragents.db"`). ### Code Locations - `src/cleveragents/config/settings.py` — `database_url` field default value - `alembic/env.py` — `database_url` fallback default ## Subtasks - [ ] Fix `Settings.database_url` default in `src/cleveragents/config/settings.py` to use `f"sqlite:///{Path.home() / '.cleveragents' / 'cleveragents.db'}"` - [ ] Fix `alembic/env.py` fallback default to use `Path.home() / ".cleveragents" / "cleveragents.db"` (matching `Settings`) - [ ] Verify both `Settings` and `alembic/env.py` now resolve to the same absolute path - [ ] Add or update a Behave scenario covering the correct `database_url` default value - [ ] Verify `CLEVERAGENTS_DATABASE_URL` env var override still works correctly in both `Settings` and `alembic/env.py` - [ ] Confirm `Settings.database_url` and `Settings.data_dir` defaults are mutually consistent (database lives inside `data_dir`) - [ ] Run `nox -e typecheck` to confirm no type regressions ## Definition of Done - [ ] `Settings().database_url` resolves to `sqlite:////home/<user>/.cleveragents/cleveragents.db` when `CLEVERAGENTS_DATABASE_URL` is not set - [ ] `alembic/env.py` fallback default resolves to the same path as `Settings().database_url` - [ ] `CLEVERAGENTS_DATABASE_URL` env var override works correctly in both locations - [ ] Behave scenario added or updated to cover the correct `database_url` default - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.7.0 milestone 2026-04-04 21:17:02 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: High — Three different database URL defaults across the codebase creates a critical data integrity risk. Migrations and the application may use different databases, leading to silent data loss or corruption. The spec explicitly requires ~/.cleveragents/cleveragents.db.
  • Milestone: v3.7.0 (already set correctly)
  • MoSCoW: Must Have — The spec says the system uses ~/.cleveragents/cleveragents.db by default. This is a MUST requirement. The current inconsistency between Settings, alembic/env.py, and the spec creates a data integrity risk that must be resolved before any release.
  • Parent Epic: #362 (Epic: Security & Safety Hardening)

This is a serious configuration bug. Three different defaults (sqlite:///cleveragents.db, .cleveragents/db.sqlite, and the spec-required ~/.cleveragents/cleveragents.db) means migrations and the application can silently use different databases. This must be fixed.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: High — Three different database URL defaults across the codebase creates a **critical data integrity risk**. Migrations and the application may use different databases, leading to silent data loss or corruption. The spec explicitly requires `~/.cleveragents/cleveragents.db`. - **Milestone**: v3.7.0 (already set correctly) - **MoSCoW**: Must Have — The spec says the system uses `~/.cleveragents/cleveragents.db` by default. This is a MUST requirement. The current inconsistency between `Settings`, `alembic/env.py`, and the spec creates a data integrity risk that must be resolved before any release. - **Parent Epic**: #362 (Epic: Security & Safety Hardening) This is a serious configuration bug. Three different defaults (`sqlite:///cleveragents.db`, `.cleveragents/db.sqlite`, and the spec-required `~/.cleveragents/cleveragents.db`) means migrations and the application can silently use different databases. This must be fixed. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Author
Owner

Starting implementation on branch fix/database-url-default-inconsistency.

Plan:

  1. Fix Settings.database_url default to use Path.home() / '.cleveragents' / 'cleveragents.db'
  2. Fix alembic/env.py fallback default to match
  3. Add Behave scenarios for correct default and env var override
  4. Run quality gates (typecheck, tests, coverage)

Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-issue-worker

Starting implementation on branch `fix/database-url-default-inconsistency`. **Plan:** 1. Fix `Settings.database_url` default to use `Path.home() / '.cleveragents' / 'cleveragents.db'` 2. Fix `alembic/env.py` fallback default to match 3. Add Behave scenarios for correct default and env var override 4. Run quality gates (typecheck, tests, coverage) --- **Automated by CleverAgents Bot** Supervisor: Implementation | Agent: ca-issue-worker
Author
Owner

All subtasks complete. Quality gates passed. PR #3234 created on branch fix/database-url-default-inconsistency.

Changes made:

  • src/cleveragents/config/settings.py: Fixed database_url default to use Path.home() / '.cleveragents' / 'cleveragents.db' (absolute path)
  • src/cleveragents/config/settings.py: Fixed test_database_url default similarly
  • alembic/env.py: Fixed fallback default to use Path.home() / '.cleveragents' / 'cleveragents.db' (matching Settings)
  • features/settings_configuration.feature: Added 3 new Behave scenarios covering correct default and env var override
  • features/steps/settings_steps.py: Added step definitions for new scenarios
  • features/steps/coverage_boost_steps.py: Updated assertions to match new correct defaults

Quality gates:

  • nox -e typecheck — 0 errors
  • nox -e lint — all checks passed
  • nox -e unit_tests (settings features) — 44 scenarios pass

PR review and merge handled by continuous review stream.


Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-issue-worker

All subtasks complete. Quality gates passed. PR #3234 created on branch `fix/database-url-default-inconsistency`. **Changes made:** - `src/cleveragents/config/settings.py`: Fixed `database_url` default to use `Path.home() / '.cleveragents' / 'cleveragents.db'` (absolute path) - `src/cleveragents/config/settings.py`: Fixed `test_database_url` default similarly - `alembic/env.py`: Fixed fallback default to use `Path.home() / '.cleveragents' / 'cleveragents.db'` (matching Settings) - `features/settings_configuration.feature`: Added 3 new Behave scenarios covering correct default and env var override - `features/steps/settings_steps.py`: Added step definitions for new scenarios - `features/steps/coverage_boost_steps.py`: Updated assertions to match new correct defaults **Quality gates:** - ✅ `nox -e typecheck` — 0 errors - ✅ `nox -e lint` — all checks passed - ✅ `nox -e unit_tests` (settings features) — 44 scenarios pass PR review and merge handled by continuous review stream. --- **Automated by CleverAgents Bot** Supervisor: Implementation | Agent: ca-issue-worker
Owner

State label reconciliation:

  • Corrected to: State/Completed
  • Reason: Issue is closed but had a non-terminal state label (State/In Review, State/Verified, or State/In Progress). CONTRIBUTING.md requires closed issues to have State/Completed or State/Wont Do.

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: backlog-groomer

State label reconciliation: - Corrected to: `State/Completed` - Reason: Issue is closed but had a non-terminal state label (`State/In Review`, `State/Verified`, or `State/In Progress`). CONTRIBUTING.md requires closed issues to have `State/Completed` or `State/Wont Do`. --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: backlog-groomer
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#2871
No description provided.