The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent/api_request_hooks,activity_tracking): try/except-pass → suppress
Teknium1c1fa21d173d
diff --git a/agent/activity_tracking.py b/agent/activity_tracking.pyindex 93a2866eda4..72acb63203e 100644--- a/agent/activity_tracking.py+++ b/agent/activity_tracking.py@@ -7,6 +7,7 @@ import loggingimport osimport threadingimport time+from contextlib import suppressfrom typing import Optionalfrom agent.session_activity import ActivityProvenance@@ -64,16 +65,14 @@ class ActivityTrackingMixin:# itself at the final mutation edge.self._turn_liveness_abort_claim = Noneif os.environ.get("HERMES_KANBAN_TASK"):- try:+ # Never let the bridge break the loop; this guard covers import-time failures.+ with suppress(Exception):from tools.kanban_tools import (heartbeat_current_worker_from_env, inject_new_comments_from_env)heartbeat_current_worker_from_env()# Fold new operator notes into the running turn (OUT-OF-BAND steer).inject_new_comments_from_env(self)- except Exception:- # Never let the bridge break the loop; this guard covers import-time failures.- passif force_persist:reset_session_activity_persist_window(self)self._persist_session_activity_if_due()@@ -128,7 +127,5 @@ class ActivityTrackingMixin:clear = getattr(session_db, "clear_session_activity_labels", None)if not callable(clear):return- try:+ with suppress(Exception): # never let durable cleanup I/O break turn teardownclear(session_id)- except Exception:- pass # Never let durable cleanup I/O break turn teardown.diff --git a/agent/api_request_hooks.py b/agent/api_request_hooks.pyindex e57cdc7011c..24630dd1c3f 100644--- a/agent/api_request_hooks.py+++ b/agent/api_request_hooks.py@@ -6,6 +6,7 @@ Extracted from ``run_agent.py``; every method resolves through ``AIAgent``'s MROimport jsonimport osimport time+from contextlib import suppressfrom types import SimpleNamespacefrom typing import Any, Dict, Optional@@ -99,24 +100,18 @@ class ApiRequestHooksMixin:if len(seq) > max_sequence:out.append({"_truncated_items": len(seq) - max_sequence})return out- try:+ with suppress(Exception):if hasattr(value, "model_dump"):return recurse(_model_dump(value))- except Exception:- pass- try:+ with suppress(Exception):from dataclasses import asdict, is_dataclassif is_dataclass(value):return recurse(asdict(value))- except Exception:- passif isinstance(value, SimpleNamespace):return recurse(vars(value))if hasattr(value, "__dict__"):- try:+ with suppress(Exception):return recurse({k: v for k, v in vars(value).items() if not str(k).startswith("_")})- except Exception:- passreturn str(value)[:max_string]@classmethod@@ -171,9 +166,8 @@ class ApiRequestHooksMixin:reason: Optional[str] = None,) -> None:# Lazy module import (not from-import) so tests can replace lifecycle dispatch at this call site.- try:+ with suppress(Exception):from hermes_cli import lifecycle as _lifecycle-if not _lifecycle.has_hook("api_request_error"):returnended_at = time.time()@@ -200,5 +194,3 @@ class ApiRequestHooksMixin:error={"type": error_type, "message": error_message},request=self._api_request_payload_for_hook(api_kwargs),)- except Exception:- pass