Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
refactor: tighten session recency cleanup
chengyongrua6a489e0fa07
diff --git a/nanobot/agent/autocompact.py b/nanobot/agent/autocompact.pyindex cd776281c..38a2a390e 100644--- a/nanobot/agent/autocompact.py+++ b/nanobot/agent/autocompact.py@@ -26,24 +26,13 @@ class AutoCompact:self._archiving: set[str] = set()self._summaries: dict[str, tuple[str, datetime]] = {}- @staticmethod- def _timestamp(ts: datetime | str | None) -> float | None:- if not ts:- return None- if isinstance(ts, str):- try:- ts = datetime.fromisoformat(ts)- except ValueError:- return None- return ts.timestamp()-def _is_expired(self, ts: datetime | str | None,now: datetime | None = None) -> bool:- ts_epoch = self._timestamp(ts)- if self._ttl <= 0 or ts_epoch is None:+ if self._ttl <= 0 or not ts:return False- now_epoch = self._timestamp(now or datetime.now())- return now_epoch is not None and now_epoch - ts_epoch >= self._ttl * 60+ if isinstance(ts, str):+ ts = datetime.fromisoformat(ts)+ return ((now or datetime.now()) - ts).total_seconds() >= self._ttl * 60def _has_compactable_idle_tail(self, key: str) -> bool:session = self.sessions.get_or_create(key)@@ -52,7 +41,7 @@ class AutoCompact:return Falseprobe = Session(key=session.key,- messages=tail.copy(),+ messages=tail,created_at=session.created_at,updated_at=session.updated_at,metadata={},diff --git a/nanobot/webui/session_list_index.py b/nanobot/webui/session_list_index.pyindex e5b0547c7..ccadcd077 100644--- a/nanobot/webui/session_list_index.py+++ b/nanobot/webui/session_list_index.py@@ -284,8 +284,6 @@ def _scan_session_row(session_manager: SessionManager, path: Path) -> dict[str,if not line.strip():continueitem = json.loads(line)- if item.get("_type") == "metadata":- continuetimestamp = _visible_message_timestamp(item)if timestamp is not None:visible_message_at = _latest_updated_at(visible_message_at, timestamp)