Files
Nandana Dileep d8ff0fe9d2 fix: [BUG] Volatile SQLite metrics stores lose their schema before the first save (#4633)
<!-- oss-harness:v2 -->
Fixes #4262.

Focused Python fix for: [BUG] Volatile SQLite metrics stores lose their
schema before the first save

Changed implementation: headroom/storage/sqlite.py.
Regression tests: tests/test_storage/test_sqlite.py.

Verification (working directory `.`): `.venv/bin/python -m pytest -q -x
-p no:cacheprovider -- /workspace/tests/test_storage/test_sqlite.py`
- Patched code: 35 tests, zero failures/errors.
- Original code with the same regression tests: 1 failures, zero
collection/setup errors.
- Base commit: `12dca26aa11d99b3af6c6d68cdf96ff90ef415aa`.

AI-assisted contribution: OpenCode using Autoloops wrote this patch. The
automated harness independently ran the tests listed above. No human
review is claimed.

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4633"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

### Maintainer real behavior proof

Reviewed `55a6c8e3807c3d59da81a457514c82d4a3b48032` against main
`12dca26aa11d99b3af6c6d68cdf96ff90ef415aa` in isolated Windows
worktrees, Python 3.12.13. Current main is an ancestor; no branch update
was needed.

Executed `.venv/Scripts/python.exe -m pytest
tests/test_storage/test_sqlite.py -q -k 'not test_creates_db_file'
--disable-warnings`: **34 passed**, including disk migration/concurrency
and volatile-store regressions. Ruff and `git diff --check` passed. The
excluded test fails before exercising storage because its fixture holds
the temporary file open on Windows; the identical WinError 32 was
reproduced independently on current main.

Also ran a direct API smoke script, separately loading `git show
upstream/main:headroom/storage/sqlite.py` and `git show
HEAD:headroom/storage/sqlite.py`. For each of
`SQLiteStorage(':memory:')` and `SQLiteStorage('')`, it saved one
`RequestMetrics` row, checked equality with `get`, `count == 1`, one
result from `query`, `get_summary_stats()['total_requests'] == 1`, then
closed and verified a recreated store has zero rows. **Main: first save
raises `OperationalError('no such table: requests')` for both paths. PR:
all operations pass for both paths.**

Limits: this is a direct local storage API exercise, not a running proxy
or production-load qualification. Hosted CI's four test shards and
applicable checks passed on the exact reviewed head. No release or merge
performed.
2026-11-04 12:28:05 -06:00
..