mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-08-06 08:56:12 +00:00
* fix(database): open backend so records actually persist and reload Measurement and prediction records were never persisted to the configured database backend (e.g. LMDB). They only survived while the process was running; every restart lost the accumulated history. For LoadAkkudoktorAdjusted this silently zeroed the measurement-based adjustment (the adjusted load forecast collapsed onto the raw mean). Root cause: `db_enabled` is defined as `database.is_open`, and every database code path (initialization, load, save, insert) is guarded behind `db_enabled`. Nothing ever opened the backend first -- the only lazy open (via `_run_db`) was unreachable because those calls sit behind the same guard. The backend therefore stayed closed, `db_enabled` stayed False, and all writes fell through to the JSON file fallback, which only holds the current in-memory snapshot and is not reloaded into the record store on startup. Fix: explicitly open the configured backend in `_db_ensure_initialized` before the `db_enabled` gate, wrapped in try/except so a failure degrades gracefully to file storage. Verified via an A/B test (identical persisted config, push -> save -> restart): without the fix the backend reports enabled=false and data is lost on restart; with the fix the backend is enabled, records persist to LMDB, and reload correctly after restart. * fix(database): skip disabled providers and avoid open retry loop Address review feedback: - Skip opening the backend for disabled providers (None/"NoDB"), whose is_open is always False and would otherwise be reopened on every call. - Add a one-shot _db_open_attempted flag so a closed/failed backend is not retried (and re-logged) on every record operation. - Add tests covering that NoDB never calls open() and that an unavailable backend does not raise per operation and is opened at most once. * fix(database): drop file-storage-fallback wording from open failure log --------- Co-authored-by: Cornelius Mund <cornim@users.noreply.github.com>