The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent/E_session): contextlib.suppress for swallow-only try/except
Teknium334b72256afd
diff --git a/agent/session_activity.py b/agent/session_activity.pyindex b7a161bc65a..6c756c9ad44 100644--- a/agent/session_activity.py+++ b/agent/session_activity.py@@ -8,6 +8,7 @@ the default agent clock stamps ``unknown`` unless a writer passes an explicit ``from __future__ import annotationsimport time+from contextlib import suppressfrom enum import Enumfrom typing import Any, Mapping, Optional@@ -50,10 +51,8 @@ def normalize_activity_provenance(provenance: Optional[ActivityProvenance | str]def reset_session_activity_persist_window(agent: Any) -> None:"""Clear the durable persist rate-limit so the next stamp writes through (terminal compressionlabels must not stay stuck on mid-compress text)."""- try:+ with suppress(Exception):agent._session_activity_last_persist_mono = 0.0- except Exception:- passdef build_activity_snapshot(diff --git a/agent/shell_hooks.py b/agent/shell_hooks.pyindex 18431165a8b..8450e2ccade 100644--- a/agent/shell_hooks.py+++ b/agent/shell_hooks.py@@ -20,7 +20,7 @@ import sysimport tempfileimport threadingimport time-from contextlib import ExitStack, contextmanager+from contextlib import ExitStack, contextmanager, suppressfrom dataclasses import dataclass, fieldfrom datetime import datetime, timezonefrom pathlib import Path@@ -361,10 +361,8 @@ def _spawn(spec: ShellHookSpec, stdin_json: str) -> Dict[str, Any]:except Exception as exc:# Kill the whole tree — forked helpers holding the pipes would stall the drain.kill_process_tree(proc)- try:+ with suppress(Exception):proc.communicate(timeout=1)- except Exception:- passif not isinstance(exc, subprocess.TimeoutExpired): # pragma: no cover — defensivereturn failed(str(exc))result["timed_out"] = True@@ -540,10 +538,8 @@ def save_allowlist(data: Dict[str, Any]) -> None:fh.write(json.dumps(data, indent=2, sort_keys=True))atomic_replace(tmp_path, p)except Exception:- try:+ with suppress(OSError):os.unlink(tmp_path)- except OSError:- passraiseexcept OSError as exc:logger.warning(@@ -576,10 +572,8 @@ def _locked_update_approvals() -> Iterator[Dict[str, Any]]:def _flock_unlock(lock_fh: Any) -> None:- try:+ with suppress(OSError):fcntl.flock(lock_fh.fileno(), fcntl.LOCK_UN)- except OSError:- passdef _prompt_and_record(event: str, command: str, *, accept_hooks: bool) -> bool:diff --git a/agent/title_generator.py b/agent/title_generator.pyindex 1235cc9c2ba..a1ed0d31e76 100644--- a/agent/title_generator.py+++ b/agent/title_generator.py@@ -11,6 +11,7 @@ import jsonimport loggingimport reimport threading+from contextlib import suppressfrom typing import Any, Callable, Optionalfrom agent.auxiliary_client import call_llm@@ -407,10 +408,8 @@ def auto_title_session(from agent.portal_tags import set_conversation_contextconversation_id = session_id- try:+ with suppress(Exception):conversation_id = session_db.get_conversation_root(session_id) or session_id- except Exception:- passset_conversation_context(conversation_id)set_accounting_context(session_db, session_id)diff --git a/agent/trace_upload.py b/agent/trace_upload.pyindex 345e1189d9c..addb159e0cf 100644--- a/agent/trace_upload.py+++ b/agent/trace_upload.py@@ -14,6 +14,7 @@ import jsonimport loggingimport osimport uuid+from contextlib import suppressfrom datetime import datetime, timezonefrom typing import Any, Dict, List, Optional, Tuple@@ -225,11 +226,9 @@ def _do_upload() -> str:"""Create (idempotently) the private dataset and push the trace file.Returns a user-facing status string. Never raises."""- try:+ with suppress(Exception): # lazy-install unavailable/declined — the import below surfaces the hintfrom tools import lazy_depslazy_deps.ensure("tool.trace_upload", prompt=False)- except Exception:- pass # lazy-install unavailable/declined — the import below surfaces the hinttry:from huggingface_hub import HfApiexcept ImportError: