fix(db): reset_engine/cleanup_old_data still swallow on first lock — wire retry_on_db_lock like the _save_to_db path
Summary
Two of the three "bypass sites" the #6718 review listed as remaining are still unwired at HEAD: the tracker's reset_engine and cleanup_old_data DB deletes run through metrics_writer.get_session and swallow the first database is locked with a warning - while the third site (token_counter._save_to_db) did get the retry_on_db_lock wrap.
| Field | Value |
|---|---|
| Severity | suggested |
| Origin | Review of #6718 (post-merge extraction) |
| Review section | Prose approval leftovers ("Remaining non-blocking items if you circle back") |
| Classification | main-existing |
| Verified at | main@43061a14ebff |
| Dedup | distinct · 4 hits reviewed |
Trigger
The scheduler or a background thread holds the SQLite writer lock while reset_engine or cleanup_old_data commits their deletes.
Impact
Both operations silently degrade to the except Exception warning on first lock (no retry), the same exposure #6718 was merged to remove for the metrics write path.
Pinned evidence
43061a14ebff:src/local_deep_research/web_search_engines/rate_limiting/tracker.py:L660-L697-reset_engineDB block: deletes + commit insideget_session, no retry,except Exception: logger.warning43061a14ebff:src/local_deep_research/web_search_engines/rate_limiting/tracker.py:L780-L835-cleanup_old_dataDB block: same shape43061a14ebff:src/local_deep_research/metrics/token_counter.py:L858-L876- the wrapped counterpart (retry_on_db_lock(_write_metrics)) showing the intended pattern
Fix direction
Wrap each DB block in retry_on_db_lock with the closure-per-attempt shape used at _save_to_db (a fresh get_session per attempt so the writer lock is released between tries).
Targeted tests
Mirror the #6718 contention test: hold a BEGIN IMMEDIATE writer, call reset_engine/cleanup_old_data through a production-shaped session, assert >=2 attempts and the durable delete.
Provenance
Extracted from review of PR #6718 (post-merge extraction). Related: #6566, #6720.
Source: LearningCircuit/local-deep-research