Private
Public Access
0
0

refactor(ai_client): migrate cleanup + reset_session cache.delete to helper (Phase 11 sites 3+4)

Sites L432 (cleanup) and L450 (reset_session) had:
    try: _gemini_client.caches.delete(name=_gemini_cache.name)
    except Exception: pass

This is bare 'except: pass' = INTERNAL_SILENT_SWALLOW violation (logging is NOT
a drain; 'pass' is the worst form of silent recovery).

Migration: use existing _delete_gemini_cache_result() helper (added Phase 10).
The helper returns Result[None]; on SDK error logs a warning to comms.
The caller ignores the Result (cleanup is best-effort).

Audit: ai_client SS 11 -> 9.
This commit is contained in:
2026-06-20 13:57:27 -04:00
parent 82378339e0
commit fb7014cd63
2 changed files with 36 additions and 10 deletions
+2 -10
View File
@@ -426,11 +426,7 @@ def cleanup() -> None:
"""Performs cleanup operations like deleting server-side Gemini caches."""
global _gemini_client, _gemini_cache, _gemini_cached_file_paths
if _gemini_client and _gemini_cache:
#TODO(Ed): Exception(Review)
try:
_gemini_client.caches.delete(name=_gemini_cache.name)
except Exception:
pass
_delete_gemini_cache_result()
_gemini_cached_file_paths = []
def reset_session() -> None:
@@ -444,11 +440,7 @@ def reset_session() -> None:
global _CACHED_ANTHROPIC_TOOLS, _CACHED_DEEPSEEK_TOOLS
global _gemini_cli_adapter
if _gemini_client and _gemini_cache:
#TODO(Ed): Review(Exception)
try:
_gemini_client.caches.delete(name=_gemini_cache.name)
except Exception:
pass
_delete_gemini_cache_result()
_gemini_client = None
_gemini_chat = None
_gemini_cache = None
+34
View File
@@ -0,0 +1,34 @@
"""Phase 11 sites 3+4: cleanup + reset_session cache.delete.
Both have:
try: _gemini_client.caches.delete(name=_gemini_cache.name)
except Exception: pass
Migration: use _delete_gemini_cache_result() (already added in Phase 10).
The helper returns Result[None]; on error it logs a warning and resets
cache state. Caller ignores the Result.
"""
import sys
sys.path.insert(0, ".")
def test_phase11_sites34_cleanup_calls_delete_helper():
"""cleanup() must call _delete_gemini_cache_result, not raw caches.delete."""
import inspect
import src.ai_client
src_text = inspect.getsource(src.ai_client.cleanup)
assert "_delete_gemini_cache_result" in src_text, \
"cleanup() should call _delete_gemini_cache_result helper"
assert "except Exception" not in src_text, \
"cleanup() must NOT have a bare 'except Exception: pass'"
def test_phase11_sites34_reset_session_calls_delete_helper():
"""reset_session() must call _delete_gemini_cache_result, not raw caches.delete."""
import inspect
import src.ai_client
src_text = inspect.getsource(src.ai_client.reset_session)
assert "_delete_gemini_cache_result" in src_text, \
"reset_session() should call _delete_gemini_cache_result helper"
assert "except Exception" not in src_text, \
"reset_session() must NOT have a bare 'except Exception: pass'"