diff --git a/agent/turn_explainers.py b/agent/turn_explainers.py index 9551792ead..dae098d0d9 100644 --- a/agent/turn_explainers.py +++ b/agent/turn_explainers.py @@ -5,6 +5,7 @@ summarises why a turn ended without a final answer. Every method resolves throug """ import os import re +from contextlib import suppress from typing import Any, Dict, Optional from agent.tool_dispatch_helpers import ( @@ -189,19 +190,17 @@ class TurnExplainersMixin: changed = getattr(self, "_turn_file_mutation_paths", None) if changed is not None: changed.update(landed_paths) - # Feed the checkpoint agent-write ledger so /rollback's safe mode - # can tell Hermes-authored content from later user hand-edits. + # Feed the checkpoint agent-write ledger so /rollback's safe mode can tell + # Hermes-authored content from later user hand-edits. mgr = getattr(self, "_checkpoint_mgr", None) if mgr is not None and getattr(mgr, "enabled", False): for _p in landed_paths: - try: + with suppress(Exception): mgr.record_agent_write(_p) - except Exception: - pass if is_error and not landed: + # Keep the FIRST error per path unless a later success replaces it. preview = _extract_error_preview(result) for path in targets: - # Keep the FIRST error per path unless a later success replaces it. state.setdefault(path, {"tool": tool_name, "error_preview": preview}) else: for path in targets: diff --git a/agent/turn_usage.py b/agent/turn_usage.py index 425c9e1076..87343441d1 100644 --- a/agent/turn_usage.py +++ b/agent/turn_usage.py @@ -11,6 +11,7 @@ model/provider. Logger name stays ``agent.conversation_loop`` for caplog parity. from __future__ import annotations import logging +from contextlib import suppress from dataclasses import dataclass from typing import Any, Dict, List @@ -155,15 +156,13 @@ def record_response_usage( agent.session_cache_write_tokens += canonical_usage.cache_write_tokens agent.session_reasoning_tokens += canonical_usage.reasoning_tokens # Rolling history for status-bar averages (last 10). - try: + with suppress(Exception): hist = getattr(agent, "_api_latency_history", None) if hist is not None: hist.append(float(api_duration)) ohist = getattr(agent, "_api_output_history", None) if ohist is not None: ohist.append(int(canonical_usage.output_tokens or 0)) - except Exception: - pass _cache_pct = "" if canonical_usage.cache_read_tokens and prompt_tokens: