summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks
diff options
context:
space:
mode:
authorMohamed Hegazy <8000722+mhegazy@users.noreply.github.com>2026-11-06 11:42:19 -0800
committerGitHub <noreply@github.com>2026-11-06 11:42:19 -0800
commitb4720bd2ea255d57666fbf3aa6fbe5a40435089e (patch)
tree48542187ecab7b3a111ffdefa0c1f5d1d86016c9 /plugins/security-guidance/hooks
parent385e32d91174c6955f5cc52f9a84da314fddb3a0 (diff)
parenta7ae8adaac24a60a6ec0c030f3333d288811db45 (diff)
Merge pull request #6997 from anthropics/mhegazy/sg-net-err-on-verdict
security-guidance: clear net_err when a review gets through
Diffstat (limited to 'plugins/security-guidance/hooks')
-rw-r--r--plugins/security-guidance/hooks/_base.py6
-rw-r--r--plugins/security-guidance/hooks/llm.py13
-rwxr-xr-xplugins/security-guidance/hooks/security_reminder_hook.py4
3 files changed, 20 insertions, 3 deletions
diff --git a/plugins/security-guidance/hooks/_base.py b/plugins/security-guidance/hooks/_base.py
index 523049c1..99607e4a 100644
--- a/plugins/security-guidance/hooks/_base.py
+++ b/plugins/security-guidance/hooks/_base.py
@@ -240,7 +240,7 @@ _USAGE = {
# reported it manually.
"http_err_last": 0, # most recent HTTP error code this invocation
"http_err_count": 0, # total HTTP errors (4xx + 5xx + network)
- "net_err": 0, # why the last call got no HTTP response, 0 if it got one
+ "net_err": 0, # why the deciding call got no HTTP response, 0 if it got one
# For the usage log line only: model ids as recorded (the requested alias
# on the Agent SDK path), and whether any call had no price-table entry.
"models": [],
@@ -336,7 +336,9 @@ def _record_net_error(code):
raises outside its own error type (a default TLS context that cannot be
built, a connection closed before the reply) has no `api_error` at all.
Emitted as `net_err` on the row of a hook whose last call failed this
- way; a later call clears it."""
+ way; a later call clears it, and so does a call that gets through beside
+ it (a second probe, the other leg of a dual review, the agentic run that
+ wins a race)."""
try:
c = int(code)
except (TypeError, ValueError):
diff --git a/plugins/security-guidance/hooks/llm.py b/plugins/security-guidance/hooks/llm.py
index c0a878f4..ee9ad2be 100644
--- a/plugins/security-guidance/hooks/llm.py
+++ b/plugins/security-guidance/hooks/llm.py
@@ -437,7 +437,9 @@ def ensure_anthropic_reachable() -> bool:
debug_log("Remote env: api.anthropic.com unreachable, stripping anthropic.com from NO_PROXY")
_strip_anthropic_from_no_proxy()
_anthropic_reachable = _probe_anthropic()
- if not _anthropic_reachable:
+ if _anthropic_reachable:
+ _clear_net_error() # the first probe's failure; this one got through
+ else:
debug_log("Remote env: api.anthropic.com still unreachable after NO_PROXY scrub")
return _anthropic_reachable
@@ -994,6 +996,14 @@ def can_review(session_id) -> bool:
return HAS_API_CREDENTIALS or gateway_review_cli(session_id) is not None
+def _forget_failed_call():
+ """A review got its answer from another call running beside the one that
+ failed, so the row should not report that failure."""
+ global _last_call_claude_http_error
+ _last_call_claude_http_error = None
+ _clear_net_error()
+
+
def _call_claude_via_sdk(prompt, output_schema, *, max_tokens=16000, model=None,
cli_path=None):
"""Single-turn SDK call as a substitute for the HTTP _call_claude path on
@@ -1384,6 +1394,7 @@ def _call_claude_dual_or(prompt, output_schema, *, bool_key: str, list_key: str,
merged.append(item)
elif item not in merged:
merged.append(item)
+ _forget_failed_call() # one leg got through; the other may have failed
return {bool_key: bool(merged) or bool((ra or {}).get(bool_key)) or bool((rb or {}).get(bool_key)),
list_key: merged}
diff --git a/plugins/security-guidance/hooks/security_reminder_hook.py b/plugins/security-guidance/hooks/security_reminder_hook.py
index 7c84357f..47a992aa 100755
--- a/plugins/security-guidance/hooks/security_reminder_hook.py
+++ b/plugins/security-guidance/hooks/security_reminder_hook.py
@@ -1472,6 +1472,10 @@ def _agentic_review_with_race(
winner, (g, v, m) = "fallback", fallback_result["r"]
else:
winner, (g, v, m) = "fallback", timed_out
+ if winner == "agentic" and not m.get("agentic_fallback"):
+ # The agentic run reached the model; any failure on record is the
+ # fallback's, which lost.
+ llm._forget_failed_call()
m = {**m, **reviewer_context} # a copy: don't mutate the callee's metrics dict
m["race_winner"] = 1 if winner == "agentic" else 2
m["race_delay_s"] = delay_s