Skip to content

The agent that grows with you

fix: only call an auth DB backup "locked" when it made no progress

teknium1713a9377ccd3
diff --git a/hermes_cli/browser_connect.py b/hermes_cli/browser_connect.py
index 925bed93420..c39ae947c55 100644
--- a/hermes_cli/browser_connect.py
+++ b/hermes_cli/browser_connect.py
@@ -406,9 +406,18 @@ def _copy_auth_file(src_file: str, dst_file: str) -> str | None:
try:
if os.path.basename(src_file) in _SQLITE_AUTH_DBS:
deadline = time.monotonic() + _AUTH_BACKUP_DEADLINE_S
-
- def check_deadline(_status: int, _remaining: int, _total: int) -> None:
+ last_remaining: list[int | None] = [None]
+
+ def check_deadline(_status: int, remaining: int, total: int) -> None:
+ # A held write lock makes every step fail with ``remaining`` unchanged; a
+ # large DB on a slow disk keeps shrinking it. Only the former is "locked" —
+ # the all-locked message tells the user to quit the browser.
+ before = total if last_remaining[0] is None else last_remaining[0]
+ last_remaining[0] = remaining
if _status != sqlite3.SQLITE_DONE and time.monotonic() >= deadline:
+ if remaining < before:
+ raise TimeoutError(f"SQLite backup exceeded {_AUTH_BACKUP_DEADLINE_S:g}s "
+ "while still making progress")
raise TimeoutError(_AUTH_DB_LOCKED)
# SQLite must coordinate both ends: immutable ignores committed source WAL,
diff --git a/tests/tools/test_browser_real_profile.py b/tests/tools/test_browser_real_profile.py
index ace36127ed1..ae8a9d956ba 100644
--- a/tests/tools/test_browser_real_profile.py
+++ b/tests/tools/test_browser_real_profile.py
@@ -1136,6 +1136,21 @@ class TestWindowsLockedProfileCopy:
finally:
source.close()
+ def test_copy_auth_file_slow_but_progressing_backup_is_not_called_locked(self, tmp_path, monkeypatch):
+ """A large DB on a slow disk that is still copying pages past the deadline must not
+ get the lock wording (whose all-locked message tells the user to quit the browser)."""
+ import sqlite3
+ import hermes_cli.browser_connect as bc
+ src = str(tmp_path / "Web Data")
+ con = sqlite3.connect(src)
+ con.execute("create table t(x)")
+ con.executemany("insert into t values(?)", ((b"x" * 4000,) for _ in range(600))) # > 256 pages
+ con.commit(); con.close()
+ monkeypatch.setattr(bc, "_AUTH_BACKUP_DEADLINE_S", -1.0) # first callback is already past due
+ reason = bc._copy_auth_file(src, str(tmp_path / "out" / "Web Data"))
+ assert reason and reason != bc._AUTH_DB_LOCKED
+ assert "write lock" not in reason and "exceeded" in reason
+
def test_copy_auth_file_plain_for_non_db(self, tmp_path):
import hermes_cli.browser_connect as bc
src = str(tmp_path / "Preferences"); open(src, "w").write('{"k":1}')