From 2054c6e6f9fd705502b4dd4df92c9b25dddbdbb4 Mon Sep 17 00:00:00 2001 From: hmo Date: Tue, 21 Jul 2026 01:54:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20state.db=20=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E8=87=AA=E9=80=82=E5=BA=94=EF=BC=88=E7=A7=92?= =?UTF-8?q?/=E6=AF=AB=E7=A7=92=E6=B7=B7=E5=AD=98=EF=BC=89+=20default=20pro?= =?UTF-8?q?file=20=E6=97=A0sessions=E8=A1=A8=E9=9D=99=E9=BB=98=E8=B7=B3?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/agent_spiral_watchdog.py | 13 ++++++++++++- deploy/profile-scripts/system_hygiene_audit.py | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/deploy/profile-scripts/agent_spiral_watchdog.py b/deploy/profile-scripts/agent_spiral_watchdog.py index ae18f1c3..165c861f 100644 --- a/deploy/profile-scripts/agent_spiral_watchdog.py +++ b/deploy/profile-scripts/agent_spiral_watchdog.py @@ -59,6 +59,13 @@ def save_state(st): pass +def _to_ms(ts): + """started_at 单位自适应:>1e12 视为毫秒,否则视为秒。""" + if not ts: + return 0 + return ts if ts > 1e12 else ts * 1000 + + def main(): st = load_state() alerted = set(st.get("alerted", [])) @@ -70,6 +77,10 @@ def main(): try: conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True, timeout=10) conn.row_factory = sqlite3.Row + tables = {r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")} + if "sessions" not in tables: + conn.close() + continue rows = conn.execute(""" SELECT id, started_at, message_count, input_tokens, tool_call_count FROM sessions @@ -83,7 +94,7 @@ def main(): continue for r in rows: - sa = r["started_at"] or 0 + sa = _to_ms(r["started_at"]) age_sec = (now_ms - sa) / 1000 if age_sec < MIN_AGE_SEC: continue diff --git a/deploy/profile-scripts/system_hygiene_audit.py b/deploy/profile-scripts/system_hygiene_audit.py index c21216f9..cc9d94da 100644 --- a/deploy/profile-scripts/system_hygiene_audit.py +++ b/deploy/profile-scripts/system_hygiene_audit.py @@ -216,7 +216,8 @@ def check_stale_sessions(): except Exception: continue for r in rows: - sa = (r['started_at'] or 0) / 1000 + raw_sa = r['started_at'] or 0 + sa = (raw_sa if raw_sa > 1e12 else raw_sa * 1000) / 1000 # 单位自适应 if not (0 < sa < soul_mtime): continue # 只报"仍活跃"的:最近 6 小时内有消息(已被 bump 遗弃的旧 session 不报) @@ -226,7 +227,8 @@ def check_stale_sessions(): "SELECT MAX(created_at) FROM messages WHERE session_id=?", (r['id'],)).fetchone()[0] conn2.close() - last_ts = (last_msg or 0) / 1000 + lm = last_msg or 0 + last_ts = (lm if lm > 1e12 else lm * 1000) / 1000 # 单位自适应 if last_ts and (datetime.now().timestamp() - last_ts) > 6 * 3600: continue except Exception: