refactor(agent/api_request_hooks,activity_tracking): try/except-pass → suppress

This commit is contained in:
Teknium
2026-09-02 20:10:26 -07:00
parent dc5bd74cfb
commit 1c1fa21d17
2 changed files with 9 additions and 20 deletions
+4 -7
View File
@@ -7,6 +7,7 @@ import logging
import os
import threading
import time
from contextlib import suppress
from typing import Optional
from agent.session_activity import ActivityProvenance
@@ -64,16 +65,14 @@ class ActivityTrackingMixin:
# itself at the final mutation edge.
self._turn_liveness_abort_claim = None
if 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.
pass
if 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 teardown
clear(session_id)
except Exception:
pass # Never let durable cleanup I/O break turn teardown.
+5 -13
View File
@@ -6,6 +6,7 @@ Extracted from ``run_agent.py``; every method resolves through ``AIAgent``'s MRO
import json
import os
import time
from contextlib import suppress
from types import SimpleNamespace
from 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_dataclass
if is_dataclass(value):
return recurse(asdict(value))
except Exception:
pass
if 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:
pass
return 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"):
return
ended_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