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: