Hardcode agent stale timeout

This commit is contained in:
Brandon Zhang
2026-03-27 18:32:25 +08:00
parent 07e31ce215
commit c690d0c483
15 changed files with 14 additions and 92 deletions

View File

@@ -10,6 +10,7 @@ import sqlite3
from datetime import datetime, timezone
from typing import Optional
from app.config import AGENT_STALE_AFTER_SECONDS
from app.database import get_conn, get_write_conn
logger = logging.getLogger(__name__)
@@ -55,25 +56,15 @@ def get_latest_agent_activity() -> Optional[sqlite3.Row]:
).fetchone()
def get_agent_stale_seconds() -> int:
"""Read agent_stale_after_seconds from settings table."""
with get_conn() as conn:
row = conn.execute(
"SELECT value FROM settings WHERE key = 'agent_stale_after_seconds'"
).fetchone()
return int(row["value"]) if row else 30
def is_agent_connected() -> bool:
"""True if the most recent agent activity is within the stale threshold."""
row = get_latest_agent_activity()
if row is None:
return False
stale_seconds = get_agent_stale_seconds()
last_seen = datetime.fromisoformat(row["last_seen_at"])
now = datetime.now(timezone.utc)
if last_seen.tzinfo is None:
last_seen = last_seen.replace(tzinfo=timezone.utc)
delta = (now - last_seen).total_seconds()
return delta <= stale_seconds
return delta <= AGENT_STALE_AFTER_SECONDS