Spaces:
Running
Running
Update openspace/skill_engine/store.py
Browse files- openspace/skill_engine/store.py +26 -19
openspace/skill_engine/store.py
CHANGED
|
@@ -58,19 +58,26 @@ def _db_retry(
|
|
| 58 |
for attempt in range(max_retries):
|
| 59 |
try:
|
| 60 |
return func(*args, **kwargs)
|
| 61 |
-
except
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
raise
|
| 68 |
-
logger.warning(
|
| 69 |
-
f"DB {func.__name__} retry {attempt + 1}"
|
| 70 |
-
f"/{max_retries}: {exc}"
|
| 71 |
-
)
|
| 72 |
-
time.sleep(delay)
|
| 73 |
-
delay *= backoff
|
| 74 |
|
| 75 |
return wrapper
|
| 76 |
|
|
@@ -971,8 +978,8 @@ class SkillStore:
|
|
| 971 |
with self._reader() as conn:
|
| 972 |
where = " WHERE is_active=1" if active_only else ""
|
| 973 |
total = conn.execute(
|
| 974 |
-
f"SELECT COUNT(*) FROM skill_records{where}"
|
| 975 |
-
).fetchone()[
|
| 976 |
|
| 977 |
by_category = {
|
| 978 |
r["category"]: r["cnt"]
|
|
@@ -989,12 +996,12 @@ class SkillStore:
|
|
| 989 |
).fetchall()
|
| 990 |
}
|
| 991 |
n_analyses = conn.execute(
|
| 992 |
-
"SELECT COUNT(*) FROM execution_analyses"
|
| 993 |
-
).fetchone()[
|
| 994 |
n_candidates = conn.execute(
|
| 995 |
-
"SELECT COUNT(*) FROM execution_analyses "
|
| 996 |
"WHERE candidate_for_evolution=1"
|
| 997 |
-
).fetchone()[
|
| 998 |
agg = conn.execute(
|
| 999 |
f"""
|
| 1000 |
SELECT SUM(total_selections) AS sel,
|
|
@@ -1007,8 +1014,8 @@ class SkillStore:
|
|
| 1007 |
|
| 1008 |
# Also report total (including inactive) for context
|
| 1009 |
total_all = conn.execute(
|
| 1010 |
-
"SELECT COUNT(*) FROM skill_records"
|
| 1011 |
-
).fetchone()[
|
| 1012 |
|
| 1013 |
return {
|
| 1014 |
"total_skills": total,
|
|
|
|
| 58 |
for attempt in range(max_retries):
|
| 59 |
try:
|
| 60 |
return func(*args, **kwargs)
|
| 61 |
+
except Exception as exc:
|
| 62 |
+
# libsql_experimental might not have standard sqlite3 exceptions
|
| 63 |
+
# so we catch Exception and check if it's a known database error string
|
| 64 |
+
exc_str = str(exc).lower()
|
| 65 |
+
if "locked" in exc_str or "database error" in exc_str or "operational error" in exc_str:
|
| 66 |
+
if attempt == max_retries - 1:
|
| 67 |
+
logger.error(
|
| 68 |
+
f"DB {func.__name__} failed after "
|
| 69 |
+
f"{max_retries} retries: {exc}"
|
| 70 |
+
)
|
| 71 |
+
raise
|
| 72 |
+
logger.warning(
|
| 73 |
+
f"DB {func.__name__} retry {attempt + 1}"
|
| 74 |
+
f"/{max_retries}: {exc}"
|
| 75 |
)
|
| 76 |
+
time.sleep(delay)
|
| 77 |
+
delay *= backoff
|
| 78 |
+
else:
|
| 79 |
+
# If it's not a known transient error, raise immediately
|
| 80 |
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
return wrapper
|
| 83 |
|
|
|
|
| 978 |
with self._reader() as conn:
|
| 979 |
where = " WHERE is_active=1" if active_only else ""
|
| 980 |
total = conn.execute(
|
| 981 |
+
f"SELECT COUNT(*) as count FROM skill_records{where}"
|
| 982 |
+
).fetchone()["count"]
|
| 983 |
|
| 984 |
by_category = {
|
| 985 |
r["category"]: r["cnt"]
|
|
|
|
| 996 |
).fetchall()
|
| 997 |
}
|
| 998 |
n_analyses = conn.execute(
|
| 999 |
+
"SELECT COUNT(*) as count FROM execution_analyses"
|
| 1000 |
+
).fetchone()["count"]
|
| 1001 |
n_candidates = conn.execute(
|
| 1002 |
+
"SELECT COUNT(*) as count FROM execution_analyses "
|
| 1003 |
"WHERE candidate_for_evolution=1"
|
| 1004 |
+
).fetchone()["count"]
|
| 1005 |
agg = conn.execute(
|
| 1006 |
f"""
|
| 1007 |
SELECT SUM(total_selections) AS sel,
|
|
|
|
| 1014 |
|
| 1015 |
# Also report total (including inactive) for context
|
| 1016 |
total_all = conn.execute(
|
| 1017 |
+
"SELECT COUNT(*) as count FROM skill_records"
|
| 1018 |
+
).fetchone()["count"]
|
| 1019 |
|
| 1020 |
return {
|
| 1021 |
"total_skills": total,
|